diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/custom_test_frameworks/auxiliary | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/custom_test_frameworks/auxiliary')
-rw-r--r-- | src/test/ui/custom_test_frameworks/auxiliary/dynamic_runner.rs | 35 | ||||
-rw-r--r-- | src/test/ui/custom_test_frameworks/auxiliary/example_runner.rs | 10 |
2 files changed, 45 insertions, 0 deletions
diff --git a/src/test/ui/custom_test_frameworks/auxiliary/dynamic_runner.rs b/src/test/ui/custom_test_frameworks/auxiliary/dynamic_runner.rs new file mode 100644 index 000000000..a56e0b1f5 --- /dev/null +++ b/src/test/ui/custom_test_frameworks/auxiliary/dynamic_runner.rs @@ -0,0 +1,35 @@ +use std::process::exit; + +pub trait Testable { + // Name of the test + fn name(&self) -> String; + + // Tests pass by default + fn run(&self) -> bool { + true + } + + // A test can generate subtests + fn subtests(&self) -> Vec<Box<dyn Testable>> { + vec![] + } +} + +fn run_test(t: &dyn Testable) -> bool { + let success = t.subtests().into_iter().all(|sub_t| run_test(&*sub_t)) && t.run(); + println!("{}...{}", t.name(), if success { "SUCCESS" } else { "FAIL" }); + success +} + +pub fn runner(tests: &[&dyn Testable]) { + let mut failed = false; + for t in tests { + if !run_test(*t) { + failed = true; + } + } + + if failed { + exit(1); + } +} diff --git a/src/test/ui/custom_test_frameworks/auxiliary/example_runner.rs b/src/test/ui/custom_test_frameworks/auxiliary/example_runner.rs new file mode 100644 index 000000000..dd68c0685 --- /dev/null +++ b/src/test/ui/custom_test_frameworks/auxiliary/example_runner.rs @@ -0,0 +1,10 @@ +pub trait Testable { + fn name(&self) -> String; + fn run(&self) -> Option<String>; // None will be success, Some is the error message +} + +pub fn runner(tests: &[&dyn Testable]) { + for t in tests { + print!("{}........{}", t.name(), t.run().unwrap_or_else(|| "SUCCESS".to_string())); + } +} |