Test

#load "std/test.bl"

Integrated unit testing API.

test_eq

test_eq :: fn { 
    fn (got: string_view, expected: string_view, loc :: #call_location) ; 
    fn (got: string, expected: string_view, loc :: #call_location) ; 
    fn (got: string_view, expected: string, loc :: #call_location) ; 
    fn (got: string, expected: string, loc :: #call_location) ; 
    fn (got: f32, expected: f32, epsilon : f32: std.F32_EPSILON, loc :: #call_location) ; 
    fn (got: f64, expected: f64, epsilon : f64: std.F64_EPSILON, loc :: #call_location) ; 
    fn (got: ?T, expected: T, loc :: #call_location) ; 
}

Overloads

fn (got: string_view, expected: string_view, loc := #call_location)
fn (got: string, expected: string_view, loc := #call_location)
fn (got: string_view, expected: string, loc := #call_location)
fn (got: string, expected: string, loc := #call_location)
fn (got: f32, expected: f32, epsilon: f32 = std.F32_EPSILON, loc := #call_location)
fn (got: f64, expected: f64, epsilon: f64 = std.F64_EPSILON, loc := #call_location)
fn (got: ?T, expected: T, loc := #call_location)

Test whether got value is equal to expected value.

File: test.bl

test_neq

test_neq :: fn { 
    fn (got: string_view, expected: string_view, loc :: #call_location) ; 
    fn (got: string, expected: string_view, loc :: #call_location) ; 
    fn (got: string_view, expected: string, loc :: #call_location) ; 
    fn (got: string, expected: string, loc :: #call_location) ; 
    fn (got: f32, not_expected: f32, epsilon : f32: std.F32_EPSILON, loc :: #call_location) ; 
    fn (got: f64, not_expected: f64, epsilon : f64: std.F64_EPSILON, loc :: #call_location) ; 
    fn (got: ?T, not_expected: T, loc :: #call_location) ; 
}

Overloads

fn (got: string, not_expected: string, loc := #call_location)
fn (got: string, expected: string_view, loc := #call_location)
fn (got: string_view, expected: string, loc := #call_location)
fn (got: string, expected: string, loc := #call_location)
fn (got: f32, not_expected: f32, epsilon: f32 = std.F32_EPSILON, loc := #call_location)
fn (got: f64, not_expected: f64, epsilon: f64 = std.F64_EPSILON, loc := #call_location)
fn (got: ?T, not_expected: T, loc := #call_location)

Test whether got value is not equal to not_expected value.

File: test.bl

test_gt

test_gt :: fn (v1: ?T, v2: T, loc :: #call_location) 

Test whether v1 is greater than v2

File: test.bl

test_lt

test_lt :: fn (v1: ?T, v2: T, loc :: #call_location) 

Test whether v1 is less than v2

File: test.bl

test_true

test_true :: fn (v: bool, loc :: #call_location) 

Test whether v value is true.

File: test.bl

test_false

test_false :: fn (v: bool, loc :: #call_location) 

Test whether v value is false.

File: test.bl

test_null

test_null :: fn (ptr: *?T, loc :: #call_location) 

Test whether ptr pointer value is null.

File: test.bl

test_not_null

test_not_null :: fn (ptr: *?T, loc :: #call_location) 

Test whether ptr pointer value is not null.

File: test.bl

test_ok

test_ok :: fn (err: Error, loc :: #call_location)  #inline

Test whether err is OK.

File: test.bl

test_not_ok

test_not_ok :: fn (err: Error, loc :: #call_location)  #inline

Test whether err is not OK.

File: test.bl

test_is_error

test_is_error :: fn (got_err: Error, expected_code: s32, loc :: #call_location)  #inline

Test whether got_err code is expected_code.

File: test.bl

test_run

test_run :: fn (print_results :: true) s32

Execute all registered test cases in current assembly. The test_run function uses compiler builtin TEST_CASES constant containing slice of all registered test cases in the current assembly (all functions with hash directive #test).

Test case execution can be used in runtime and compile time, in both cases function remap default behaviour of panic() function call and try to report all failing tests without termination.

Formatted output containing information about every test run status and summary report is produced during execution of this function. In case of test failure all needed information about fail source location is reported into standard output.

Returns number of failed tests.

Example

#load "std/test.bl"

my_test :: fn () #test {
    print("Hello from test case!!!\n");     
}

main :: fn () s32 {
    return test_run(); 
} 

File: test.bl