DoxigAlpha

make

Function parameters

Parameters

#
step:*Step
options:Step.MakeOptions

Type definitions in this namespace

Types

#

Functions in this namespace

Functions

#

= .check_file

Values

#
base_id
= .check_file

Source

Implementation

#
fn make(step: *Step, options: Step.MakeOptions) !void {
    _ = options;
    const b = step.owner;
    const check_file: *CheckFile = @fieldParentPtr("step", step);
    try step.singleUnchangingWatchInput(check_file.source);

    const src_path = check_file.source.getPath2(b, step);
    const contents = fs.cwd().readFileAlloc(b.allocator, src_path, check_file.max_bytes) catch |err| {
        return step.fail("unable to read '{s}': {s}", .{
            src_path, @errorName(err),
        });
    };

    for (check_file.expected_matches) |expected_match| {
        if (mem.indexOf(u8, contents, expected_match) == null) {
            return step.fail(
                \\
                \\========= expected to find: ===================
                \\{s}
                \\========= but file does not contain it: =======
                \\{s}
                \\===============================================
            , .{ expected_match, contents });
        }
    }

    if (check_file.expected_exact) |expected_exact| {
        if (!mem.eql(u8, expected_exact, contents)) {
            return step.fail(
                \\
                \\========= expected: =====================
                \\{s}
                \\========= but found: ====================
                \\{s}
                \\========= from the following file: ======
                \\{s}
            , .{ expected_exact, contents, src_path });
        }
    }
}