aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Boesch <[email protected]>2023-05-03 18:17:21 +0200
committerChris Boesch <[email protected]>2023-05-03 18:17:21 +0200
commit193bee7d2dc4a04fc08d99ed66849a36695ecfb6 (patch)
treedbe5367df9d7a846eaaf7fe7f57b334019ecf584
parent72a6287a5f1784b6da091c1ef1cc3cb3c1153d05 (diff)
downloadziglings-193bee7d2dc4a04fc08d99ed66849a36695ecfb6.tar.xz
ziglings-193bee7d2dc4a04fc08d99ed66849a36695ecfb6.zip
Added new flag 'run_test' to support test steps for test exercises.
Also created a simple exercise '102_testing' to test the new flag. After the new build system is ready, we skip the exercise in the flow to finish the actual testing exercise.
-rw-r--r--build.zig9
-rw-r--r--exercises/102_testing.zig10
2 files changed, 19 insertions, 0 deletions
diff --git a/build.zig b/build.zig
index 3b59d70..7042fd5 100644
--- a/build.zig
+++ b/build.zig
@@ -35,6 +35,10 @@ pub const Exercise = struct {
/// We need to keep track of this, so we compile with libc
link_libc: bool = false,
+ /// This exercise doesn't have a main function.
+ /// We only call the test.
+ run_test: bool = false,
+
/// This exercise is not supported by the current Zig compiler.
skip: bool = false,
@@ -1080,6 +1084,11 @@ const exercises = [_]Exercise{
.output = "1. Wizard (Gold: 25, XP: 40)\n2. Bard (Gold: 11, XP: 17)\n3. Bard (Gold: 5, XP: 55)\n4. Warrior (Gold: 7392, XP: 21)",
},
.{
+ .main_file = "102_testing.zig",
+ .output = "All 1 tests passed.",
+ .run_test = true,
+ },
+ .{
.main_file = "999_the_end.zig",
.output = "\nThis is the end for now!\nWe hope you had fun and were able to learn a lot, so visit us again when the next exercises are available.",
},
diff --git a/exercises/102_testing.zig b/exercises/102_testing.zig
new file mode 100644
index 0000000..dc1da59
--- /dev/null
+++ b/exercises/102_testing.zig
@@ -0,0 +1,10 @@
+const std = @import("std");
+const testing = std.testing;
+
+fn add(a: u16, b: u16) u16 {
+ return a + b;
+}
+
+test "simple test" {
+ try testing.expect(add(41, 1) == 42);
+}