| 1 | const std = @import("std"); |
| 2 | |
| 3 | pub const Enum = enum { alfa, bravo, charlie }; |
| 4 | |
| 5 | pub fn build(b: *std.Build) !void { |
| 6 | const target = b.standardTargetOptions(.{}); |
| 7 | const optimize = b.standardOptimizeOption(.{}); |
| 8 | |
| 9 | const expected_bool: bool = true; |
| 10 | const expected_int: i64 = 123; |
| 11 | const expected_float: f64 = 0.5; |
| 12 | const expected_string: []const u8 = "abc"; |
| 13 | const expected_string_list: []const []const u8 = &.{ "a", "b", "c" }; |
| 14 | const expected_lazy_path: std.Build.LazyPath = .{ .cwd_relative = "abc.txt" }; |
| 15 | const expected_lazy_path_list: []const std.Build.LazyPath = &.{ |
| 16 | .{ .cwd_relative = "a.txt" }, |
| 17 | .{ .cwd_relative = "b.txt" }, |
| 18 | .{ .cwd_relative = "c.txt" }, |
| 19 | }; |
| 20 | const expected_enum: Enum = .alfa; |
| 21 | const expected_enum_list: []const Enum = &.{ .alfa, .bravo, .charlie }; |
| 22 | const expected_build_id: std.zig.BuildId = .uuid; |
| 23 | const expected_hex_build_id: std.zig.BuildId = .initHexString("\x12\x34\xcd\xef"); |
| 24 | |
| 25 | const @"bool" = b.option(bool, "bool", "bool") orelse expected_bool; |
| 26 | const int = b.option(i64, "int", "int") orelse expected_int; |
| 27 | const float = b.option(f64, "float", "float") orelse expected_float; |
| 28 | const string = b.option([]const u8, "string", "string") orelse expected_string; |
| 29 | const string_list = b.option([]const []const u8, "string_list", "string_list") orelse expected_string_list; |
| 30 | const lazy_path = b.option(std.Build.LazyPath, "lazy_path", "lazy_path") orelse expected_lazy_path; |
| 31 | const lazy_path_list = b.option([]const std.Build.LazyPath, "lazy_path_list", "lazy_path_list") orelse expected_lazy_path_list; |
| 32 | const @"enum" = b.option(Enum, "enum", "enum") orelse expected_enum; |
| 33 | const enum_list = b.option([]const Enum, "enum_list", "enum_list") orelse expected_enum_list; |
| 34 | const build_id = b.option(std.zig.BuildId, "build_id", "build_id") orelse expected_build_id; |
| 35 | const hex_build_id = b.option(std.zig.BuildId, "hex_build_id", "hex_build_id") orelse expected_hex_build_id; |
| 36 | |
| 37 | if (@"bool" != expected_bool) return error.TestFailed; |
| 38 | if (int != expected_int) return error.TestFailed; |
| 39 | if (float != expected_float) return error.TestFailed; |
| 40 | if (!std.mem.eql(u8, string, expected_string)) return error.TestFailed; |
| 41 | if (string_list.len != expected_string_list.len) return error.TestFailed; |
| 42 | for (string_list, expected_string_list) |x, y| { |
| 43 | if (!std.mem.eql(u8, x, y)) return error.TestFailed; |
| 44 | } |
| 45 | if (!std.mem.eql(u8, lazy_path.cwd_relative, expected_lazy_path.cwd_relative)) return error.TestFailed; |
| 46 | for (lazy_path_list, expected_lazy_path_list) |x, y| { |
| 47 | if (!std.mem.eql(u8, x.cwd_relative, y.cwd_relative)) return error.TestFailed; |
| 48 | } |
| 49 | if (@"enum" != expected_enum) return error.TestFailed; |
| 50 | if (!std.mem.eql(Enum, enum_list, expected_enum_list)) return error.TestFailed; |
| 51 | if (!std.meta.eql(build_id, expected_build_id)) return error.TestFailed; |
| 52 | if (!hex_build_id.eql(expected_hex_build_id)) return error.TestFailed; |
| 53 | |
| 54 | _ = b.addModule("dummy", .{ |
| 55 | .root_source_file = b.path("build.zig"), |
| 56 | .target = target, |
| 57 | .optimize = optimize, |
| 58 | }); |
| 59 | } |