mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
Extend standalone tests for cmakedefine
This commit is contained in:
parent
8a0429e885
commit
2ce32e4497
12 changed files with 158 additions and 13 deletions
|
|
@ -4,7 +4,8 @@ const ConfigHeader = std.Build.Step.ConfigHeader;
|
|||
pub fn build(b: *std.Build) void {
|
||||
const config_header = b.addConfigHeader(
|
||||
.{
|
||||
.style = .{ .cmake = .{ .path = "config.h.cmake" } },
|
||||
.style = .{ .cmake = .{ .path = "config.h.in" } },
|
||||
.include_path = "config.h",
|
||||
},
|
||||
.{
|
||||
.noval = null,
|
||||
|
|
@ -25,23 +26,75 @@ pub fn build(b: *std.Build) void {
|
|||
},
|
||||
);
|
||||
|
||||
const pwd_sh = b.addConfigHeader(
|
||||
.{
|
||||
.style = .{ .cmake = .{ .path = "pwd.sh.in" } },
|
||||
.include_path = "pwd.sh",
|
||||
},
|
||||
.{ .DIR = "${PWD}" },
|
||||
);
|
||||
|
||||
const sigil_header = b.addConfigHeader(
|
||||
.{
|
||||
.style = .{ .cmake = .{ .path = "sigil.h.in" } },
|
||||
.include_path = "sigil.h",
|
||||
},
|
||||
.{},
|
||||
);
|
||||
|
||||
const stack_header = b.addConfigHeader(
|
||||
.{
|
||||
.style = .{ .cmake = .{ .path = "stack.h.in" } },
|
||||
.include_path = "stack.h",
|
||||
},
|
||||
.{
|
||||
.AT = "@",
|
||||
.UNDERSCORE = "_",
|
||||
.NEST_UNDERSCORE_PROXY = "UNDERSCORE",
|
||||
.NEST_PROXY = "NEST_UNDERSCORE_PROXY",
|
||||
},
|
||||
);
|
||||
|
||||
const wrapper_header = b.addConfigHeader(
|
||||
.{
|
||||
.style = .{ .cmake = .{ .path = "wrapper.h.in" } },
|
||||
.include_path = "wrapper.h",
|
||||
},
|
||||
.{
|
||||
.DOLLAR = "$",
|
||||
.TEXT = "TRAP",
|
||||
|
||||
.STRING = "TEXT",
|
||||
.STRING_AT = "@STRING@",
|
||||
.STRING_CURLY = "{STRING}",
|
||||
.STRING_VAR = "${STRING}",
|
||||
},
|
||||
);
|
||||
|
||||
const test_step = b.step("test", "Test it");
|
||||
test_step.makeFn = compare_headers;
|
||||
test_step.dependOn(&config_header.step);
|
||||
test_step.dependOn(&pwd_sh.step);
|
||||
test_step.dependOn(&sigil_header.step);
|
||||
test_step.dependOn(&stack_header.step);
|
||||
test_step.dependOn(&wrapper_header.step);
|
||||
}
|
||||
|
||||
fn compare_headers(step: *std.Build.Step, prog_node: *std.Progress.Node) !void {
|
||||
_ = prog_node;
|
||||
const allocator = step.owner.allocator;
|
||||
const cmake_header_path = "expected.h";
|
||||
const expected_fmt = "expected_{s}";
|
||||
|
||||
const config_header_step = step.dependencies.getLast();
|
||||
for (step.dependencies.items) |config_header_step| {
|
||||
const config_header = @fieldParentPtr(ConfigHeader, "step", config_header_step);
|
||||
|
||||
const zig_header_path = config_header.output_file.path orelse @panic("Could not locate header file");
|
||||
|
||||
const cwd = std.fs.cwd();
|
||||
|
||||
const cmake_header_path = try std.fmt.allocPrint(allocator, expected_fmt, .{std.fs.path.basename(zig_header_path)});
|
||||
defer allocator.free(cmake_header_path);
|
||||
|
||||
const cmake_header = try cwd.readFileAlloc(allocator, cmake_header_path, config_header.max_bytes);
|
||||
defer allocator.free(cmake_header);
|
||||
|
||||
|
|
@ -53,4 +106,5 @@ fn compare_headers(step: *std.Build.Step, prog_node: *std.Progress.Node) !void {
|
|||
if (!std.mem.eql(u8, zig_header[header_text_index + 1 ..], cmake_header)) {
|
||||
@panic("processed cmakedefine header does not match expected output");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
5
test/standalone/cmakedefine/expected_error.h
Normal file
5
test/standalone/cmakedefine/expected_error.h
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
// bad interleave
|
||||
#define @STRV${AL_AT@TEXT}
|
||||
|
||||
// bad interleave
|
||||
#define ${STRV@AL_AT}TEXT@
|
||||
1
test/standalone/cmakedefine/expected_pwd.sh
Normal file
1
test/standalone/cmakedefine/expected_pwd.sh
Normal file
|
|
@ -0,0 +1 @@
|
|||
echo ${PWD}
|
||||
5
test/standalone/cmakedefine/expected_sigil.h
Normal file
5
test/standalone/cmakedefine/expected_sigil.h
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#define VAR
|
||||
#define AT @
|
||||
#define ATAT @@
|
||||
#define ATATAT @@@
|
||||
#define ATATATAT @@@@
|
||||
7
test/standalone/cmakedefine/expected_stack.h
Normal file
7
test/standalone/cmakedefine/expected_stack.h
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#define NEST_UNDERSCORE_PROXY NEST_UNDERSCORE_PROXY
|
||||
#define UNDERSCORE UNDERSCORE
|
||||
|
||||
#define NEST_UNDERSCORE_PROXY NEST_UNDERSCORE_PROXY
|
||||
#define UNDERSCORE UNDERSCORE
|
||||
|
||||
#define (empty)
|
||||
30
test/standalone/cmakedefine/expected_wrapper.h
Normal file
30
test/standalone/cmakedefine/expected_wrapper.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// becomes TEXT
|
||||
#define TEXT
|
||||
#define TEXT
|
||||
|
||||
// becomes `at`TEXT`at`
|
||||
#define @TEXT@
|
||||
#define @TEXT@
|
||||
|
||||
// becomes TRAP
|
||||
#define TRAP
|
||||
|
||||
// becomes `dollar sign`{STRING}
|
||||
#define ${STRING}
|
||||
#define ${STRING}
|
||||
|
||||
// becomes `dollar sign`{STRING}
|
||||
#define ${STRING}
|
||||
#define ${STRING}
|
||||
|
||||
// becomes `dollar sign`{TEXT}
|
||||
#define ${TEXT}
|
||||
#define ${TEXT}
|
||||
|
||||
// becomes `at`STRING`at`
|
||||
#define @STRING@
|
||||
#define @STRING@
|
||||
|
||||
// becomes `empty`
|
||||
#define
|
||||
#define
|
||||
1
test/standalone/cmakedefine/pwd.sh.in
Normal file
1
test/standalone/cmakedefine/pwd.sh.in
Normal file
|
|
@ -0,0 +1 @@
|
|||
echo @DIR@
|
||||
5
test/standalone/cmakedefine/sigil.h.in
Normal file
5
test/standalone/cmakedefine/sigil.h.in
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#define VAR ${}
|
||||
#define AT @
|
||||
#define ATAT @@
|
||||
#define ATATAT @@@
|
||||
#define ATATATAT @@@@
|
||||
7
test/standalone/cmakedefine/stack.h.in
Normal file
7
test/standalone/cmakedefine/stack.h.in
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#define NEST_UNDERSCORE_PROXY ${NEST${UNDERSCORE}PROXY}
|
||||
#define UNDERSCORE @NEST@UNDERSCORE@PROXY@
|
||||
|
||||
#define NEST_UNDERSCORE_PROXY ${NEST${${NEST_UNDERSCORE${UNDERSCORE}PROXY}}PROXY}
|
||||
#define UNDERSCORE @NEST@@NEST_UNDERSCORE@UNDERSCORE@PROXY@@PROXY@
|
||||
|
||||
#define (empty) ${NEST${${AT}UNDERSCORE${AT}}PROXY}
|
||||
30
test/standalone/cmakedefine/wrapper.h.in
Normal file
30
test/standalone/cmakedefine/wrapper.h.in
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// becomes TEXT
|
||||
#define @STRING@
|
||||
#define ${STRING}
|
||||
|
||||
// becomes `at`TEXT`at`
|
||||
#define @${STRING}@
|
||||
#define @@STRING@@
|
||||
|
||||
// becomes TRAP
|
||||
#define ${@STRING@}
|
||||
|
||||
// becomes `dollar sign`{STRING}
|
||||
#define $@STRING_CURLY@
|
||||
#define $${STRING_CURLY}
|
||||
|
||||
// becomes `dollar sign`{STRING}
|
||||
#define @STRING_VAR@
|
||||
#define ${STRING_VAR}
|
||||
|
||||
// becomes `dollar sign`{TEXT}
|
||||
#define ${DOLLAR}{${STRING}}
|
||||
#define @DOLLAR@{${STRING}}
|
||||
|
||||
// becomes `at`STRING`at`
|
||||
#define ${STRING_AT}
|
||||
#define @STRING_AT@
|
||||
|
||||
// becomes `empty`
|
||||
#define ${${STRING_VAR}}
|
||||
#define ${@STRING_VAR@}
|
||||
Loading…
Add table
Reference in a new issue