From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- .../auxiliary/dynamic_runner.rs | 35 ++++++++++++++++++++++ .../auxiliary/example_runner.rs | 10 +++++++ 2 files changed, 45 insertions(+) create mode 100644 src/test/ui/custom_test_frameworks/auxiliary/dynamic_runner.rs create mode 100644 src/test/ui/custom_test_frameworks/auxiliary/example_runner.rs (limited to 'src/test/ui/custom_test_frameworks/auxiliary') 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> { + 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; // 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())); + } +} -- cgit v1.2.3