| author | |
| committer | |
| log | 7ee00730ac5679ea5e24fac352ed9b72469f9329 |
| tree | f05bee8200126abc3fe9b4ac019357fe239078e2 |
| parent | a9ecb26c34d77f616fb029af3d09ffd69b9aa178 |
5 files changed, 58 insertions(+), 11 deletions(-)
build.zig+7-3| ... | ... | @@ -3,16 +3,20 @@ const tests = @import("test/tests.zig"); |
| 3 | 3 | |
| 4 | 4 | pub fn build(b: &Builder) { |
| 5 | 5 | const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter"); |
| 6 | const with_lldb = b.option(bool, "with-lldb", "Run tests in LLDB to get a backtrace if one fails") ?? false; | |
| 6 | 7 | const test_step = b.step("test", "Run all the tests"); |
| 7 | 8 | |
| 8 | 9 | test_step.dependOn(tests.addPkgTests(b, test_filter, |
| 9 | "test/behavior.zig", "behavior", "Run the behavior tests")); | |
| 10 | "test/behavior.zig", "behavior", "Run the behavior tests", | |
| 11 | with_lldb)); | |
| 10 | 12 | |
| 11 | 13 | test_step.dependOn(tests.addPkgTests(b, test_filter, |
| 12 | "std/index.zig", "std", "Run the standard library tests")); | |
| 14 | "std/index.zig", "std", "Run the standard library tests", | |
| 15 | with_lldb)); | |
| 13 | 16 | |
| 14 | 17 | test_step.dependOn(tests.addPkgTestsAlwaysLibc(b, test_filter, |
| 15 | "std/special/compiler_rt/index.zig", "compiler-rt", "Run the compiler_rt tests")); | |
| 18 | "std/special/compiler_rt/index.zig", "compiler-rt", "Run the compiler_rt tests", | |
| 19 | with_lldb)); | |
| 16 | 20 | |
| 17 | 21 | test_step.dependOn(tests.addCompareOutputTests(b, test_filter)); |
| 18 | 22 | test_step.dependOn(tests.addBuildExampleTests(b, test_filter)); |
ci/travis_osx_script+1-1| ... | ... | @@ -7,4 +7,4 @@ cd build |
| 7 | 7 | cmake .. -DCMAKE_PREFIX_PATH=/usr/local/opt/llvm@5/ -DCMAKE_INSTALL_PREFIX=$(pwd) -DZIG_LIBC_LIB_DIR=$(dirname $($CC -print-file-name=crt1.o)) -DZIG_LIBC_INCLUDE_DIR=$(echo -n | $CC -E -x c - -v 2>&1 | grep -B1 "End of search list." | head -n1 | cut -c 2- | sed "s/ .*//") -DZIG_LIBC_STATIC_LIB_DIR=$(dirname $($CC -print-file-name=crtbegin.o)) |
| 8 | 8 | make VERBOSE=1 |
| 9 | 9 | make install |
| 10 | ./zig build --build-file ../build.zig test | |
| 10 | ./zig build --build-file ../build.zig test -Dwith-lldb |
src/main.cpp+24-2| ... | ... | @@ -75,6 +75,8 @@ static int usage(const char *arg0) { |
| 75 | 75 | "Test Options:\n" |
| 76 | 76 | " --test-filter [text] skip tests that do not match filter\n" |
| 77 | 77 | " --test-name-prefix [text] add prefix to all tests\n" |
| 78 | " --test-cmd [arg] specify test execution command one arg at a time\n" | |
| 79 | " --test-cmd-bin appends test binary path to test cmd args\n" | |
| 78 | 80 | , arg0); |
| 79 | 81 | return EXIT_FAILURE; |
| 80 | 82 | } |
| ... | ... | @@ -215,6 +217,7 @@ int main(int argc, char **argv) { |
| 215 | 217 | const char *cache_dir = nullptr; |
| 216 | 218 | CliPkg *cur_pkg = allocate<CliPkg>(1); |
| 217 | 219 | BuildMode build_mode = BuildModeDebug; |
| 220 | ZigList<const char *> test_exec_args = {0}; | |
| 218 | 221 | |
| 219 | 222 | if (argc >= 2 && strcmp(argv[1], "build") == 0) { |
| 220 | 223 | const char *zig_exe_path = arg0; |
| ... | ... | @@ -355,6 +358,8 @@ int main(int argc, char **argv) { |
| 355 | 358 | each_lib_rpath = true; |
| 356 | 359 | } else if (strcmp(arg, "--enable-timing-info") == 0) { |
| 357 | 360 | timing_info = true; |
| 361 | } else if (strcmp(arg, "--test-cmd-bin") == 0) { | |
| 362 | test_exec_args.append(nullptr); | |
| 358 | 363 | } else if (arg[1] == 'L' && arg[2] != 0) { |
| 359 | 364 | // alias for --library-path |
| 360 | 365 | lib_dirs.append(&arg[2]); |
| ... | ... | @@ -451,6 +456,8 @@ int main(int argc, char **argv) { |
| 451 | 456 | ver_minor = atoi(argv[i]); |
| 452 | 457 | } else if (strcmp(arg, "--ver-patch") == 0) { |
| 453 | 458 | ver_patch = atoi(argv[i]); |
| 459 | } else if (strcmp(arg, "--test-cmd") == 0) { | |
| 460 | test_exec_args.append(argv[i]); | |
| 454 | 461 | } else { |
| 455 | 462 | fprintf(stderr, "Invalid argument: %s\n", arg); |
| 456 | 463 | return usage(arg0); |
| ... | ... | @@ -682,6 +689,12 @@ int main(int argc, char **argv) { |
| 682 | 689 | |
| 683 | 690 | Buf *test_exe_name = buf_sprintf("./test%s", target_exe_file_ext(non_null_target)); |
| 684 | 691 | |
| 692 | for (size_t i = 0; i < test_exec_args.length; i += 1) { | |
| 693 | if (test_exec_args.items[i] == nullptr) { | |
| 694 | test_exec_args.items[i] = buf_ptr(test_exe_name); | |
| 695 | } | |
| 696 | } | |
| 697 | ||
| 685 | 698 | codegen_build(g); |
| 686 | 699 | codegen_link(g, buf_ptr(test_exe_name)); |
| 687 | 700 | |
| ... | ... | @@ -693,9 +706,18 @@ int main(int argc, char **argv) { |
| 693 | 706 | return 0; |
| 694 | 707 | } |
| 695 | 708 | |
| 696 | ZigList<const char *> args = {0}; | |
| 697 | 709 | Termination term; |
| 698 | os_spawn_process(buf_ptr(test_exe_name), args, &term); | |
| 710 | if (test_exec_args.length > 0) { | |
| 711 | ZigList<const char *> rest_args = {0}; | |
| 712 | for (size_t i = 1; i < test_exec_args.length; i += 1) { | |
| 713 | rest_args.append(test_exec_args.at(i)); | |
| 714 | } | |
| 715 | os_spawn_process(test_exec_args.items[0], rest_args, &term); | |
| 716 | } else { | |
| 717 | ZigList<const char *> no_args = {0}; | |
| 718 | os_spawn_process(buf_ptr(test_exe_name), no_args, &term); | |
| 719 | } | |
| 720 | ||
| 699 | 721 | if (term.how != TerminationIdClean || term.code != 0) { |
| 700 | 722 | fprintf(stderr, "\nTests failed. Use the following command to reproduce the failure:\n"); |
| 701 | 723 | fprintf(stderr, "%s\n", buf_ptr(test_exe_name)); |
std/build.zig+17| ... | ... | @@ -1028,6 +1028,7 @@ pub const TestStep = struct { |
| 1028 | 1028 | name_prefix: []const u8, |
| 1029 | 1029 | filter: ?[]const u8, |
| 1030 | 1030 | target: Target, |
| 1031 | exec_cmd_args: ?[]const ?[]const u8, | |
| 1031 | 1032 | |
| 1032 | 1033 | pub fn init(builder: &Builder, root_src: []const u8) -> TestStep { |
| 1033 | 1034 | const step_name = builder.fmt("test {}", root_src); |
| ... | ... | @@ -1041,6 +1042,7 @@ pub const TestStep = struct { |
| 1041 | 1042 | .filter = null, |
| 1042 | 1043 | .link_libs = BufSet.init(builder.allocator), |
| 1043 | 1044 | .target = Target.Native, |
| 1045 | .exec_cmd_args = null, | |
| 1044 | 1046 | } |
| 1045 | 1047 | } |
| 1046 | 1048 | |
| ... | ... | @@ -1076,6 +1078,10 @@ pub const TestStep = struct { |
| 1076 | 1078 | }; |
| 1077 | 1079 | } |
| 1078 | 1080 | |
| 1081 | pub fn setExecCmd(self: &TestStep, args: []const ?[]const u8) { | |
| 1082 | self.exec_cmd_args = args; | |
| 1083 | } | |
| 1084 | ||
| 1079 | 1085 | fn make(step: &Step) -> %void { |
| 1080 | 1086 | const self = @fieldParentPtr(TestStep, "step", step); |
| 1081 | 1087 | const builder = self.builder; |
| ... | ... | @@ -1129,6 +1135,17 @@ pub const TestStep = struct { |
| 1129 | 1135 | } |
| 1130 | 1136 | } |
| 1131 | 1137 | |
| 1138 | if (self.exec_cmd_args) |exec_cmd_args| { | |
| 1139 | for (exec_cmd_args) |cmd_arg| { | |
| 1140 | if (cmd_arg) |arg| { | |
| 1141 | %%zig_args.append("--test-cmd"); | |
| 1142 | %%zig_args.append(arg); | |
| 1143 | } else { | |
| 1144 | %%zig_args.append("--test-cmd-bin"); | |
| 1145 | } | |
| 1146 | } | |
| 1147 | } | |
| 1148 | ||
| 1132 | 1149 | for (builder.include_paths.toSliceConst()) |include_path| { |
| 1133 | 1150 | %%zig_args.append("-isystem"); |
| 1134 | 1151 | %%zig_args.append(builder.pathFromRoot(include_path)); |
test/tests.zig+9-5| ... | ... | @@ -130,19 +130,19 @@ pub fn addParseCTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Ste |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | pub fn addPkgTests(b: &build.Builder, test_filter: ?[]const u8, root_src: []const u8, |
| 133 | name:[] const u8, desc: []const u8) -> &build.Step | |
| 133 | name:[] const u8, desc: []const u8, with_lldb: bool) -> &build.Step | |
| 134 | 134 | { |
| 135 | return addPkgTestsRaw(b, test_filter, root_src, name, desc, false); | |
| 135 | return addPkgTestsRaw(b, test_filter, root_src, name, desc, false, with_lldb); | |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | pub fn addPkgTestsAlwaysLibc(b: &build.Builder, test_filter: ?[]const u8, root_src: []const u8, |
| 139 | name:[] const u8, desc: []const u8) -> &build.Step | |
| 139 | name:[] const u8, desc: []const u8, with_lldb: bool) -> &build.Step | |
| 140 | 140 | { |
| 141 | return addPkgTestsRaw(b, test_filter, root_src, name, desc, true); | |
| 141 | return addPkgTestsRaw(b, test_filter, root_src, name, desc, true, with_lldb); | |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | pub fn addPkgTestsRaw(b: &build.Builder, test_filter: ?[]const u8, root_src: []const u8, |
| 145 | name:[] const u8, desc: []const u8, always_link_libc: bool) -> &build.Step | |
| 145 | name:[] const u8, desc: []const u8, always_link_libc: bool, with_lldb: bool) -> &build.Step | |
| 146 | 146 | { |
| 147 | 147 | const libc_bools = if (always_link_libc) []bool{true} else []bool{false, true}; |
| 148 | 148 | const step = b.step(b.fmt("test-{}", name), desc); |
| ... | ... | @@ -165,6 +165,10 @@ pub fn addPkgTestsRaw(b: &build.Builder, test_filter: ?[]const u8, root_src: []c |
| 165 | 165 | if (link_libc) { |
| 166 | 166 | these_tests.linkSystemLibrary("c"); |
| 167 | 167 | } |
| 168 | if (with_lldb) { | |
| 169 | these_tests.setExecCmd([]?[]const u8{ | |
| 170 | "lldb", null, "-o", "run", "-o", "bt", "-o", "exit"}); | |
| 171 | } | |
| 168 | 172 | step.dependOn(&these_tests.step); |
| 169 | 173 | } |
| 170 | 174 | } |