authorgravatar for wozeparrot@gmail.comwozeparrot <wozeparrot@gmail.com> 2020-10-29 15:16:47-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-10-29 15:16:47-04:00
log32e65c3f96b5418acf4d444714facbba98790a91
treeabadcf4c47d677bd8f7f2bb49512c307c6f443dc
parent3a0e8c2b45e57e75cedd052b00fd7ae46def8383
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

make addBuildOption append type (#6801)

* add addBuildOption test

1 files changed, 29 insertions(+), 1 deletions(-)

lib/std/build.zig+29-1
......@@ -1816,7 +1816,7 @@ pub const LibExeObjStep = struct {
18161816 },
18171817 else => {},
18181818 }
1819 out.print("pub const {z} = {};\n", .{ name, value }) catch unreachable;
1819 out.print("pub const {z}: {} = {};\n", .{ name, @typeName(T), value }) catch unreachable;
18201820 }
18211821
18221822 /// The value is the path in the cache dir.
......@@ -2751,6 +2751,34 @@ test "Builder.dupePkg()" {
27512751 std.testing.expect(dupe_deps[0].path.ptr != pkg_dep.path.ptr);
27522752}
27532753
2754test "LibExeObjStep.addBuildOption" {
2755 if (builtin.os.tag == .wasi) return error.SkipZigTest;
2756
2757 var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
2758 defer arena.deinit();
2759 var builder = try Builder.create(
2760 &arena.allocator,
2761 "test",
2762 "test",
2763 "test",
2764 );
2765 defer builder.destroy();
2766
2767 var exe = builder.addExecutable("not_an_executable", "/not/an/executable.zig");
2768 exe.addBuildOption(usize, "option1", 1);
2769 exe.addBuildOption(?usize, "option2", null);
2770 exe.addBuildOption([]const u8, "string", "zigisthebest");
2771 exe.addBuildOption(?[]const u8, "optional_string", null);
2772
2773 std.testing.expectEqualStrings(
2774 \\pub const option1: usize = 1;
2775 \\pub const option2: ?usize = null;
2776 \\pub const string: []const u8 = "zigisthebest";
2777 \\pub const optional_string: ?[]const u8 = null;
2778 \\
2779 , exe.build_options_contents.items);
2780}
2781
27542782test "LibExeObjStep.addPackage" {
27552783 if (builtin.os.tag == .wasi) return error.SkipZigTest;
27562784