From 9dcddc2249217c8c99c9d07bb0187904847d2ae2 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 16 Jul 2019 12:15:46 -0400 Subject: [PATCH] retire the example/ folder, rename test-build-examples to "standalone" closes #2759 --- build.zig | 2 +- example/README.md | 14 ------------ example/hello_world/hello_windows.zig | 8 ------- test/{build_examples.zig => standalone.zig} | 14 ++++++------ {example => test/standalone}/cat/main.zig | 0 .../standalone}/guess_number/main.zig | 0 .../standalone}/hello_world/hello.zig | 0 .../standalone}/hello_world/hello_libc.zig | 0 .../standalone}/mix_o_files/base64.zig | 0 .../standalone}/mix_o_files/build.zig | 0 .../standalone}/mix_o_files/test.c | 0 .../standalone}/shared_library/build.zig | 0 .../standalone}/shared_library/mathtest.zig | 0 .../standalone}/shared_library/test.c | 0 test/tests.zig | 22 +++++++++---------- 15 files changed, 19 insertions(+), 41 deletions(-) delete mode 100644 example/README.md delete mode 100644 example/hello_world/hello_windows.zig rename test/{build_examples.zig => standalone.zig} (75%) rename {example => test/standalone}/cat/main.zig (100%) rename {example => test/standalone}/guess_number/main.zig (100%) rename {example => test/standalone}/hello_world/hello.zig (100%) rename {example => test/standalone}/hello_world/hello_libc.zig (100%) rename {example => test/standalone}/mix_o_files/base64.zig (100%) rename {example => test/standalone}/mix_o_files/build.zig (100%) rename {example => test/standalone}/mix_o_files/test.c (100%) rename {example => test/standalone}/shared_library/build.zig (100%) rename {example => test/standalone}/shared_library/mathtest.zig (100%) rename {example => test/standalone}/shared_library/test.c (100%) diff --git a/build.zig b/build.zig index 2cd0804894..07041d026f 100644 --- a/build.zig +++ b/build.zig @@ -134,7 +134,7 @@ pub fn build(b: *Builder) !void { test_step.dependOn(tests.addPkgTests(b, test_filter, "std/special/compiler_rt.zig", "compiler-rt", "Run the compiler_rt tests", modes, skip_non_native)); test_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes)); - test_step.dependOn(tests.addBuildExampleTests(b, test_filter, modes)); + test_step.dependOn(tests.addStandaloneTests(b, test_filter, modes)); test_step.dependOn(tests.addCliTests(b, test_filter, modes)); test_step.dependOn(tests.addCompileErrorTests(b, test_filter, modes)); test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter, modes)); diff --git a/example/README.md b/example/README.md deleted file mode 100644 index 188ece00a2..0000000000 --- a/example/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# Zig Examples - - * **Tetris** - A simple Tetris clone written in Zig. See - [andrewrk/tetris](https://github.com/andrewrk/tetris). - * **hello_world** - demonstration of a printing a single line to stdout. - One version depends on libc; one does not. - * **guess_number** - simple console game where you guess the number the - computer is thinking of and it says higher or lower. No dependency on - libc. - * **cat** - implementation of the `cat` UNIX utility in Zig, with no dependency - on libc. - * **shared_library** - demonstration of building a shared library and generating - a header file for interop with C code. - * **mix_o_files** - how to mix .zig and .c files together as object files diff --git a/example/hello_world/hello_windows.zig b/example/hello_world/hello_windows.zig deleted file mode 100644 index 8016c3c490..0000000000 --- a/example/hello_world/hello_windows.zig +++ /dev/null @@ -1,8 +0,0 @@ -use @import("std").os.windows; - -extern "user32" stdcallcc fn MessageBoxA(hWnd: ?HANDLE, lpText: ?LPCTSTR, lpCaption: ?LPCTSTR, uType: UINT) c_int; - -export fn WinMain(hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: PWSTR, nCmdShow: INT) INT { - _ = MessageBoxA(null, c"hello", c"title", 0); - return 0; -} diff --git a/test/build_examples.zig b/test/standalone.zig similarity index 75% rename from test/build_examples.zig rename to test/standalone.zig index 4733a25b64..f3a1f735da 100644 --- a/test/build_examples.zig +++ b/test/standalone.zig @@ -2,16 +2,16 @@ const tests = @import("tests.zig"); const builtin = @import("builtin"); const is_windows = builtin.os == builtin.Os.windows; -pub fn addCases(cases: *tests.BuildExamplesContext) void { - cases.add("example/hello_world/hello.zig"); - cases.addC("example/hello_world/hello_libc.zig"); - cases.add("example/cat/main.zig"); - cases.add("example/guess_number/main.zig"); +pub fn addCases(cases: *tests.StandaloneContext) void { + cases.add("test/standalone/hello_world/hello.zig"); + cases.addC("test/standalone/hello_world/hello_libc.zig"); + cases.add("test/standalone/cat/main.zig"); + cases.add("test/standalone/guess_number/main.zig"); cases.add("test/standalone/main_return_error/error_u8.zig"); cases.add("test/standalone/main_return_error/error_u8_non_zero.zig"); cases.addBuildFile("test/standalone/main_pkg_path/build.zig"); - cases.addBuildFile("example/shared_library/build.zig"); - cases.addBuildFile("example/mix_o_files/build.zig"); + cases.addBuildFile("test/standalone/shared_library/build.zig"); + cases.addBuildFile("test/standalone/mix_o_files/build.zig"); cases.addBuildFile("test/standalone/static_c_lib/build.zig"); cases.addBuildFile("test/standalone/issue_339/build.zig"); cases.addBuildFile("test/standalone/issue_794/build.zig"); diff --git a/example/cat/main.zig b/test/standalone/cat/main.zig similarity index 100% rename from example/cat/main.zig rename to test/standalone/cat/main.zig diff --git a/example/guess_number/main.zig b/test/standalone/guess_number/main.zig similarity index 100% rename from example/guess_number/main.zig rename to test/standalone/guess_number/main.zig diff --git a/example/hello_world/hello.zig b/test/standalone/hello_world/hello.zig similarity index 100% rename from example/hello_world/hello.zig rename to test/standalone/hello_world/hello.zig diff --git a/example/hello_world/hello_libc.zig b/test/standalone/hello_world/hello_libc.zig similarity index 100% rename from example/hello_world/hello_libc.zig rename to test/standalone/hello_world/hello_libc.zig diff --git a/example/mix_o_files/base64.zig b/test/standalone/mix_o_files/base64.zig similarity index 100% rename from example/mix_o_files/base64.zig rename to test/standalone/mix_o_files/base64.zig diff --git a/example/mix_o_files/build.zig b/test/standalone/mix_o_files/build.zig similarity index 100% rename from example/mix_o_files/build.zig rename to test/standalone/mix_o_files/build.zig diff --git a/example/mix_o_files/test.c b/test/standalone/mix_o_files/test.c similarity index 100% rename from example/mix_o_files/test.c rename to test/standalone/mix_o_files/test.c diff --git a/example/shared_library/build.zig b/test/standalone/shared_library/build.zig similarity index 100% rename from example/shared_library/build.zig rename to test/standalone/shared_library/build.zig diff --git a/example/shared_library/mathtest.zig b/test/standalone/shared_library/mathtest.zig similarity index 100% rename from example/shared_library/mathtest.zig rename to test/standalone/shared_library/mathtest.zig diff --git a/example/shared_library/test.c b/test/standalone/shared_library/test.c similarity index 100% rename from example/shared_library/test.c rename to test/standalone/shared_library/test.c diff --git a/test/tests.zig b/test/tests.zig index 411f16d92b..d94c012ac1 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -13,7 +13,7 @@ const Mode = builtin.Mode; const LibExeObjStep = build.LibExeObjStep; const compare_output = @import("compare_output.zig"); -const build_examples = @import("build_examples.zig"); +const standalone = @import("standalone.zig"); const compile_errors = @import("compile_errors.zig"); const assemble_and_link = @import("assemble_and_link.zig"); const runtime_safety = @import("runtime_safety.zig"); @@ -91,17 +91,17 @@ pub fn addCompileErrorTests(b: *build.Builder, test_filter: ?[]const u8, modes: return cases.step; } -pub fn addBuildExampleTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step { - const cases = b.allocator.create(BuildExamplesContext) catch unreachable; - cases.* = BuildExamplesContext{ +pub fn addStandaloneTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step { + const cases = b.allocator.create(StandaloneContext) catch unreachable; + cases.* = StandaloneContext{ .b = b, - .step = b.step("test-build-examples", "Build the examples"), + .step = b.step("test-standalone", "Run the standalone tests"), .test_index = 0, .test_filter = test_filter, .modes = modes, }; - build_examples.addCases(cases); + standalone.addCases(cases); return cases.step; } @@ -830,22 +830,22 @@ pub const CompileErrorContext = struct { } }; -pub const BuildExamplesContext = struct { +pub const StandaloneContext = struct { b: *build.Builder, step: *build.Step, test_index: usize, test_filter: ?[]const u8, modes: []const Mode, - pub fn addC(self: *BuildExamplesContext, root_src: []const u8) void { + pub fn addC(self: *StandaloneContext, root_src: []const u8) void { self.addAllArgs(root_src, true); } - pub fn add(self: *BuildExamplesContext, root_src: []const u8) void { + pub fn add(self: *StandaloneContext, root_src: []const u8) void { self.addAllArgs(root_src, false); } - pub fn addBuildFile(self: *BuildExamplesContext, build_file: []const u8) void { + pub fn addBuildFile(self: *StandaloneContext, build_file: []const u8) void { const b = self.b; const annotated_case_name = b.fmt("build {} (Debug)", build_file); @@ -875,7 +875,7 @@ pub const BuildExamplesContext = struct { self.step.dependOn(&log_step.step); } - pub fn addAllArgs(self: *BuildExamplesContext, root_src: []const u8, link_libc: bool) void { + pub fn addAllArgs(self: *StandaloneContext, root_src: []const u8, link_libc: bool) void { const b = self.b; for (self.modes) |mode| {