//! docs/typ/reference.typ, The log . const std = @import("std"); const Session = @import("session").Session; fn has(hay: []const u8, needle: []const u8) bool { return std.mem.indexOf(u8, hay, needle) != null; } test "log: a message from a root ctl write is the session's, and its own words stand for its Verbose announcement" { var s = try Session.initFile(std.testing.allocator, "x\n"); defer s.deinit(); try s.write("/ctl", "Kill\n"); const log = try s.read("/log"); try std.testing.expect(has(log, "\nmsg - Kill: nothing running\n")); try std.testing.expectEqual(@as(usize, 1), std.mem.count(u8, log, "Kill")); } test "log: a builtin that fails a ctl write logs only its err, so the same failure again is counted" { var s = try Session.initFile(std.testing.allocator, "x\n"); defer s.deinit(); // Another failure first: the pane's `new` is logged after it. _ = try s.refused("/ctl", "Unmount yyy\n"); for (0..3) |_| try std.testing.expect(try s.refused("/ctl", "Unmount zzz\n") != 0); const log = try s.read("/log"); try std.testing.expect(std.mem.endsWith(u8, log, "err - ctl: Unmount: no such mount zzz (x3)\n")); try std.testing.expect(!has(log, "msg - Unmount")); } test "log: a root exec that fails logs its err against the pane it ran at" { var s = try Session.initFile(std.testing.allocator, "x\n"); defer s.deinit(); const n = try s.focused(); try s.write(s.at("/pane/{d}/body", .{n}), "unsaved\n"); try std.testing.expect(try s.refused("/exec", "Exit\n") != 0); try std.testing.expect(has(try s.read("/log"), s.at("err {d} exec: ", .{n}))); }