authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-04-26 18:58:16+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-04-28 18:35:01+02:00
logf41dd3617e3f630c3d5ec7745784076ccc0c3025
tree7d9c2ba2810b3fa90df815c60190b75e2331fea7
parentd305a6fb550d68f4ee57bbb86f482969b819653b

test: pass Strategy per directory of tests


4 files changed, 8 insertions(+), 16 deletions(-)

src/test.zig+8-11
...@@ -80,7 +80,7 @@ test {...@@ -80,7 +80,7 @@ test {
80 var dir = try std.fs.cwd().openDir(dir_path, .{ .iterate = true });80 var dir = try std.fs.cwd().openDir(dir_path, .{ .iterate = true });
81 defer dir.close();81 defer dir.close();
8282
83 ctx.addTestCasesFromDir(dir);83 ctx.addTestCasesFromDir(dir, .incremental);
84 }84 }
8585
86 try @import("test_cases").addCases(&ctx);86 try @import("test_cases").addCases(&ctx);
...@@ -834,10 +834,6 @@ pub const TestContext = struct {...@@ -834,10 +834,6 @@ pub const TestContext = struct {
834 /// Execute all tests as incremental updates to a single compilation. Explicitly834 /// Execute all tests as incremental updates to a single compilation. Explicitly
835 /// incremental tests ("foo.0.zig", "foo.1.zig", etc.) still execute in order835 /// incremental tests ("foo.0.zig", "foo.1.zig", etc.) still execute in order
836 incremental,836 incremental,
837
838 fn parse(str: []const u8) ?Strategy {
839 return std.meta.stringToEnum(Strategy, str);
840 }
841 };837 };
842838
843 /// Adds a compile-error test for each file in the provided directory, using the839 /// Adds a compile-error test for each file in the provided directory, using the
...@@ -866,9 +862,9 @@ pub const TestContext = struct {...@@ -866,9 +862,9 @@ pub const TestContext = struct {
866 };862 };
867 }863 }
868864
869 pub fn addTestCasesFromDir(ctx: *TestContext, dir: std.fs.Dir) void {865 pub fn addTestCasesFromDir(ctx: *TestContext, dir: std.fs.Dir, strategy: Strategy) void {
870 var current_file: []const u8 = "none";866 var current_file: []const u8 = "none";
871 addTestCasesFromDirInner(ctx, dir, &current_file) catch |err| {867 addTestCasesFromDirInner(ctx, dir, strategy, &current_file) catch |err| {
872 std.debug.panic("test harness failed to process file '{s}': {s}\n", .{868 std.debug.panic("test harness failed to process file '{s}': {s}\n", .{
873 current_file, @errorName(err),869 current_file, @errorName(err),
874 });870 });
...@@ -938,6 +934,7 @@ pub const TestContext = struct {...@@ -938,6 +934,7 @@ pub const TestContext = struct {
938 fn addTestCasesFromDirInner(934 fn addTestCasesFromDirInner(
939 ctx: *TestContext,935 ctx: *TestContext,
940 dir: std.fs.Dir,936 dir: std.fs.Dir,
937 strategy: Strategy,
941 /// This is kept up to date with the currently being processed file so938 /// This is kept up to date with the currently being processed file so
942 /// that if any errors occur the caller knows it happened during this file.939 /// that if any errors occur the caller knows it happened during this file.
943 current_file: *[]const u8,940 current_file: *[]const u8,
...@@ -988,8 +985,8 @@ pub const TestContext = struct {...@@ -988,8 +985,8 @@ pub const TestContext = struct {
988 // in a new sequence ("*.0.zig") or an independent test file ("*.zig")985 // in a new sequence ("*.0.zig") or an independent test file ("*.zig")
989 if (new_parts.test_index != null and new_parts.test_index.? != 0) return error.InvalidIncrementalTestIndex;986 if (new_parts.test_index != null and new_parts.test_index.? != 0) return error.InvalidIncrementalTestIndex;
990987
991 // if (strategy == .independent)988 if (strategy == .independent)
992 // opt_case = null; // Generate a new independent test case for this update989 opt_case = null; // Generate a new independent test case for this update
993 }990 }
994 }991 }
995 prev_filename = filename;992 prev_filename = filename;
...@@ -999,13 +996,12 @@ pub const TestContext = struct {...@@ -999,13 +996,12 @@ pub const TestContext = struct {
999996
1000 // Parse the manifest997 // Parse the manifest
1001 var manifest = try TestManifest.parse(ctx.arena, src);998 var manifest = try TestManifest.parse(ctx.arena, src);
1002 const strategy = manifest.getConfigForKey("strategy", Strategy, Strategy.parse).next().?;
1003 const backend = manifest.getConfigForKey("backend", Backend, Backend.parse).next().?;
1004999
1005 switch (manifest.@"type") {1000 switch (manifest.@"type") {
1006 .@"error" => {1001 .@"error" => {
1007 const case = opt_case orelse case: {1002 const case = opt_case orelse case: {
1008 const case = try ctx.cases.addOne();1003 const case = try ctx.cases.addOne();
1004 const backend = manifest.getConfigForKey("backend", Backend, Backend.parse).next().?;
1009 case.* = .{1005 case.* = .{
1010 .name = "none",1006 .name = "none",
1011 .target = .{},1007 .target = .{},
...@@ -1032,6 +1028,7 @@ pub const TestContext = struct {...@@ -1032,6 +1028,7 @@ pub const TestContext = struct {
1032 .run => {1028 .run => {
1033 const case = opt_case orelse case: {1029 const case = opt_case orelse case: {
1034 const case = try ctx.cases.addOne();1030 const case = try ctx.cases.addOne();
1031 const backend = manifest.getConfigForKey("backend", Backend, Backend.parse).next().?;
1035 case.* = .{1032 case.* = .{
1036 .name = "none",1033 .name = "none",
1037 .target = .{},1034 .target = .{},
test/incremental/add.0.zig-1
...@@ -8,5 +8,4 @@ fn add(a: u32, b: u32) void {...@@ -8,5 +8,4 @@ fn add(a: u32, b: u32) void {
88
9// run9// run
10// backend=stage210// backend=stage2
11// strategy=incremental
12//11//
test/incremental/add.1.zig-2
...@@ -9,6 +9,4 @@ fn add(a: u32, b: u32) u32 {...@@ -9,6 +9,4 @@ fn add(a: u32, b: u32) u32 {
9const x = add(3, 4);9const x = add(3, 4);
1010
11// run11// run
12// backend=stage2
13// strategy=incremental
14//12//
test/incremental/add.2.zig-2
...@@ -9,6 +9,4 @@ inline fn add(a: usize, b: usize, c: usize) usize {...@@ -9,6 +9,4 @@ inline fn add(a: usize, b: usize, c: usize) usize {
9}9}
1010
11// run11// run
12// backend=stage2
13// strategy=incremental
14//12//