Add debuggable test builds and version check

This commit is contained in:
Martin Wickham 2021-12-07 12:52:40 -06:00
parent 68670b5944
commit 69a2266f4b
4 changed files with 655 additions and 19 deletions

324
.vscode/launch.json vendored
View file

@ -304,5 +304,329 @@
"console": "integratedTerminal",
"preLaunchTask": "build day 25",
},
{
"name": "all tests",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/test_all.exe",
"args": ["std.testing.zig_exe_path is unavailable"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "build tests",
},
{
"name": "tests: util.zig",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/test_util.exe",
"args": ["std.testing.zig_exe_path is unavailable"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "build tests util",
},
{
"name": "tests: day 01",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/test_day01.exe",
"args": ["std.testing.zig_exe_path is unavailable"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "build tests day01",
},
{
"name": "tests: day 02",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/test_day02.exe",
"args": ["std.testing.zig_exe_path is unavailable"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "build tests day02",
},
{
"name": "tests: day 03",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/test_day03.exe",
"args": ["std.testing.zig_exe_path is unavailable"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "build tests day03",
},
{
"name": "tests: day 04",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/test_day04.exe",
"args": ["std.testing.zig_exe_path is unavailable"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "build tests day04",
},
{
"name": "tests: day 05",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/test_day05.exe",
"args": ["std.testing.zig_exe_path is unavailable"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "build tests day05",
},
{
"name": "tests: day 06",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/test_day06.exe",
"args": ["std.testing.zig_exe_path is unavailable"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "build tests day06",
},
{
"name": "tests: day 07",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/test_day07.exe",
"args": ["std.testing.zig_exe_path is unavailable"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "build tests day07",
},
{
"name": "tests: day 08",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/test_day08.exe",
"args": ["std.testing.zig_exe_path is unavailable"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "build tests day08",
},
{
"name": "tests: day 09",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/test_day09.exe",
"args": ["std.testing.zig_exe_path is unavailable"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "build tests day09",
},
{
"name": "tests: day 10",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/test_day10.exe",
"args": ["std.testing.zig_exe_path is unavailable"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "build tests day10",
},
{
"name": "tests: day 11",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/test_day11.exe",
"args": ["std.testing.zig_exe_path is unavailable"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "build tests day11",
},
{
"name": "tests: day 12",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/test_day12.exe",
"args": ["std.testing.zig_exe_path is unavailable"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "build tests day12",
},
{
"name": "tests: day 13",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/test_day13.exe",
"args": ["std.testing.zig_exe_path is unavailable"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "build tests day13",
},
{
"name": "tests: day 14",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/test_day14.exe",
"args": ["std.testing.zig_exe_path is unavailable"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "build tests day14",
},
{
"name": "tests: day 15",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/test_day15.exe",
"args": ["std.testing.zig_exe_path is unavailable"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "build tests day15",
},
{
"name": "tests: day 16",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/test_day16.exe",
"args": ["std.testing.zig_exe_path is unavailable"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "build tests day16",
},
{
"name": "tests: day 17",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/test_day17.exe",
"args": ["std.testing.zig_exe_path is unavailable"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "build tests day17",
},
{
"name": "tests: day 18",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/test_day18.exe",
"args": ["std.testing.zig_exe_path is unavailable"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "build tests day18",
},
{
"name": "tests: day 19",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/test_day19.exe",
"args": ["std.testing.zig_exe_path is unavailable"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "build tests day19",
},
{
"name": "tests: day 20",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/test_day20.exe",
"args": ["std.testing.zig_exe_path is unavailable"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "build tests day20",
},
{
"name": "tests: day 21",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/test_day21.exe",
"args": ["std.testing.zig_exe_path is unavailable"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "build tests day21",
},
{
"name": "tests: day 22",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/test_day22.exe",
"args": ["std.testing.zig_exe_path is unavailable"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "build tests day22",
},
{
"name": "tests: day 23",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/test_day23.exe",
"args": ["std.testing.zig_exe_path is unavailable"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "build tests day23",
},
{
"name": "tests: day 24",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/test_day24.exe",
"args": ["std.testing.zig_exe_path is unavailable"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "build tests day24",
},
{
"name": "tests: day 25",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/test_day25.exe",
"args": ["std.testing.zig_exe_path is unavailable"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal",
"preLaunchTask": "build tests day25",
},
]
}

225
.vscode/tasks.json vendored
View file

@ -204,15 +204,228 @@
"group": "build",
},
{
"label": "test",
"label": "build tests",
"type": "shell",
"command": "zig",
"args": ["build", "test"],
"args": ["build", "install_tests"],
"problemMatcher": [],
"group": {
"kind": "test",
"isDefault": true
}
"group": "build",
},
{
"label": "build tests util",
"type": "shell",
"command": "zig",
"args": ["build", "install_tests_util"],
"problemMatcher": [],
"group": "build",
},
{
"label": "build tests day01",
"type": "shell",
"command": "zig",
"args": ["build", "install_tests_day01"],
"problemMatcher": [],
"group": "build",
},
{
"label": "build tests day02",
"type": "shell",
"command": "zig",
"args": ["build", "install_tests_day02"],
"problemMatcher": [],
"group": "build",
},
{
"label": "build tests day03",
"type": "shell",
"command": "zig",
"args": ["build", "install_tests_day03"],
"problemMatcher": [],
"group": "build",
},
{
"label": "build tests day04",
"type": "shell",
"command": "zig",
"args": ["build", "install_tests_day04"],
"problemMatcher": [],
"group": "build",
},
{
"label": "build tests day05",
"type": "shell",
"command": "zig",
"args": ["build", "install_tests_day05"],
"problemMatcher": [],
"group": "build",
},
{
"label": "build tests day06",
"type": "shell",
"command": "zig",
"args": ["build", "install_tests_day06"],
"problemMatcher": [],
"group": "build",
},
{
"label": "build tests day06",
"type": "shell",
"command": "zig",
"args": ["build", "install_tests_day06"],
"problemMatcher": [],
"group": "build",
},
{
"label": "build tests day07",
"type": "shell",
"command": "zig",
"args": ["build", "install_tests_day07"],
"problemMatcher": [],
"group": "build",
},
{
"label": "build tests day08",
"type": "shell",
"command": "zig",
"args": ["build", "install_tests_day08"],
"problemMatcher": [],
"group": "build",
},
{
"label": "build tests day09",
"type": "shell",
"command": "zig",
"args": ["build", "install_tests_day09"],
"problemMatcher": [],
"group": "build",
},
{
"label": "build tests day10",
"type": "shell",
"command": "zig",
"args": ["build", "install_tests_day10"],
"problemMatcher": [],
"group": "build",
},
{
"label": "build tests day11",
"type": "shell",
"command": "zig",
"args": ["build", "install_tests_day11"],
"problemMatcher": [],
"group": "build",
},
{
"label": "build tests day12",
"type": "shell",
"command": "zig",
"args": ["build", "install_tests_day12"],
"problemMatcher": [],
"group": "build",
},
{
"label": "build tests day13",
"type": "shell",
"command": "zig",
"args": ["build", "install_tests_day13"],
"problemMatcher": [],
"group": "build",
},
{
"label": "build tests day14",
"type": "shell",
"command": "zig",
"args": ["build", "install_tests_day14"],
"problemMatcher": [],
"group": "build",
},
{
"label": "build tests day15",
"type": "shell",
"command": "zig",
"args": ["build", "install_tests_day15"],
"problemMatcher": [],
"group": "build",
},
{
"label": "build tests day16",
"type": "shell",
"command": "zig",
"args": ["build", "install_tests_day16"],
"problemMatcher": [],
"group": "build",
},
{
"label": "build tests day17",
"type": "shell",
"command": "zig",
"args": ["build", "install_tests_day17"],
"problemMatcher": [],
"group": "build",
},
{
"label": "build tests day18",
"type": "shell",
"command": "zig",
"args": ["build", "install_tests_day18"],
"problemMatcher": [],
"group": "build",
},
{
"label": "build tests day19",
"type": "shell",
"command": "zig",
"args": ["build", "install_tests_day19"],
"problemMatcher": [],
"group": "build",
},
{
"label": "build tests day20",
"type": "shell",
"command": "zig",
"args": ["build", "install_tests_day20"],
"problemMatcher": [],
"group": "build",
},
{
"label": "build tests day21",
"type": "shell",
"command": "zig",
"args": ["build", "install_tests_day21"],
"problemMatcher": [],
"group": "build",
},
{
"label": "build tests day22",
"type": "shell",
"command": "zig",
"args": ["build", "install_tests_day22"],
"problemMatcher": [],
"group": "build",
},
{
"label": "build tests day23",
"type": "shell",
"command": "zig",
"args": ["build", "install_tests_day23"],
"problemMatcher": [],
"group": "build",
},
{
"label": "build tests day24",
"type": "shell",
"command": "zig",
"args": ["build", "install_tests_day24"],
"problemMatcher": [],
"group": "build",
},
{
"label": "build tests day25",
"type": "shell",
"command": "zig",
"args": ["build", "install_tests_day25"],
"problemMatcher": [],
"group": "build",
},
{
"label": "format",

View file

@ -5,10 +5,6 @@ const LibExeObjStep = std.build.LibExeObjStep;
// set this to true to link libc
const should_link_libc = false;
const test_files = [_][]const u8{
// list any zig files with tests here
};
fn linkObject(b: *Builder, obj: *LibExeObjStep) void {
if (should_link_libc) obj.linkLibC();
_ = b;
@ -16,7 +12,21 @@ fn linkObject(b: *Builder, obj: *LibExeObjStep) void {
// Add linking for packages or third party libraries here
}
const required_zig_version = std.SemanticVersion.parse("0.9.0-dev.1920+de81c504b") catch unreachable;
pub fn build(b: *Builder) void {
if (comptime @import("builtin").zig_version.order(required_zig_version) == .lt) {
std.debug.print(
\\Error: Your version of Zig is missing features that are needed for this template.
\\You will need to download a newer build.
\\
\\ https://ziglang.org/download/
\\
\\
, .{});
std.os.exit(1);
}
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
@ -28,6 +38,7 @@ pub fn build(b: *Builder) void {
const mode = b.standardReleaseOptions();
const install_all = b.step("install_all", "Install all days");
const install_all_tests = b.step("install_tests_all", "Install tests for all days");
const run_all = b.step("run_all", "Run all days");
// Set up an exe for each day
@ -45,11 +56,39 @@ pub fn build(b: *Builder) void {
const install_cmd = b.addInstallArtifact(exe);
const run_test = b.addTest(zigFile);
run_test.setTarget(target);
run_test.setBuildMode(mode);
linkObject(b, exe);
const build_test = b.addTestExe(b.fmt("test_{s}", .{dayString}), zigFile);
build_test.setTarget(target);
build_test.setBuildMode(mode);
linkObject(b, exe);
const install_test = b.addInstallArtifact(build_test);
{
const step_key = b.fmt("install_{s}", .{dayString});
const step_desc = b.fmt("Install {s}.exe", .{dayString});
const install_step = b.step(step_key, step_desc);
install_step.dependOn(&install_cmd.step);
install_all.dependOn(&install_cmd.step);
}
{
const step_key = b.fmt("test_{s}", .{dayString});
const step_desc = b.fmt("Run tests in {s}", .{zigFile});
const step = b.step(step_key, step_desc);
step.dependOn(&run_test.step);
}
{
const step_key = b.fmt("install_tests_{s}", .{dayString});
const step_desc = b.fmt("Install test_{s}.exe", .{dayString});
const step = b.step(step_key, step_desc);
step.dependOn(&install_test.step);
install_all_tests.dependOn(&install_test.step);
}
const run_cmd = exe.run();
run_cmd.step.dependOn(&install_cmd.step);
@ -63,14 +102,45 @@ pub fn build(b: *Builder) void {
run_all.dependOn(&run_cmd.step);
}
// Set up a step to run all tests
const test_step = b.step("test", "Run all tests");
for (test_files) |file| {
const test_cmd = b.addTest(file);
// Set up tests for util.zig
{
const test_util = b.step("test_util", "Run tests in util.zig");
const test_cmd = b.addTest("src/util.zig");
test_cmd.setTarget(target);
test_cmd.setBuildMode(mode);
linkObject(b, test_cmd);
test_util.dependOn(&test_cmd.step);
}
// Set up test executable for util.zig
{
const test_util = b.step("install_tests_util", "Run tests in util.zig");
const test_exe = b.addTestExe("test_util", "src/util.zig");
test_exe.setTarget(target);
test_exe.setBuildMode(mode);
linkObject(b, test_exe);
const install = b.addInstallArtifact(test_exe);
test_util.dependOn(&install.step);
}
// Set up a step to run all tests
{
const test_step = b.step("test", "Run all tests");
const test_cmd = b.addTest("src/test_all.zig");
test_cmd.setTarget(target);
test_cmd.setBuildMode(mode);
linkObject(b, test_cmd);
test_step.dependOn(&test_cmd.step);
}
// Set up a step to build tests (but not run them)
{
const test_build = b.step("install_tests", "Install test_all.exe");
const test_exe = b.addTestExe("test_all", "src/test_all.zig");
test_exe.setTarget(target);
test_exe.setBuildMode(mode);
linkObject(b, test_exe);
const test_exe_install = b.addInstallArtifact(test_exe);
test_build.dependOn(&test_exe_install.step);
}
}

29
src/test_all.zig Normal file
View file

@ -0,0 +1,29 @@
test {
_ = @import("util.zig");
_ = @import("day01.zig");
_ = @import("day02.zig");
_ = @import("day03.zig");
_ = @import("day04.zig");
_ = @import("day05.zig");
_ = @import("day06.zig");
_ = @import("day07.zig");
_ = @import("day08.zig");
_ = @import("day09.zig");
_ = @import("day10.zig");
_ = @import("day11.zig");
_ = @import("day12.zig");
_ = @import("day13.zig");
_ = @import("day14.zig");
_ = @import("day15.zig");
_ = @import("day16.zig");
_ = @import("day17.zig");
_ = @import("day18.zig");
_ = @import("day19.zig");
_ = @import("day20.zig");
_ = @import("day21.zig");
_ = @import("day22.zig");
_ = @import("day23.zig");
_ = @import("day24.zig");
_ = @import("day25.zig");
// Import any other files with tests here
}