1
//! Self-hosted test framework — DEFTEST / ASSERT-EQUAL / RUN-TESTS.
2
//! Cover the registration → execution → summary path end to end via
3
//! the public Compiler API.
4

            
5
use super::common::{compile_and_validate, compile_expect_error};
6

            
7
#[test]
8
1
fn deftest_alone_compiles() {
9
1
    compile_and_validate("(deftest my-test (+ 1 1))");
10
1
}
11

            
12
#[test]
13
1
fn deftest_with_multi_form_body_compiles() {
14
1
    compile_and_validate(
15
1
        "(deftest multi (debug \"step 1\") (assert-equal 1 1) (debug \"step 2\"))",
16
    );
17
1
}
18

            
19
#[test]
20
1
fn deftest_requires_name_symbol_errors() {
21
1
    let err = compile_expect_error("(deftest \"not-a-symbol\" 42)");
22
1
    assert!(
23
1
        err.contains("DEFTEST") || err.contains("symbol"),
24
        "got: {err}"
25
    );
26
1
}
27

            
28
#[test]
29
1
fn deftest_without_body_errors() {
30
1
    let err = compile_expect_error("(deftest empty)");
31
1
    assert!(err.contains("DEFTEST"), "got: {err}");
32
1
}
33

            
34
#[test]
35
1
fn assert_equal_equal_returns_nil() {
36
1
    compile_and_validate("(assert-equal 1 1)");
37
1
}
38

            
39
#[test]
40
1
fn assert_equal_unequal_errors() {
41
1
    let err = compile_expect_error("(assert-equal 1 2)");
42
1
    assert!(err.contains("assertion failed"), "got: {err}");
43
1
}
44

            
45
#[test]
46
1
fn assert_equal_compares_strings() {
47
1
    compile_and_validate("(assert-equal \"abc\" \"abc\")");
48
1
}
49

            
50
#[test]
51
1
fn assert_equal_arity_zero_errors() {
52
1
    let err = compile_expect_error("(assert-equal)");
53
1
    assert!(err.contains("ASSERT-EQUAL"), "got: {err}");
54
1
}
55

            
56
#[test]
57
1
fn run_tests_empty_registry_reports_zero() {
58
1
    compile_and_validate("(run-tests)");
59
1
}
60

            
61
#[test]
62
1
fn run_tests_after_one_passing_test() {
63
1
    compile_and_validate("(deftest passes (assert-equal 1 1)) (run-tests)");
64
1
}
65

            
66
#[test]
67
1
fn run_tests_after_one_failing_test() {
68
    // The failing test is caught by RUN-TESTS and counted; the
69
    // outer compile-and-validate must still succeed.
70
1
    compile_and_validate("(deftest fails (assert-equal 1 2)) (run-tests)");
71
1
}
72

            
73
#[test]
74
1
fn run_tests_after_mixed_pass_and_fail() {
75
1
    compile_and_validate(
76
1
        "(deftest a (assert-equal 1 1)) \
77
1
         (deftest b (assert-equal 2 3)) \
78
1
         (deftest c (assert-equal \"x\" \"x\")) \
79
1
         (run-tests)",
80
    );
81
1
}
82

            
83
#[test]
84
1
fn run_tests_rejects_args() {
85
1
    let err = compile_expect_error("(run-tests 42)");
86
1
    assert!(err.contains("RUN-TESTS"), "got: {err}");
87
1
}