migrate langref documentation generation to the build system
[zig.git] / doc / langref / testing_introduction.zig
blob6a46c8d6887f06c003dadae16383f07cd476d6cc
1 const std = @import("std");
3 test "expect addOne adds one to 41" {
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);
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);
18 /// The function `addOne` adds one to the number given as its argument.
19 fn addOne(number: i32) i32 {
20     return number + 1;
23 // test