| ... | ... | @@ -1,19 +1,19 @@ |
| 1 | | const std = @import("../std.zig"); |
| 2 | | const Step = std.Build.Step; |
| 3 | | const fs = std.fs; |
| 4 | | const mem = std.mem; |
| 5 | | |
| 6 | | const CheckFileStep = @This(); |
| 7 | | |
| 8 | | pub const base_id = .check_file; |
| 1 | //! Fail the build step if a file does not match certain checks. |
| 2 | //! TODO: make this more flexible, supporting more kinds of checks. |
| 3 | //! TODO: generalize the code in std.testing.expectEqualStrings and make this |
| 4 | //! CheckFileStep produce those helpful diagnostics when there is not a match. |
| 9 | 5 | |
| 10 | 6 | step: Step, |
| 11 | 7 | expected_matches: []const []const u8, |
| 8 | expected_exact: ?[]const u8, |
| 12 | 9 | source: std.Build.FileSource, |
| 13 | 10 | max_bytes: usize = 20 * 1024 * 1024, |
| 14 | 11 | |
| 12 | pub const base_id = .check_file; |
| 13 | |
| 15 | 14 | pub const Options = struct { |
| 16 | | expected_matches: []const []const u8, |
| 15 | expected_matches: []const []const u8 = &.{}, |
| 16 | expected_exact: ?[]const u8 = null, |
| 17 | 17 | }; |
| 18 | 18 | |
| 19 | 19 | pub fn create( |
| ... | ... | @@ -31,6 +31,7 @@ pub fn create( |
| 31 | 31 | }), |
| 32 | 32 | .source = source.dupe(owner), |
| 33 | 33 | .expected_matches = owner.dupeStrings(options.expected_matches), |
| 34 | .expected_exact = options.expected_exact, |
| 34 | 35 | }; |
| 35 | 36 | self.source.addStepDependencies(&self.step); |
| 36 | 37 | return self; |
| ... | ... | @@ -60,8 +61,28 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 60 | 61 | \\{s} |
| 61 | 62 | \\========= but file does not contain it: ======= |
| 62 | 63 | \\{s} |
| 63 | | \\ |
| 64 | \\=============================================== |
| 64 | 65 | , .{ expected_match, contents }); |
| 65 | 66 | } |
| 66 | 67 | } |
| 68 | |
| 69 | if (self.expected_exact) |expected_exact| { |
| 70 | if (!mem.eql(u8, expected_exact, contents)) { |
| 71 | return step.fail( |
| 72 | \\ |
| 73 | \\========= expected: ===================== |
| 74 | \\{s} |
| 75 | \\========= but found: ==================== |
| 76 | \\{s} |
| 77 | \\========= from the following file: ====== |
| 78 | \\{s} |
| 79 | , .{ expected_exact, contents, src_path }); |
| 80 | } |
| 81 | } |
| 67 | 82 | } |
| 83 | |
| 84 | const CheckFileStep = @This(); |
| 85 | const std = @import("../std.zig"); |
| 86 | const Step = std.Build.Step; |
| 87 | const fs = std.fs; |
| 88 | const mem = std.mem; |