Skip to content

Commit 342235e

Browse files
committed
test/link/elf: enhance merge strings tests
1 parent 4931a29 commit 342235e

File tree

1 file changed

+37
-12
lines changed

1 file changed

+37
-12
lines changed

test/link/elf.zig

+37-12
Original file line numberDiff line numberDiff line change
@@ -2328,7 +2328,7 @@ fn testMergeStrings(b: *Build, opts: Options) *Step {
23282328
fn testMergeStrings2(b: *Build, opts: Options) *Step {
23292329
const test_step = addTestStep(b, "merge-strings2", opts);
23302330

2331-
const obj1 = addObject(b, opts, .{ .name = "a.o", .zig_source_bytes =
2331+
const obj1 = addObject(b, opts, .{ .name = "a", .zig_source_bytes =
23322332
\\const std = @import("std");
23332333
\\export fn foo() void {
23342334
\\ var arr: [5:0]u16 = [_:0]u16{ 1, 2, 3, 4, 5 };
@@ -2337,7 +2337,7 @@ fn testMergeStrings2(b: *Build, opts: Options) *Step {
23372337
\\}
23382338
});
23392339

2340-
const exe = addExecutable(b, opts, .{ .name = "main", .zig_source_bytes =
2340+
const obj2 = addObject(b, opts, .{ .name = "b", .zig_source_bytes =
23412341
\\const std = @import("std");
23422342
\\extern fn foo() void;
23432343
\\pub fn main() void {
@@ -2347,18 +2347,43 @@ fn testMergeStrings2(b: *Build, opts: Options) *Step {
23472347
\\ std.testing.expectEqualSlices(u16, arr[0..2], slice) catch unreachable;
23482348
\\}
23492349
});
2350-
exe.addObject(obj1);
23512350

2352-
const run = addRunArtifact(exe);
2353-
run.expectExitCode(0);
2354-
test_step.dependOn(&run.step);
2351+
{
2352+
const exe = addExecutable(b, opts, .{ .name = "main1" });
2353+
exe.addObject(obj1);
2354+
exe.addObject(obj2);
23552355

2356-
const check = exe.checkObject();
2357-
check.dumpSection(".rodata.str");
2358-
check.checkContains("\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x00\x00");
2359-
check.dumpSection(".rodata.str");
2360-
check.checkContains("\x05\x00\x04\x00\x03\x00\x02\x00\x01\x00\x00\x00");
2361-
test_step.dependOn(&check.step);
2356+
const run = addRunArtifact(exe);
2357+
run.expectExitCode(0);
2358+
test_step.dependOn(&run.step);
2359+
2360+
const check = exe.checkObject();
2361+
check.dumpSection(".rodata.str");
2362+
check.checkContains("\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x00\x00");
2363+
check.dumpSection(".rodata.str");
2364+
check.checkContains("\x05\x00\x04\x00\x03\x00\x02\x00\x01\x00\x00\x00");
2365+
test_step.dependOn(&check.step);
2366+
}
2367+
2368+
{
2369+
const obj3 = addObject(b, opts, .{ .name = "c" });
2370+
obj3.addObject(obj1);
2371+
obj3.addObject(obj2);
2372+
2373+
const exe = addExecutable(b, opts, .{ .name = "main2" });
2374+
exe.addObject(obj3);
2375+
2376+
const run = addRunArtifact(exe);
2377+
run.expectExitCode(0);
2378+
test_step.dependOn(&run.step);
2379+
2380+
const check = exe.checkObject();
2381+
check.dumpSection(".rodata.str");
2382+
check.checkContains("\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x00\x00");
2383+
check.dumpSection(".rodata.str");
2384+
check.checkContains("\x05\x00\x04\x00\x03\x00\x02\x00\x01\x00\x00\x00");
2385+
test_step.dependOn(&check.step);
2386+
}
23622387

23632388
return test_step;
23642389
}

0 commit comments

Comments
 (0)