authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-12-16 15:09:34+00:00
committergravatar for bratishkaerik@landless-city.netEric Joldasov <bratishkaerik@landless-city.net> 2024-12-18 01:48:57+05:00
logb8472db215a892754b7e834ce44b2d7f254ff60d
tree5fd63dde164b4db6f91f97d94f3e10f60435de4d
parent93af1de0502d8041debf96e3579af04c8f7f8e38
signaturelock-open Commit is signed but in an unrecognized format.

tests.zig: migrate from deprecated std.Build APIs


1 files changed, 51 insertions(+), 36 deletions(-)

test/tests.zig+51-36
...@@ -1106,9 +1106,11 @@ pub fn addStackTraceTests(...@@ -1106,9 +1106,11 @@ pub fn addStackTraceTests(
1106) *Step {1106) *Step {
1107 const check_exe = b.addExecutable(.{1107 const check_exe = b.addExecutable(.{
1108 .name = "check-stack-trace",1108 .name = "check-stack-trace",
1109 .root_source_file = b.path("test/src/check-stack-trace.zig"),1109 .root_module = b.createModule(.{
1110 .target = b.graph.host,1110 .root_source_file = b.path("test/src/check-stack-trace.zig"),
1111 .optimize = .Debug,1111 .target = b.graph.host,
1112 .optimize = .Debug,
1113 }),
1112 });1114 });
11131115
1114 const cases = b.allocator.create(StackTracesContext) catch @panic("OOM");1116 const cases = b.allocator.create(StackTracesContext) catch @panic("OOM");
...@@ -1330,7 +1332,7 @@ pub fn addCliTests(b: *std.Build) *Step {...@@ -1330,7 +1332,7 @@ pub fn addCliTests(b: *std.Build) *Step {
1330 run5.step.dependOn(&run4.step);1332 run5.step.dependOn(&run4.step);
13311333
1332 const unformatted_code_utf16 = "\xff\xfe \x00 \x00 \x00 \x00/\x00/\x00 \x00n\x00o\x00 \x00r\x00e\x00a\x00s\x00o\x00n\x00";1334 const unformatted_code_utf16 = "\xff\xfe \x00 \x00 \x00 \x00/\x00/\x00 \x00n\x00o\x00 \x00r\x00e\x00a\x00s\x00o\x00n\x00";
1333 const fmt6_path = std.fs.path.join(b.allocator, &.{ tmp_path, "fmt6.zig" }) catch @panic("OOM");1335 const fmt6_path = b.pathJoin(&.{ tmp_path, "fmt6.zig" });
1334 const write6 = b.addUpdateSourceFiles();1336 const write6 = b.addUpdateSourceFiles();
1335 write6.addBytesToSource(unformatted_code_utf16, fmt6_path);1337 write6.addBytesToSource(unformatted_code_utf16, fmt6_path);
1336 write6.step.dependOn(&run5.step);1338 write6.step.dependOn(&run5.step);
...@@ -1514,18 +1516,20 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {...@@ -1514,18 +1516,20 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
1514 options.max_rss;1516 options.max_rss;
15151517
1516 const these_tests = b.addTest(.{1518 const these_tests = b.addTest(.{
1517 .root_source_file = b.path(options.root_src),1519 .root_module = b.createModule(.{
1518 .optimize = test_target.optimize_mode,1520 .root_source_file = b.path(options.root_src),
1519 .target = resolved_target,1521 .optimize = test_target.optimize_mode,
1522 .target = resolved_target,
1523 .link_libc = test_target.link_libc,
1524 .pic = test_target.pic,
1525 .strip = test_target.strip,
1526 .single_threaded = test_target.single_threaded,
1527 }),
1520 .max_rss = max_rss,1528 .max_rss = max_rss,
1521 .filters = options.test_filters,1529 .filters = options.test_filters,
1522 .link_libc = test_target.link_libc,
1523 .single_threaded = test_target.single_threaded,
1524 .use_llvm = test_target.use_llvm,1530 .use_llvm = test_target.use_llvm,
1525 .use_lld = test_target.use_lld,1531 .use_lld = test_target.use_lld,
1526 .zig_lib_dir = b.path("lib"),1532 .zig_lib_dir = b.path("lib"),
1527 .pic = test_target.pic,
1528 .strip = test_target.strip,
1529 });1533 });
1530 if (options.no_builtin) these_tests.no_builtin = true;1534 if (options.no_builtin) these_tests.no_builtin = true;
1531 if (options.build_options) |build_options| {1535 if (options.build_options) |build_options| {
...@@ -1561,12 +1565,17 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {...@@ -1561,12 +1565,17 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
1561 var altered_query = test_target.target;1565 var altered_query = test_target.target;
1562 altered_query.ofmt = null;1566 altered_query.ofmt = null;
15631567
1564 const compile_c = b.addExecutable(.{1568 const compile_c = b.createModule(.{
1565 .name = qualified_name,1569 .root_source_file = null,
1566 .link_libc = test_target.link_libc,1570 .link_libc = test_target.link_libc,
1567 .target = b.resolveTargetQuery(altered_query),1571 .target = b.resolveTargetQuery(altered_query),
1572 });
1573 const compile_c_exe = b.addExecutable(.{
1574 .name = qualified_name,
1575 .root_module = compile_c,
1568 .zig_lib_dir = b.path("lib"),1576 .zig_lib_dir = b.path("lib"),
1569 });1577 });
1578
1570 compile_c.addCSourceFile(.{1579 compile_c.addCSourceFile(.{
1571 .file = these_tests.getEmittedBin(),1580 .file = these_tests.getEmittedBin(),
1572 .flags = &.{1581 .flags = &.{
...@@ -1611,22 +1620,22 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {...@@ -1611,22 +1620,22 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
1611 continue;1620 continue;
1612 }1621 }
1613 if (test_target.link_libc == false) {1622 if (test_target.link_libc == false) {
1614 compile_c.subsystem = .Console;1623 compile_c_exe.subsystem = .Console;
1615 compile_c.linkSystemLibrary("kernel32");1624 compile_c.linkSystemLibrary("kernel32", .{});
1616 compile_c.linkSystemLibrary("ntdll");1625 compile_c.linkSystemLibrary("ntdll", .{});
1617 }1626 }
1618 if (mem.eql(u8, options.name, "std")) {1627 if (mem.eql(u8, options.name, "std")) {
1619 if (test_target.link_libc == false) {1628 if (test_target.link_libc == false) {
1620 compile_c.linkSystemLibrary("shell32");1629 compile_c.linkSystemLibrary("shell32", .{});
1621 compile_c.linkSystemLibrary("advapi32");1630 compile_c.linkSystemLibrary("advapi32", .{});
1622 }1631 }
1623 compile_c.linkSystemLibrary("crypt32");1632 compile_c.linkSystemLibrary("crypt32", .{});
1624 compile_c.linkSystemLibrary("ws2_32");1633 compile_c.linkSystemLibrary("ws2_32", .{});
1625 compile_c.linkSystemLibrary("ole32");1634 compile_c.linkSystemLibrary("ole32", .{});
1626 }1635 }
1627 }1636 }
16281637
1629 const run = b.addRunArtifact(compile_c);1638 const run = b.addRunArtifact(compile_c_exe);
1630 run.skip_foreign_checks = true;1639 run.skip_foreign_checks = true;
1631 run.enableTestRunnerMode();1640 run.enableTestRunnerMode();
1632 run.setName(b.fmt("run test {s}", .{qualified_name}));1641 run.setName(b.fmt("run test {s}", .{qualified_name}));
...@@ -1675,6 +1684,20 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step {...@@ -1675,6 +1684,20 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step {
1675 continue;1684 continue;
1676 }1685 }
16771686
1687 const test_mod = b.createModule(.{
1688 .root_source_file = b.path("test/c_abi/main.zig"),
1689 .target = resolved_target,
1690 .optimize = optimize_mode,
1691 .link_libc = true,
1692 .pic = c_abi_target.pic,
1693 .strip = c_abi_target.strip,
1694 });
1695 test_mod.addCSourceFile(.{
1696 .file = b.path("test/c_abi/cfuncs.c"),
1697 .flags = &.{"-std=c99"},
1698 });
1699 for (c_abi_target.c_defines) |define| test_mod.addCMacro(define, "1");
1700
1678 const test_step = b.addTest(.{1701 const test_step = b.addTest(.{
1679 .name = b.fmt("test-c-abi-{s}-{s}-{s}{s}{s}{s}", .{1702 .name = b.fmt("test-c-abi-{s}-{s}-{s}{s}{s}{s}", .{
1680 triple_txt,1703 triple_txt,
...@@ -1691,20 +1714,10 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step {...@@ -1691,20 +1714,10 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step {
1691 if (c_abi_target.use_lld == false) "-no-lld" else "",1714 if (c_abi_target.use_lld == false) "-no-lld" else "",
1692 if (c_abi_target.pic == true) "-pic" else "",1715 if (c_abi_target.pic == true) "-pic" else "",
1693 }),1716 }),
1694 .root_source_file = b.path("test/c_abi/main.zig"),1717 .root_module = test_mod,
1695 .target = resolved_target,
1696 .optimize = optimize_mode,
1697 .link_libc = true,
1698 .use_llvm = c_abi_target.use_llvm,1718 .use_llvm = c_abi_target.use_llvm,
1699 .use_lld = c_abi_target.use_lld,1719 .use_lld = c_abi_target.use_lld,
1700 .pic = c_abi_target.pic,
1701 .strip = c_abi_target.strip,
1702 });1720 });
1703 test_step.addCSourceFile(.{
1704 .file = b.path("test/c_abi/cfuncs.c"),
1705 .flags = &.{"-std=c99"},
1706 });
1707 for (c_abi_target.c_defines) |define| test_step.root_module.addCMacro(define, "1");
17081721
1709 // This test is intentionally trying to check if the external ABI is1722 // This test is intentionally trying to check if the external ABI is
1710 // done properly. LTO would be a hindrance to this.1723 // done properly. LTO would be a hindrance to this.
...@@ -1784,9 +1797,11 @@ pub fn addDebuggerTests(b: *std.Build, options: DebuggerContext.Options) ?*Step...@@ -1784,9 +1797,11 @@ pub fn addDebuggerTests(b: *std.Build, options: DebuggerContext.Options) ?*Step
1784pub fn addIncrementalTests(b: *std.Build, test_step: *Step) !void {1797pub fn addIncrementalTests(b: *std.Build, test_step: *Step) !void {
1785 const incr_check = b.addExecutable(.{1798 const incr_check = b.addExecutable(.{
1786 .name = "incr-check",1799 .name = "incr-check",
1787 .root_source_file = b.path("tools/incr-check.zig"),1800 .root_module = b.createModule(.{
1788 .target = b.graph.host,1801 .root_source_file = b.path("tools/incr-check.zig"),
1789 .optimize = .Debug,1802 .target = b.graph.host,
1803 .optimize = .Debug,
1804 }),
1790 });1805 });
17911806
1792 var dir = try b.build_root.handle.openDir("test/incremental", .{ .iterate = true });1807 var dir = try b.build_root.handle.openDir("test/incremental", .{ .iterate = true });