diff options
| author | Evan Haas <evan@lagerdata.com> | 2022-05-06 10:14:31 -0700 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-05-09 18:42:42 +0300 |
| commit | 94b9bcd034960f0467ca789217064b17f2ca7a49 (patch) | |
| tree | fb9bc675814214ad303f41bce4c8b3ca75f2c3c8 /test | |
| parent | d7f8368da86241f47e97257e737b6fb14bf5f773 (diff) | |
| download | zig-94b9bcd034960f0467ca789217064b17f2ca7a49.tar.gz zig-94b9bcd034960f0467ca789217064b17f2ca7a49.zip | |
stdlib: escape backslashes and double quotes in Builder response file
Fixes #11595
Diffstat (limited to 'test')
| -rw-r--r-- | test/standalone.zig | 1 | ||||
| -rw-r--r-- | test/standalone/issue_11595/build.zig | 52 | ||||
| -rw-r--r-- | test/standalone/issue_11595/main.zig | 5 | ||||
| -rw-r--r-- | test/standalone/issue_11595/test.c | 10 |
4 files changed, 68 insertions, 0 deletions
diff --git a/test/standalone.zig b/test/standalone.zig index 6df3387018..856a58df84 100644 --- a/test/standalone.zig +++ b/test/standalone.zig @@ -49,6 +49,7 @@ pub fn addCases(cases: *tests.StandaloneContext) void { cases.addBuildFile("test/standalone/issue_7030/build.zig", .{}); cases.addBuildFile("test/standalone/install_raw_hex/build.zig", .{}); cases.addBuildFile("test/standalone/issue_9812/build.zig", .{}); + cases.addBuildFile("test/standalone/issue_11595/build.zig", .{}); if (builtin.os.tag != .wasi) { cases.addBuildFile("test/standalone/load_dynamic_library/build.zig", .{}); } diff --git a/test/standalone/issue_11595/build.zig b/test/standalone/issue_11595/build.zig new file mode 100644 index 0000000000..d636f63ebc --- /dev/null +++ b/test/standalone/issue_11595/build.zig @@ -0,0 +1,52 @@ +const std = @import("std"); +const builtin = @import("builtin"); +const Builder = std.build.Builder; +const CrossTarget = std.zig.CrossTarget; + +// TODO integrate this with the std.build executor API +fn isRunnableTarget(t: CrossTarget) bool { + if (t.isNative()) return true; + + return (t.getOsTag() == builtin.os.tag and + t.getCpuArch() == builtin.cpu.arch); +} + +pub fn build(b: *Builder) void { + const mode = b.standardReleaseOptions(); + const target = b.standardTargetOptions(.{}); + + const exe = b.addExecutable("zigtest", "main.zig"); + exe.setBuildMode(mode); + exe.install(); + + const c_sources = [_][]const u8{ + "test.c", + }; + + exe.addCSourceFiles(&c_sources, &.{}); + exe.linkLibC(); + + var i: i32 = 0; + while (i < 1000) : (i += 1) { + exe.defineCMacro("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); + } + + exe.defineCMacro("FOO", "42"); + exe.defineCMacro("BAR", "\"BAR\""); + exe.defineCMacro("BAZ", + \\"\"BAZ\"" + ); + exe.defineCMacro("QUX", "\"Q\" \"UX\""); + exe.defineCMacro("QUUX", "\"QU\\\"UX\""); + + exe.setTarget(target); + b.default_step.dependOn(&exe.step); + + const test_step = b.step("test", "Test the program"); + if (isRunnableTarget(target)) { + const run_cmd = exe.run(); + test_step.dependOn(&run_cmd.step); + } else { + test_step.dependOn(&exe.step); + } +} diff --git a/test/standalone/issue_11595/main.zig b/test/standalone/issue_11595/main.zig new file mode 100644 index 0000000000..b91f54cb9c --- /dev/null +++ b/test/standalone/issue_11595/main.zig @@ -0,0 +1,5 @@ +extern fn check() c_int; + +pub fn main() u8 { + return @intCast(u8, check()); +} diff --git a/test/standalone/issue_11595/test.c b/test/standalone/issue_11595/test.c new file mode 100644 index 0000000000..5bfaa1a351 --- /dev/null +++ b/test/standalone/issue_11595/test.c @@ -0,0 +1,10 @@ + #include <string.h> + +int check(void) { + if (FOO != 42) return 1; + if (strcmp(BAR, "BAR")) return 2; + if (strcmp(BAZ, "\"BAZ\"")) return 3; + if (strcmp(QUX, "QUX")) return 4; + if (strcmp(QUUX, "QU\"UX")) return 5; + return 0; +} |
