forked from nulang-org/nulang
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.nula
More file actions
39 lines (35 loc) · 1.33 KB
/
Copy pathtest.nula
File metadata and controls
39 lines (35 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Nulang standard library — testing primitives via built-in Test effect.
// Language version: 2.0.0-alpha
//
// The `Test` effect is wired into the standalone VM. Assertion failures
// produce runtime errors that abort execution and are reported by the
// `nula test` runner.
//
// Usage:
// import std.test
// fn my_tests() {
// test.assert(1 + 1 == 2, "basic arithmetic failed")
// test.assert_eq(add(1, 2), 3)
// test.assert_true(meaning_of_life() == 42)
// }
/// Assert that a boolean condition is true.
/// On failure, produces a runtime error: `assertion failed: {msg}`.
pub fn assert(cond: Bool, msg: String) -> Unit ! {Test} {
perform Test.assert(cond, msg)
}
/// Assert that two integers are equal.
/// On failure, produces a runtime error: `assertion failed: expected {b}, got {a}`.
/// `a` is the actual value, `b` is the expected value.
pub fn assert_eq(a: Int, b: Int) -> Unit ! {Test} {
perform Test.assert_eq(a, b)
}
/// Assert that a boolean condition is true.
/// On failure, produces a runtime error: `assertion failed`.
pub fn assert_true(cond: Bool) -> Unit ! {Test} {
perform Test.assert_true(cond)
}
/// Fail unconditionally with a message.
/// Produces a runtime error: `assertion failed: {message}`.
pub fn fail_with(message: String) -> Unit ! {Test} {
perform Test.assert(false, message)
}