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 {
5656 },
5757 };
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
5965 pub const TestType = enum {
6066 Zig,
6167 ZIR,
......@@ -78,6 +84,8 @@ pub const TestContext = struct {
7884 extension: TestType,
7985 cbe: bool = false,
8086
87 files: std.ArrayList(File),
88
8189 /// Adds a subcase in which the module is updated with `src`, and the
8290 /// resulting ZIR is validated against `result`.
8391 pub fn addTransform(self: *Case, src: [:0]const u8, result: [:0]const u8) void {
......@@ -156,6 +164,7 @@ pub const TestContext = struct {
156164 .updates = std.ArrayList(Update).init(ctx.cases.allocator),
157165 .output_mode = .Exe,
158166 .extension = T,
167 .files = std.ArrayList(File).init(ctx.cases.allocator),
159168 }) catch unreachable;
160169 return &ctx.cases.items[ctx.cases.items.len - 1];
161170 }
......@@ -182,6 +191,7 @@ pub const TestContext = struct {
182191 .updates = std.ArrayList(Update).init(ctx.cases.allocator),
183192 .output_mode = .Obj,
184193 .extension = T,
194 .files = std.ArrayList(File).init(ctx.cases.allocator),
185195 }) catch unreachable;
186196 return &ctx.cases.items[ctx.cases.items.len - 1];
187197 }
......@@ -204,6 +214,7 @@ pub const TestContext = struct {
204214 .output_mode = .Obj,
205215 .extension = T,
206216 .cbe = true,
217 .files = std.ArrayList(File).init(ctx.cases.allocator),
207218 }) catch unreachable;
208219 return &ctx.cases.items[ctx.cases.items.len - 1];
209220 }
......@@ -505,6 +516,10 @@ pub const TestContext = struct {
505516 });
506517 defer comp.destroy();
507518
519 for (case.files.items) |file| {
520 try tmp.dir.writeFile(file.path, file.src);
521 }
522
508523 for (case.updates.items) |update, update_index| {
509524 var update_node = root_node.start("update", 3);
510525 update_node.activate();
test/stage2/test.zig+38
......@@ -909,6 +909,44 @@ pub fn addCases(ctx: *TestContext) !void {
909909 );
910910 }
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
912950 {
913951 var case = ctx.exe("wasm function calls", wasi);
914952