From 37b9a2e6a4aa59494406d38495768778502fbcda Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 19 Apr 2017 01:13:15 -0400 Subject: convert compare-output tests to use zig build system --- src/main.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 32b22e8bda..058fa7a884 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -168,6 +168,7 @@ int main(int argc, char **argv) { ZigList args = {0}; args.append(zig_exe_path); + args.append(NULL); // placeholder for (int i = 2; i < argc; i += 1) { if (strcmp(argv[i], "--debug-build-verbose") == 0) { verbose = true; @@ -202,6 +203,8 @@ int main(int argc, char **argv) { Buf build_file_dirname = BUF_INIT; os_path_split(&build_file_abs, &build_file_dirname, &build_file_basename); + args.items[1] = buf_ptr(&build_file_dirname); + bool build_file_exists; if ((err = os_file_exists(&build_file_abs, &build_file_exists))) { fprintf(stderr, "unable to open '%s': %s\n", buf_ptr(&build_file_abs), err_str(err)); -- cgit v1.2.3 From 666435195fff867417f92e1b4f8ef7e0608470ee Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 19 Apr 2017 04:36:48 -0400 Subject: update zig build help text when no build.zig found --- src/main.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 058fa7a884..044ac11517 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -217,11 +217,14 @@ int main(int argc, char **argv) { "Usage: %s build [options]\n" "\n" "General Options:\n" - " --help Print this help and exit.\n" - " --build-file [file] Override path to build.zig.\n" - " --verbose Print commands before executing them.\n" - " --debug-build-verbose Print verbose debugging information for the build system itself.\n" - " --prefix [prefix] Override default install prefix.\n" + " --help Print this help and exit\n" + " --build-file [file] Override path to build.zig\n" + " --verbose Print commands before executing them\n" + " --debug-build-verbose Print verbose debugging information for the build system itself\n" + " --prefix [prefix] Override default install prefix\n" + "\n" + "More options become available when the build file is found.\n" + "Run this command with no options to generate a build.zig template.\n" , zig_exe_path); return 0; } -- cgit v1.2.3 From d12f1f5b4954d893111c05420060354537a1485c Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 19 Apr 2017 15:38:12 -0400 Subject: test framework supports name prefix and filter argument rename self hosted tests to behavior tests --- build.zig | 20 +++++++------ src/all_types.hpp | 3 ++ src/analyze.cpp | 9 +++++- src/codegen.cpp | 8 ++++++ src/codegen.hpp | 2 ++ src/main.cpp | 17 +++++++++++ std/build.zig | 80 ++++++++++++++++++++++++++++++---------------------- test/behavior.zig | 39 +++++++++++++++++++++++++ test/self_hosted.zig | 39 ------------------------- test/tests.zig | 4 +-- 10 files changed, 137 insertions(+), 84 deletions(-) create mode 100644 test/behavior.zig delete mode 100644 test/self_hosted.zig (limited to 'src/main.cpp') diff --git a/build.zig b/build.zig index 4ce81914f8..fc9df1149f 100644 --- a/build.zig +++ b/build.zig @@ -5,18 +5,20 @@ pub fn build(b: &Builder) { const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter"); const test_step = b.step("test", "Run all the tests"); - const self_hosted_tests = b.step("test-self-hosted", "Run the self-hosted tests"); - test_step.dependOn(self_hosted_tests); + const behavior_tests = b.step("test-behavior", "Run the behavior tests"); + test_step.dependOn(behavior_tests); for ([]bool{false, true}) |release| { for ([]bool{false, true}) |link_libc| { - const these_tests = b.addTest("test/self_hosted.zig"); - // TODO add prefix to test names - // TODO pass test_filter to these_tests + const these_tests = b.addTest("test/behavior.zig"); + these_tests.setNamePrefix(b.fmt("behavior-{}-{} ", + if (release) "release" else "debug", + if (link_libc) "c" else "bare")); + these_tests.setFilter(test_filter); these_tests.setRelease(release); if (link_libc) { these_tests.linkLibrary("c"); } - self_hosted_tests.dependOn(&these_tests.step); + behavior_tests.dependOn(&these_tests.step); } } @@ -25,8 +27,10 @@ pub fn build(b: &Builder) { for ([]bool{false, true}) |release| { for ([]bool{false, true}) |link_libc| { const these_tests = b.addTest("std/index.zig"); - // TODO add prefix to test names - // TODO pass test_filter to these_tests + these_tests.setNamePrefix(b.fmt("std-{}-{} ", + if (release) "release" else "debug", + if (link_libc) "c" else "bare")); + these_tests.setFilter(test_filter); these_tests.setRelease(release); if (link_libc) { these_tests.linkLibrary("c"); diff --git a/src/all_types.hpp b/src/all_types.hpp index 8386050cae..5dc7b90578 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -1458,6 +1458,9 @@ struct CodeGen { ZigList link_objects; ZigList name_table_enums; + + Buf *test_filter; + Buf *test_name_prefix; }; enum VarLinkage { diff --git a/src/analyze.cpp b/src/analyze.cpp index af910cd590..aef85ca0b5 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -1959,7 +1959,14 @@ static void preview_test_decl(CodeGen *g, AstNode *node, ScopeDecls *decls_scope if (import->package != g->root_package) return; - Buf *test_name = node->data.test_decl.name; + Buf *decl_name_buf = node->data.test_decl.name; + + Buf *test_name = g->test_name_prefix ? + buf_sprintf("%s%s", buf_ptr(g->test_name_prefix), buf_ptr(decl_name_buf)) : decl_name_buf; + + if (g->test_filter != nullptr && strstr(buf_ptr(test_name), buf_ptr(g->test_filter)) == nullptr) { + return; + } TldFn *tld_fn = allocate(1); init_tld(&tld_fn->base, TldIdFn, test_name, VisibModPrivate, node, &decls_scope->base); diff --git a/src/codegen.cpp b/src/codegen.cpp index 3061c82766..fc57b49772 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -147,6 +147,14 @@ void codegen_set_omit_zigrt(CodeGen *g, bool omit_zigrt) { g->omit_zigrt = omit_zigrt; } +void codegen_set_test_filter(CodeGen *g, Buf *filter) { + g->test_filter = filter; +} + +void codegen_set_test_name_prefix(CodeGen *g, Buf *prefix) { + g->test_name_prefix = prefix; +} + void codegen_set_is_test(CodeGen *g, bool is_test_build) { g->is_test_build = is_test_build; } diff --git a/src/codegen.hpp b/src/codegen.hpp index e40fee9b1e..03aa6f53e4 100644 --- a/src/codegen.hpp +++ b/src/codegen.hpp @@ -44,6 +44,8 @@ void codegen_set_mmacosx_version_min(CodeGen *g, Buf *mmacosx_version_min); void codegen_set_mios_version_min(CodeGen *g, Buf *mios_version_min); void codegen_set_linker_script(CodeGen *g, const char *linker_script); void codegen_set_omit_zigrt(CodeGen *g, bool omit_zigrt); +void codegen_set_test_filter(CodeGen *g, Buf *filter); +void codegen_set_test_name_prefix(CodeGen *g, Buf *prefix); PackageTableEntry *new_package(const char *root_src_dir, const char *root_src_path); void codegen_add_root_code(CodeGen *g, Buf *source_dir, Buf *source_basename, Buf *source_code); diff --git a/src/main.cpp b/src/main.cpp index 044ac11517..1d37352427 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -64,6 +64,9 @@ static int usage(const char *arg0) { " -mwindows (windows only) --subsystem windows to the linker\n" " -rdynamic add all symbols to the dynamic symbol table\n" " -rpath [path] add directory to the runtime library search path\n" + "Test Options:\n" + " --test-filter [text] skip tests that do not match filter\n" + " --test-name-prefix [text] add prefix to all tests\n" , arg0); return EXIT_FAILURE; } @@ -151,6 +154,8 @@ int main(int argc, char **argv) { ZigList rpath_list = {0}; bool each_lib_rpath = false; ZigList objects = {0}; + const char *test_filter = nullptr; + const char *test_name_prefix = nullptr; if (argc >= 2 && strcmp(argv[1], "build") == 0) { const char *zig_exe_path = arg0; @@ -341,6 +346,10 @@ int main(int argc, char **argv) { linker_script = argv[i]; } else if (strcmp(arg, "-rpath") == 0) { rpath_list.append(argv[i]); + } else if (strcmp(arg, "--test-filter") == 0) { + test_filter = argv[i]; + } else if (strcmp(arg, "--test-name-prefix") == 0) { + test_name_prefix = argv[i]; } else { fprintf(stderr, "Invalid argument: %s\n", arg); return usage(arg0); @@ -562,6 +571,14 @@ int main(int argc, char **argv) { codegen_set_mios_version_min(g, buf_create_from_str(mios_version_min)); } + if (test_filter) { + codegen_set_test_filter(g, buf_create_from_str(test_filter)); + } + + if (test_name_prefix) { + codegen_set_test_name_prefix(g, buf_create_from_str(test_name_prefix)); + } + if (cmd == CmdBuild) { codegen_add_root_code(g, &root_source_dir, &root_source_name, &root_source_code); codegen_link(g, out_file); diff --git a/std/build.zig b/std/build.zig index c58a72eec3..20fb4cad5c 100644 --- a/std/build.zig +++ b/std/build.zig @@ -10,7 +10,7 @@ const StdIo = os.ChildProcess.StdIo; const Term = os.ChildProcess.Term; const BufSet = @import("buf_set.zig").BufSet; const BufMap = @import("buf_map.zig").BufMap; -const fmt = @import("fmt.zig"); +const fmt_lib = @import("fmt.zig"); error ExtraArg; error UncleanExit; @@ -189,7 +189,7 @@ pub const Builder = struct { } pub fn addLog(self: &Builder, comptime format: []const u8, args: ...) -> &LogStep { - const data = %%fmt.allocPrint(self.allocator, format, args); + const data = self.fmt(format, args); const log_step = %%self.allocator.create(LogStep); *log_step = LogStep.init(self, data); return log_step; @@ -543,6 +543,10 @@ pub const Builder = struct { fn pathFromRoot(self: &Builder, rel_path: []const u8) -> []u8 { return %%os.path.join(self.allocator, self.build_root, rel_path); } + + pub fn fmt(self: &Builder, comptime format: []const u8, args: ...) -> []u8 { + return %%fmt_lib.allocPrint(self.allocator, format, args); + } }; const Version = struct { @@ -891,19 +895,16 @@ pub const LinkStep = struct { fn computeOutFileName(self: &LinkStep) { switch (self.out_type) { OutType.Exe => { - self.out_filename = %%fmt.allocPrint(self.builder.allocator, "{}{}", - self.name, self.target.exeFileExt()); + self.out_filename = self.builder.fmt("{}{}", self.name, self.target.exeFileExt()); }, OutType.Lib => { if (self.static) { - self.out_filename = %%fmt.allocPrint(self.builder.allocator, "lib{}.a", self.name); + self.out_filename = self.builder.fmt("lib{}.a", self.name); } else { - self.out_filename = %%fmt.allocPrint(self.builder.allocator, "lib{}.so.{d}.{d}.{d}", + self.out_filename = self.builder.fmt("lib{}.so.{d}.{d}.{d}", self.name, self.version.major, self.version.minor, self.version.patch); - self.major_only_filename = %%fmt.allocPrint(self.builder.allocator, - "lib{}.so.{d}", self.name, self.version.major); - self.name_only_filename = %%fmt.allocPrint(self.builder.allocator, - "lib{}.so", self.name); + self.major_only_filename = self.builder.fmt("lib{}.so.{d}", self.name, self.version.major); + self.name_only_filename = self.builder.fmt("lib{}.so", self.name); } }, } @@ -1051,15 +1052,19 @@ pub const TestStep = struct { release: bool, verbose: bool, link_libs: BufSet, + name_prefix: []const u8, + filter: ?[]const u8, pub fn init(builder: &Builder, root_src: []const u8) -> TestStep { - const step_name = %%fmt.allocPrint(builder.allocator, "test {}", root_src); + const step_name = builder.fmt("test {}", root_src); TestStep { .step = Step.init(step_name, builder.allocator, make), .builder = builder, .root_src = root_src, .release = false, .verbose = false, + .name_prefix = "", + .filter = null, .link_libs = BufSet.init(builder.allocator), } } @@ -1076,6 +1081,14 @@ pub const TestStep = struct { %%self.link_libs.put(name); } + pub fn setNamePrefix(self: &TestStep, text: []const u8) { + self.name_prefix = text; + } + + pub fn setFilter(self: &TestStep, text: ?[]const u8) { + self.filter = text; + } + fn make(step: &Step) -> %void { const self = @fieldParentPtr(TestStep, "step", step); const builder = self.builder; @@ -1094,6 +1107,16 @@ pub const TestStep = struct { %%zig_args.append("--release"); } + if (const filter ?= self.filter) { + %%zig_args.append("--test-filter"); + %%zig_args.append(filter); + } + + if (self.name_prefix.len != 0) { + %%zig_args.append("--test-name-prefix"); + %%zig_args.append(self.name_prefix); + } + { var it = self.link_libs.iterator(); while (true) { @@ -1169,14 +1192,12 @@ pub const CLibrary = struct { fn computeOutFileName(self: &CLibrary) { if (self.static) { - self.out_filename = %%fmt.allocPrint(self.builder.allocator, "lib{}.a", self.name); + self.out_filename = self.builder.fmt("lib{}.a", self.name); } else { - self.out_filename = %%fmt.allocPrint(self.builder.allocator, "lib{}.so.{d}.{d}.{d}", + self.out_filename = self.builder.fmt("lib{}.so.{d}.{d}.{d}", self.name, self.version.major, self.version.minor, self.version.patch); - self.major_only_filename = %%fmt.allocPrint(self.builder.allocator, - "lib{}.so.{d}", self.name, self.version.major); - self.name_only_filename = %%fmt.allocPrint(self.builder.allocator, - "lib{}.so", self.name); + self.major_only_filename = self.builder.fmt("lib{}.so.{d}", self.name, self.version.major); + self.name_only_filename = self.builder.fmt("lib{}.so", self.name); } } @@ -1235,7 +1256,7 @@ pub const CLibrary = struct { %%cc_args.append(source_file); // TODO don't dump the .o file in the same place as the source file - const o_file = %%fmt.allocPrint(builder.allocator, "{}{}", source_file, self.target.oFileExt()); + const o_file = builder.fmt("{}{}", source_file, self.target.oFileExt()); defer builder.allocator.free(o_file); %%cc_args.append("-o"); %%cc_args.append(o_file); @@ -1262,8 +1283,7 @@ pub const CLibrary = struct { %%cc_args.append("-fPIC"); %%cc_args.append("-shared"); - const soname_arg = %%fmt.allocPrint(builder.allocator, "-Wl,-soname,lib{}.so.{d}", - self.name, self.version.major); + const soname_arg = builder.fmt("-Wl,-soname,lib{}.so.{d}", self.name, self.version.major); defer builder.allocator.free(soname_arg); %%cc_args.append(soname_arg); @@ -1372,7 +1392,7 @@ pub const CExecutable = struct { %%cc_args.append(source_file); // TODO don't dump the .o file in the same place as the source file - const o_file = %%fmt.allocPrint(builder.allocator, "{}{}", source_file, self.target.oFileExt()); + const o_file = builder.fmt("{}{}", source_file, self.target.oFileExt()); defer builder.allocator.free(o_file); %%cc_args.append("-o"); %%cc_args.append(o_file); @@ -1400,7 +1420,7 @@ pub const CExecutable = struct { %%cc_args.append("-o"); %%cc_args.append(self.name); - const rpath_arg = %%fmt.allocPrint(builder.allocator, "-Wl,-rpath,{}", builder.out_dir); + const rpath_arg = builder.fmt("-Wl,-rpath,{}", builder.out_dir); defer builder.allocator.free(rpath_arg); %%cc_args.append(rpath_arg); @@ -1462,9 +1482,7 @@ pub const InstallCLibraryStep = struct { pub fn init(builder: &Builder, lib: &CLibrary) -> InstallCLibraryStep { var self = InstallCLibraryStep { .builder = builder, - .step = Step.init( - %%fmt.allocPrint(builder.allocator, "install {}", lib.step.name), - builder.allocator, make), + .step = Step.init(builder.fmt("install {}", lib.step.name), builder.allocator, make), .lib = lib, .dest_file = undefined, }; @@ -1497,9 +1515,7 @@ pub const InstallFileStep = struct { pub fn init(builder: &Builder, src_path: []const u8, dest_path: []const u8) -> InstallFileStep { return InstallFileStep { .builder = builder, - .step = Step.init( - %%fmt.allocPrint(builder.allocator, "install {}", src_path), - builder.allocator, make), + .step = Step.init(builder.fmt("install {}", src_path), builder.allocator, make), .src_path = src_path, .dest_path = dest_path, }; @@ -1521,9 +1537,7 @@ pub const WriteFileStep = struct { pub fn init(builder: &Builder, file_path: []const u8, data: []const u8) -> WriteFileStep { return WriteFileStep { .builder = builder, - .step = Step.init( - %%fmt.allocPrint(builder.allocator, "writefile {}", file_path), - builder.allocator, make), + .step = Step.init(builder.fmt("writefile {}", file_path), builder.allocator, make), .file_path = file_path, .data = data, }; @@ -1550,9 +1564,7 @@ pub const LogStep = struct { pub fn init(builder: &Builder, data: []const u8) -> LogStep { return LogStep { .builder = builder, - .step = Step.init( - %%fmt.allocPrint(builder.allocator, "log {}", data), - builder.allocator, make), + .step = Step.init(builder.fmt("log {}", data), builder.allocator, make), .data = data, }; } diff --git a/test/behavior.zig b/test/behavior.zig new file mode 100644 index 0000000000..98d0277f78 --- /dev/null +++ b/test/behavior.zig @@ -0,0 +1,39 @@ +comptime { + _ = @import("cases/array.zig"); + _ = @import("cases/asm.zig"); + _ = @import("cases/atomics.zig"); + _ = @import("cases/bool.zig"); + _ = @import("cases/cast.zig"); + _ = @import("cases/const_slice_child.zig"); + _ = @import("cases/defer.zig"); + _ = @import("cases/enum.zig"); + _ = @import("cases/enum_with_members.zig"); + _ = @import("cases/error.zig"); + _ = @import("cases/eval.zig"); + _ = @import("cases/field_parent_ptr.zig"); + _ = @import("cases/fn.zig"); + _ = @import("cases/for.zig"); + _ = @import("cases/generics.zig"); + _ = @import("cases/goto.zig"); + _ = @import("cases/if.zig"); + _ = @import("cases/import.zig"); + _ = @import("cases/incomplete_struct_param_tld.zig"); + _ = @import("cases/ir_block_deps.zig"); + _ = @import("cases/math.zig"); + _ = @import("cases/misc.zig"); + _ = @import("cases/namespace_depends_on_compile_var/index.zig"); + _ = @import("cases/null.zig"); + _ = @import("cases/pub_enum/index.zig"); + _ = @import("cases/sizeof_and_typeof.zig"); + _ = @import("cases/struct.zig"); + _ = @import("cases/struct_contains_slice_of_itself.zig"); + _ = @import("cases/switch.zig"); + _ = @import("cases/switch_prong_err_enum.zig"); + _ = @import("cases/switch_prong_implicit_cast.zig"); + _ = @import("cases/this.zig"); + _ = @import("cases/try.zig"); + _ = @import("cases/undefined.zig"); + _ = @import("cases/var_args.zig"); + _ = @import("cases/void.zig"); + _ = @import("cases/while.zig"); +} diff --git a/test/self_hosted.zig b/test/self_hosted.zig deleted file mode 100644 index 98d0277f78..0000000000 --- a/test/self_hosted.zig +++ /dev/null @@ -1,39 +0,0 @@ -comptime { - _ = @import("cases/array.zig"); - _ = @import("cases/asm.zig"); - _ = @import("cases/atomics.zig"); - _ = @import("cases/bool.zig"); - _ = @import("cases/cast.zig"); - _ = @import("cases/const_slice_child.zig"); - _ = @import("cases/defer.zig"); - _ = @import("cases/enum.zig"); - _ = @import("cases/enum_with_members.zig"); - _ = @import("cases/error.zig"); - _ = @import("cases/eval.zig"); - _ = @import("cases/field_parent_ptr.zig"); - _ = @import("cases/fn.zig"); - _ = @import("cases/for.zig"); - _ = @import("cases/generics.zig"); - _ = @import("cases/goto.zig"); - _ = @import("cases/if.zig"); - _ = @import("cases/import.zig"); - _ = @import("cases/incomplete_struct_param_tld.zig"); - _ = @import("cases/ir_block_deps.zig"); - _ = @import("cases/math.zig"); - _ = @import("cases/misc.zig"); - _ = @import("cases/namespace_depends_on_compile_var/index.zig"); - _ = @import("cases/null.zig"); - _ = @import("cases/pub_enum/index.zig"); - _ = @import("cases/sizeof_and_typeof.zig"); - _ = @import("cases/struct.zig"); - _ = @import("cases/struct_contains_slice_of_itself.zig"); - _ = @import("cases/switch.zig"); - _ = @import("cases/switch_prong_err_enum.zig"); - _ = @import("cases/switch_prong_implicit_cast.zig"); - _ = @import("cases/this.zig"); - _ = @import("cases/try.zig"); - _ = @import("cases/undefined.zig"); - _ = @import("cases/var_args.zig"); - _ = @import("cases/void.zig"); - _ = @import("cases/while.zig"); -} diff --git a/test/tests.zig b/test/tests.zig index 61dc1fc051..8e15bcc126 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -341,8 +341,8 @@ pub const CompareOutputContext = struct { }, Special.None => { for ([]bool{false, true}) |release| { - const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "{} ({})", - case.name, if (release) "release" else "debug"); + const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "{} {} ({})", + "compare-output", case.name, if (release) "release" else "debug"); if (const filter ?= self.test_filter) { if (mem.indexOf(u8, annotated_case_name, filter) == null) continue; -- cgit v1.2.3