mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
Instead of using `zig test` to build a special version of the compiler that runs all the test-cases, the zig build system is now used as much as possible - all with the basic steps found in the standard library. For incremental compilation tests (the ones that look like foo.0.zig, foo.1.zig, foo.2.zig, etc.), a special version of the compiler is compiled into a utility executable called "check-case" which checks exactly one sequence of incremental updates in an independent subprocess. Previously, all incremental and non-incremental test cases were done in the same test runner process. The compile error checking code is now simpler, but also a bit rudimentary, and so it additionally makes sure that the actual compile errors do not include *extra* messages, and it makes sure that the actual compile errors output in the same order as expected. It is also based on the "ends-with" property of each line rather than the previous logic, which frankly I didn't want to touch with a ten-meter pole. The compile error test cases have been updated to pass in light of these differences. Previously, 'error' mode with 0 compile errors was used to shoehorn in a different kind of test-case - one that only checks if a piece of code compiles without errors. Now there is a 'compile' mode of test-cases, and 'error' must be only used when there are greater than 0 errors. link test cases are updated to omit the target object format argument when calling checkObject since that is no longer needed. The test/stage2 directory is removed; the 2 files within are moved to be directly in the test/ directory.
78 lines
2.9 KiB
Zig
78 lines
2.9 KiB
Zig
const std = @import("std");
|
|
|
|
pub const requires_stage2 = true;
|
|
|
|
pub fn build(b: *std.Build) void {
|
|
const test_step = b.step("test", "Test it");
|
|
b.default_step = test_step;
|
|
|
|
add(b, test_step, .Debug);
|
|
add(b, test_step, .ReleaseFast);
|
|
add(b, test_step, .ReleaseSmall);
|
|
add(b, test_step, .ReleaseSafe);
|
|
}
|
|
|
|
fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
|
|
const import_table = b.addSharedLibrary(.{
|
|
.name = "import_table",
|
|
.root_source_file = .{ .path = "lib.zig" },
|
|
.target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
|
|
.optimize = optimize,
|
|
});
|
|
import_table.use_llvm = false;
|
|
import_table.use_lld = false;
|
|
import_table.import_table = true;
|
|
|
|
const export_table = b.addSharedLibrary(.{
|
|
.name = "export_table",
|
|
.root_source_file = .{ .path = "lib.zig" },
|
|
.target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
|
|
.optimize = optimize,
|
|
});
|
|
export_table.use_llvm = false;
|
|
export_table.use_lld = false;
|
|
export_table.export_table = true;
|
|
|
|
const regular_table = b.addSharedLibrary(.{
|
|
.name = "regular_table",
|
|
.root_source_file = .{ .path = "lib.zig" },
|
|
.target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
|
|
.optimize = optimize,
|
|
});
|
|
regular_table.use_llvm = false;
|
|
regular_table.use_lld = false;
|
|
|
|
const check_import = import_table.checkObject();
|
|
const check_export = export_table.checkObject();
|
|
const check_regular = regular_table.checkObject();
|
|
|
|
check_import.checkStart("Section import");
|
|
check_import.checkNext("entries 1");
|
|
check_import.checkNext("module env");
|
|
check_import.checkNext("name __indirect_function_table");
|
|
check_import.checkNext("kind table");
|
|
check_import.checkNext("type funcref");
|
|
check_import.checkNext("min 1"); // 1 function pointer
|
|
check_import.checkNotPresent("max"); // when importing, we do not provide a max
|
|
check_import.checkNotPresent("Section table"); // we're importing it
|
|
|
|
check_export.checkStart("Section export");
|
|
check_export.checkNext("entries 2");
|
|
check_export.checkNext("name __indirect_function_table"); // as per linker specification
|
|
check_export.checkNext("kind table");
|
|
|
|
check_regular.checkStart("Section table");
|
|
check_regular.checkNext("entries 1");
|
|
check_regular.checkNext("type funcref");
|
|
check_regular.checkNext("min 2"); // index starts at 1 & 1 function pointer = 2.
|
|
check_regular.checkNext("max 2");
|
|
check_regular.checkStart("Section element");
|
|
check_regular.checkNext("entries 1");
|
|
check_regular.checkNext("table index 0");
|
|
check_regular.checkNext("i32.const 1"); // we want to start function indexes at 1
|
|
check_regular.checkNext("indexes 1"); // 1 function pointer
|
|
|
|
test_step.dependOn(&check_import.step);
|
|
test_step.dependOn(&check_export.step);
|
|
test_step.dependOn(&check_regular.step);
|
|
}
|