authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-09-09 19:24:21+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-09-30 17:00:57+03:00
logd819da4350cc4325a7281ebeaf6057586b8eb0d7
treededb59eb42ab562d99ba0e33d158a917c14d016f
parente246fe0f5bdf1168171f79570af16cd3e79665a6
signature Commit is signed but in an unrecognized format.

stage2: support multiple files in tests


2 files changed, 53 insertions(+), 0 deletions(-)

src/test.zig+15
...@@ -56,6 +56,12 @@ pub const TestContext = struct {...@@ -56,6 +56,12 @@ pub const TestContext = struct {
56 },56 },
57 };57 };
5858
59 pub const File = struct {
60 /// Contents of the importable file. Doesn't yet support incremental updates.
61 src: [:0]const u8,
62 path: []const u8,
63 };
64
59 pub const TestType = enum {65 pub const TestType = enum {
60 Zig,66 Zig,
61 ZIR,67 ZIR,
...@@ -78,6 +84,8 @@ pub const TestContext = struct {...@@ -78,6 +84,8 @@ pub const TestContext = struct {
78 extension: TestType,84 extension: TestType,
79 cbe: bool = false,85 cbe: bool = false,
8086
87 files: std.ArrayList(File),
88
81 /// Adds a subcase in which the module is updated with `src`, and the89 /// Adds a subcase in which the module is updated with `src`, and the
82 /// resulting ZIR is validated against `result`.90 /// resulting ZIR is validated against `result`.
83 pub fn addTransform(self: *Case, src: [:0]const u8, result: [:0]const u8) void {91 pub fn addTransform(self: *Case, src: [:0]const u8, result: [:0]const u8) void {
...@@ -156,6 +164,7 @@ pub const TestContext = struct {...@@ -156,6 +164,7 @@ pub const TestContext = struct {
156 .updates = std.ArrayList(Update).init(ctx.cases.allocator),164 .updates = std.ArrayList(Update).init(ctx.cases.allocator),
157 .output_mode = .Exe,165 .output_mode = .Exe,
158 .extension = T,166 .extension = T,
167 .files = std.ArrayList(File).init(ctx.cases.allocator),
159 }) catch unreachable;168 }) catch unreachable;
160 return &ctx.cases.items[ctx.cases.items.len - 1];169 return &ctx.cases.items[ctx.cases.items.len - 1];
161 }170 }
...@@ -182,6 +191,7 @@ pub const TestContext = struct {...@@ -182,6 +191,7 @@ pub const TestContext = struct {
182 .updates = std.ArrayList(Update).init(ctx.cases.allocator),191 .updates = std.ArrayList(Update).init(ctx.cases.allocator),
183 .output_mode = .Obj,192 .output_mode = .Obj,
184 .extension = T,193 .extension = T,
194 .files = std.ArrayList(File).init(ctx.cases.allocator),
185 }) catch unreachable;195 }) catch unreachable;
186 return &ctx.cases.items[ctx.cases.items.len - 1];196 return &ctx.cases.items[ctx.cases.items.len - 1];
187 }197 }
...@@ -204,6 +214,7 @@ pub const TestContext = struct {...@@ -204,6 +214,7 @@ pub const TestContext = struct {
204 .output_mode = .Obj,214 .output_mode = .Obj,
205 .extension = T,215 .extension = T,
206 .cbe = true,216 .cbe = true,
217 .files = std.ArrayList(File).init(ctx.cases.allocator),
207 }) catch unreachable;218 }) catch unreachable;
208 return &ctx.cases.items[ctx.cases.items.len - 1];219 return &ctx.cases.items[ctx.cases.items.len - 1];
209 }220 }
...@@ -505,6 +516,10 @@ pub const TestContext = struct {...@@ -505,6 +516,10 @@ pub const TestContext = struct {
505 });516 });
506 defer comp.destroy();517 defer comp.destroy();
507518
519 for (case.files.items) |file| {
520 try tmp.dir.writeFile(file.path, file.src);
521 }
522
508 for (case.updates.items) |update, update_index| {523 for (case.updates.items) |update, update_index| {
509 var update_node = root_node.start("update", 3);524 var update_node = root_node.start("update", 3);
510 update_node.activate();525 update_node.activate();
test/stage2/test.zig+38
...@@ -909,6 +909,44 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -909,6 +909,44 @@ pub fn addCases(ctx: *TestContext) !void {
909 );909 );
910 }910 }
911911
912 {
913 var case = ctx.exe("basic import", linux_x64);
914 case.addCompareOutput(
915 \\export fn _start() noreturn {
916 \\ @import("print.zig").print();
917 \\ exit();
918 \\}
919 \\
920 \\fn exit() noreturn {
921 \\ asm volatile ("syscall"
922 \\ :
923 \\ : [number] "{rax}" (231),
924 \\ [arg1] "{rdi}" (@as(usize, 0))
925 \\ : "rcx", "r11", "memory"
926 \\ );
927 \\ unreachable;
928 \\}
929 ,
930 "Hello, World!\n",
931 );
932 try case.files.append(.{
933 .src =
934 \\pub fn print() void {
935 \\ asm volatile ("syscall"
936 \\ :
937 \\ : [number] "{rax}" (@as(usize, 1)),
938 \\ [arg1] "{rdi}" (@as(usize, 1)),
939 \\ [arg2] "{rsi}" (@ptrToInt("Hello, World!\n")),
940 \\ [arg3] "{rdx}" (@as(usize, 14))
941 \\ : "rcx", "r11", "memory"
942 \\ );
943 \\ return;
944 \\}
945 ,
946 .path = "print.zig",
947 });
948 }
949
912 {950 {
913 var case = ctx.exe("wasm function calls", wasi);951 var case = ctx.exe("wasm function calls", wasi);
914952