Compare commits

...

4 Commits

Author SHA1 Message Date
kayomn 3ca0bd5724 Add ability to debug test suite in VS Code
continuous-integration/drone/push Build is passing Details
2022-10-02 12:56:19 +01:00
kayomn 11b6040237 Fix incorrect test root in build.zig 2022-10-02 12:22:22 +01:00
kayomn 3f2f37e0f5 Fix incorrect test root in build.zig 2022-10-02 12:22:04 +01:00
kayomn 9c1ddd6e8f Add tests to VS Code debug config 2022-10-02 12:20:53 +01:00
6 changed files with 44 additions and 32 deletions

36
.vscode/launch.json vendored
View File

@ -1,16 +1,24 @@
{ {
// Use IntelliSense to learn about possible attributes. "version": "0.2.0",
// Hover to view descriptions of existing attributes. "configurations": [
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 {
"version": "0.2.0", "name": "Build",
"configurations": [ "type": "gdb",
{ "request": "launch",
"name": "Ona", "target": "${workspaceFolder}/zig-out/bin/ona",
"type": "gdb", "cwd": "${workspaceRoot}",
"request": "launch", "valuesFormatting": "parseText",
"target": "${workspaceFolder}/zig-out/bin/ona", "preLaunchTask": "Build",
"cwd": "${workspaceRoot}", },
"valuesFormatting": "parseText", {
} "name": "Test",
] "type": "gdb",
"request": "launch",
"target": "${workspaceFolder}/zig-cache/o/b57ef32c79a05339fbe4a8eb648ff6df/test",
"arguments": "main.zig",
"cwd": "${workspaceRoot}",
"valuesFormatting": "parseText",
"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/stack.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

@ -15,7 +15,7 @@ pub fn main() anyerror!void {
} }
test { test {
// Empty test is here to run all others (for now). _ = @import("./mem.zig");
} }
fn run(event_loop: *sys.EventLoop, graphics: *sys.GraphicsContext) anyerror!void { fn run(event_loop: *sys.EventLoop, graphics: *sys.GraphicsContext) anyerror!void {

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);
} }