1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
//! docs/typ/reference.typ, Other files <other-files>, through a real
//! session's socket.
const std = @import("std");
const process = @import("../process.zig");
pub const cases = .{
.{ "other-files: kbdin and mousein drive a detached session as the user would, each write done before it is answered", keysAndMouse },
.{ "other-files: a held connection lists a directory, stats a file, writes and reads, is refused in words and removes a pane", heldConnection },
};
/// A script types and clicks as the user does: no sleep or poll between a
/// write and the read that checks it; where to click is read off /screen.
/// (test/fs.py's keys_and_mouse, the first case written through the files
/// alone.)
fn keysAndMouse(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var d = try process.Detached.start(gpa, exe, "kbd", .{});
defer d.deinit();
const f = &d.files;
var buf: [4096]u8 = undefined;
try @import("../e2e_harness.zig").writeFile(try std.fmt.bufPrintSentinel(&buf, "{s}/target.txt", .{d.root()}, 0), "hello-target\n");
const serial = try f.newPane();
try f.write(f.at("/pane/{d}/body", .{serial}), "see \n");
try f.write("/focus", f.at("{d}\n", .{serial}));
try f.keys("Atarget.txt\x1b");
try f.expect(f.at("/pane/{d}/body", .{serial}), "see target.txt\n");
try f.click("target.txt", 2, 4);
var index = std.mem.splitBackwardsScalar(u8, std.mem.trimEnd(u8, try f.read("/index"), "\n"), '\n');
const last = index.first();
try std.testing.expect(std.mem.endsWith(u8, last, "target.txt 1"));
const opened = try std.fmt.parseInt(u32, last[0..std.mem.indexOfScalar(u8, last, ' ').?], 10);
try std.testing.expect(opened != serial);
try f.expect(f.at("/pane/{d}/body", .{opened}), "hello-target\n");
// Undone from the keyboard, as the user would: u in normal mode.
try f.write("/focus", f.at("{d}\n", .{serial}));
try f.keys("u");
try f.expect(f.at("/pane/{d}/body", .{serial}), "see \n");
}
/// The runner's held connection, against a real session: a directory's
/// entries, a stat, an open held while another write lands, a remove.
fn heldConnection(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var d = try process.Detached.start(gpa, exe, "conn", .{});
defer d.deinit();
const c = try process.Conn.dial(gpa, d.socket());
defer c.deinit(gpa);
const names = try c.list(gpa, "/");
defer {
for (names) |n| gpa.free(n);
gpa.free(names);
}
var has_index = false;
for (names) |n| has_index = has_index or std.mem.eql(u8, n, "index");
try std.testing.expect(has_index);
try std.testing.expect((try c.stat("/kbdin")).mode & 0o222 != 0);
const serial = try std.fmt.parseInt(u32, std.mem.trim(u8, try d.files.read("/pane/new"), "\n"), 10);
var path: [64]u8 = undefined;
const body = try std.fmt.bufPrint(&path, "/pane/{d}/body", .{serial});
try c.write(body, "held\n");
const got = try c.read(gpa, body);
defer gpa.free(got);
try std.testing.expectEqualStrings("held\n", got);
try std.testing.expectError(error.Refused, c.write("/mousein", "nonsense\n"));
try std.testing.expect(c.said.len > 0);
try c.remove(try std.fmt.bufPrint(&path, "/pane/{d}", .{serial}));
try std.testing.expectError(error.NotFound, c.walk(body));
}
|