Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

runTestResultMessage

time_report.runTestResultMessage
pub fn runTestResultMessage(msg_bytes: []u8) error

File

lib/build-web/time_report.zig:248

Code

pub fn runTestResultMessage(msg_bytes: []u8) error{OutOfMemory}!void {
    if (msg_bytes.len < @sizeOf(abi.RunTestResult)) @panic("malformed RunTestResult message");
    const hdr: *const abi.RunTestResult = @ptrCast(msg_bytes[0..@sizeOf(abi.RunTestResult)]);
    if (hdr.step_idx >= step_list.*.len) @panic("malformed RunTestResult message");
    const trailing = msg_bytes[@sizeOf(abi.RunTestResult)..];

    const durations: []align(1) const u64 = @ptrCast(trailing[0 .. hdr.tests_len * 8]);
    var offset: usize = hdr.tests_len * 8;

    var table_html: std.ArrayList(u8) = .empty;
    defer table_html.deinit(gpa);

    for (durations) |test_ns| {
        const test_name_len = std.mem.indexOfScalar(u8, trailing[offset..], 0) orelse @panic("malformed RunTestResult message");
        const test_name = trailing[offset..][0..test_name_len];
        offset += test_name_len + 1;
        try table_html.print(gpa, "<tr><th scope=\"row\"><code>{f}</code></th>", .{fmtEscapeHtml(test_name)});
        if (test_ns == std.math.maxInt(u64)) {
            try table_html.appendSlice(gpa, "<td class=\"empty-cell\"></td>"); // didn't run
        } else {
            try table_html.print(gpa, "<td>{f}</td>", .{std.Io.Duration{ .nanoseconds = test_ns }});
        }
        try table_html.appendSlice(gpa, "</tr>\n");
    }

    if (offset != trailing.len) @panic("malformed RunTestResult message");

    js.updateRunTest(
        hdr.step_idx,
        table_html.items.ptr,
        table_html.items.len,
    );
}