const std = @import("std");
const builtin = @import("builtin");

pub fn main(init: std.process.Init) !void {
    const arena = init.arena.allocator();
    const io = init.io;
    const args = try init.minimal.args.toSlice(arena);

    if (args.len != 3) return error.BadUsage;
    const actual_path = args[1];
    const expected_path = args[2];

    const actual = try std.Io.Dir.cwd().readFileAlloc(io, actual_path, arena, .limited(1024 * 1024));
    const expected = try std.Io.Dir.cwd().readFileAlloc(io, expected_path, arena, .limited(1024 * 1024));

    // The actual output starts with a comment which we should strip out before comparing.
    const comment_str = "/* This file was generated by ConfigHeader using the Zig Build System. */\n";
    if (!std.mem.startsWith(u8, actual, comment_str)) {
        return error.MissingOrMalformedComment;
    }
    const actual_without_comment = actual[comment_str.len..];

    if (builtin.os.tag == .windows) return; // https://codeberg.org/ziglang/zig/issues/30138

    try std.testing.expectEqualStrings(expected, actual_without_comment);
}
