Skip to main content

ruda_test_utils/test_mode/
base.rs

1//! Test-mode policy.
2//!
3//! Reads `ruda-test.toml` (see `crate::config`) once and decides whether each
4//! test outcome should `Accept` or `Reject`. The TOML's `[test] policy`
5//! field controls the pass/fail logic; the `[print]` section drives what
6//! gets dumped to stdout (in `correctness::render`).
7
8use crate::config::{TestPolicy, config};
9use crate::{TestDecision, TestOutcome, ValidationResult};
10
11/// Decide whether a test outcome passes or fails under the active policy.
12pub fn decide(outcome: TestOutcome) -> TestDecision {
13    use TestDecision::*;
14    use TestOutcome::*;
15    use ValidationResult::*;
16
17    let cfg = config();
18    let print_force_fail = cfg.print.enabled && cfg.print.force_fail;
19
20    match cfg.test.policy {
21        TestPolicy::Correct => match outcome {
22            Validated(result) => match result {
23                Pass => {
24                    if print_force_fail {
25                        Reject("print mode: tensors dumped".into())
26                    } else {
27                        Accept
28                    }
29                }
30                Fail(reason) => Reject(reason),
31                Error(reason) => Reject(reason),
32                Skipped(_) => Accept,
33            },
34            CompileError(reason) => {
35                if print_force_fail {
36                    Reject(reason)
37                } else {
38                    Accept
39                }
40            }
41        },
42        TestPolicy::Strict => match outcome {
43            Validated(result) => match result {
44                Pass => {
45                    if print_force_fail {
46                        Reject("print mode: tensors dumped".into())
47                    } else {
48                        Accept
49                    }
50                }
51                Fail(reason) => Reject(reason),
52                Error(reason) => Reject(reason),
53                Skipped(reason) => Reject(reason),
54            },
55            CompileError(reason) => Reject(reason),
56        },
57        TestPolicy::FailIfRun => match outcome {
58            Validated(result) => match result {
59                Pass => Reject("Actually passed, but fail-if-run policy active".into()),
60                Fail(_) => Accept,
61                Error(_) => Accept,
62                Skipped(_) => Accept,
63            },
64            CompileError(_) => Accept,
65        },
66    }
67}