summaryrefslogtreecommitdiff
path: root/test/process_test.zig
blob: 37dd0954a270854635b3578e345a9a5cdb5a7f59 (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
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
//! The process tests (T2 of docs/next-tests.md): each case starts a real
//! pardes through test/process.zig and drives it over its socket. A file
//! in test/process/ a section of the book, as test/behaviour/'s are.
//!
//!     pardes-process-test <pardes> [filter]
const std = @import("std");
const process = @import("process.zig");

const files = .{
    @import("process/builtins.zig"),
    @import("process/edit.zig"),
    @import("process/flags.zig"),
    @import("process/look_and_exec.zig"),
    @import("process/mounts.zig"),
    @import("process/other_files.zig"),
    @import("process/repls.zig"),
    @import("process/root_ctl.zig"),
    @import("process/terminals.zig"),
    @import("process/tree.zig"),
    @import("process/window.zig"),
};

pub fn main(init: std.process.Init) !void {
    const all = try init.minimal.args.toSlice(init.arena.allocator());
    // <pardes> [--backend=tui|gui] [--image-addon=<image.so>] [filter]
    var args: [3][:0]const u8 = undefined;
    var n: usize = 0;
    for (all[1..]) |a| {
        if (std.mem.startsWith(u8, a, "--backend=")) {
            process.backend = std.meta.stringToEnum(process.Backend, a["--backend=".len..]) orelse return error.Usage;
        } else if (std.mem.startsWith(u8, a, "--image-addon=")) {
            process.image_addon = try std.Io.Dir.cwd().realPathFileAlloc(init.io, a["--image-addon=".len..], init.arena.allocator());
        } else if (n < args.len) {
            args[n] = a;
            n += 1;
        }
    }
    if (n < 1) return error.Usage;
    const exe = args[0];
    const filter: []const u8 = if (n > 1) args[1] else "";
    const gpa = std.heap.page_allocator;
    const on = @tagName(process.backend);
    var failed: usize = 0;
    var skipped: usize = 0;
    var ran: usize = 0;
    inline for (files) |file| inline for (file.cases) |case| {
        if (std.mem.indexOf(u8, case[0], filter) != null) {
            ran += 1;
            const t0 = process.nowMs();
            if (case[1](gpa, exe)) {
                std.debug.print("PASS [{s}] {d} ms {s}\n", .{ on, process.nowMs() - t0, case[0] });
            } else |err| if (err == error.SkipZigTest) {
                skipped += 1;
                std.debug.print("SKIP [{s}] {s}\n", .{ on, case[0] });
            } else {
                failed += 1;
                if (@errorReturnTrace()) |t| std.debug.dumpErrorReturnTrace(t);
                std.debug.print("FAIL [{s}] {d} ms {s}: {t}\n", .{ on, process.nowMs() - t0, case[0], err });
            }
        }
    };
    std.debug.print("{d} of {d} process tests failed on {s} ({d} skipped)\n", .{ failed, ran, on, skipped });
    if (failed > 0 or ran == 0) std.process.exit(1);
}