Add ability to debug test suite in VS Code
continuous-integration/drone/push Build is passing Details

This commit is contained in:
kayomn 2022-10-02 12:56:19 +01:00
parent 11b6040237
commit 3ca0bd5724
5 changed files with 24 additions and 19 deletions

5
.vscode/launch.json vendored
View File

@ -8,16 +8,17 @@
"target": "${workspaceFolder}/zig-out/bin/ona", "target": "${workspaceFolder}/zig-out/bin/ona",
"cwd": "${workspaceRoot}", "cwd": "${workspaceRoot}",
"valuesFormatting": "parseText", "valuesFormatting": "parseText",
"preLaunchTask": "build", "preLaunchTask": "Build",
}, },
{ {
"name": "Test", "name": "Test",
"type": "gdb", "type": "gdb",
"request": "launch", "request": "launch",
"target": "${workspaceFolder}/zig-cache/o/b57ef32c79a05339fbe4a8eb648ff6df/test", "target": "${workspaceFolder}/zig-cache/o/b57ef32c79a05339fbe4a8eb648ff6df/test",
"arguments": "main.zig",
"cwd": "${workspaceRoot}", "cwd": "${workspaceRoot}",
"valuesFormatting": "parseText", "valuesFormatting": "parseText",
"preLaunchTask": "test" "preLaunchTask": "Build Test",
}, },
] ]
} }

View File

@ -13,5 +13,5 @@
}, },
"git.detectSubmodulesLimit": 0, "git.detectSubmodulesLimit": 0,
"git.ignoreSubmodules": true "git.ignoreSubmodules": true,
} }

8
.vscode/tasks.json vendored
View File

@ -44,11 +44,17 @@
{ {
"label": "Test", "label": "Test",
"type": "shell", "type": "shell",
"command": "zig build test", "command": "zig test src/main.zig",
"group": { "group": {
"kind": "test", "kind": "test",
"isDefault": true "isDefault": true
}, },
}, },
{
"label": "Build Test",
"type": "shell",
"command": "zig build test",
"group": "test"
},
], ],
} }

View File

@ -6,7 +6,7 @@ pub fn build(builder: *std.build.Builder) void {
// Ona executable. // Ona executable.
{ {
const ona_exe = builder.addExecutable("ona", "src/main.zig"); const ona_exe = builder.addExecutable("ona", "./src/main.zig");
ona_exe.setTarget(target); ona_exe.setTarget(target);
ona_exe.setBuildMode(mode); ona_exe.setBuildMode(mode);
@ -25,7 +25,7 @@ pub fn build(builder: *std.build.Builder) void {
// Ona tests. // Ona tests.
{ {
const ona_tests = builder.addTest("src/main.zig"); const ona_tests = builder.addTestExe("test", "./src/main.zig");
ona_tests.setTarget(target); ona_tests.setTarget(target);
ona_tests.setBuildMode(mode); ona_tests.setBuildMode(mode);

View File

@ -92,28 +92,26 @@ pub const FixedPushError = error {
}; };
test "fixed stack" { test "fixed stack" {
const testing = @import("std").testing; const testing = std.testing;
const expectError = testing.expectError;
const expectEqual = testing.expectEqual;
var buffer = std.mem.zeroes([4]u8); var buffer = std.mem.zeroes([4]u8);
var stack = Fixed(u8){.buffer = &buffer}; var stack = Fixed(u8){.buffer = &buffer};
try expectEqual(stack.count(), 0); try testing.expectEqual(stack.count(), 0);
try expectEqual(stack.pop(), null); try testing.expectEqual(stack.pop(), null);
try stack.push(69); try stack.push(69);
try expectEqual(stack.count(), 1); try testing.expectEqual(stack.count(), 1);
try expectEqual(stack.pop(), 69); try testing.expectEqual(stack.pop(), 69);
try stack.pushAll(&.{42, 10, 95, 0}); try stack.pushAll(&.{42, 10, 95, 0});
try expectEqual(stack.count(), 4); try testing.expectEqual(stack.count(), 4);
try expectError(FixedPushError.Overflow, stack.push(1)); try testing.expectError(FixedPushError.Overflow, stack.push(1));
try expectError(FixedPushError.Overflow, stack.pushAll(&.{1, 11, 11})); try testing.expectError(FixedPushError.Overflow, stack.pushAll(&.{1, 11, 11}));
stack.clear(); stack.clear();
try expectEqual(stack.count(), 0); try testing.expectEqual(stack.count(), 0);
const writer = stack.writer(); const writer = stack.writer();
try expectEqual(writer.write(&.{0, 0, 0, 0}), 4); try testing.expectEqual(writer.write(&.{0, 0, 0, 0}), 4);
try expectEqual(writer.writeByte(0), false); try testing.expectEqual(writer.writeByte(0), false);
} }