summaryrefslogtreecommitdiff
path: root/test/behaviour/log.zig
blob: 21bccdf0346baf94df62044fb5b3c57489b8e7cc (plain) (blame)
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
//! docs/typ/reference.typ, The log <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})));
}