testing_introduction.zig (758B) - Raw
1 const std = @import("std"); 2 3 test "expect addOne adds one to 41" { 4 5 // The Standard Library contains useful functions to help create tests. 6 // `expect` is a function that verifies its argument is true. 7 // It will return an error if its argument is false to indicate a failure. 8 // `try` is used to return an error to the test runner to notify it that the test failed. 9 try std.testing.expect(addOne(41) == 42); 10 } 11 12 test addOne { 13 // A test name can also be written using an identifier. 14 // This is a doctest, and serves as documentation for `addOne`. 15 try std.testing.expect(addOne(41) == 42); 16 } 17 18 /// The function `addOne` adds one to the number given as its argument. 19 fn addOne(number: i32) i32 { 20 return number + 1; 21 } 22 23 // test