Skip to content

Commit f881627

Browse files
committed
Run tests in the order given
1 parent 372d6d7 commit f881627

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

test/test-manager/src/main.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ enum Commands {
118118
#[arg(long)]
119119
openvpn_certificate: Option<PathBuf>,
120120

121-
/// Only run tests matching substrings
121+
/// Names of tests to run. The order given will be respected. If not set, all tests will be
122+
/// run.
122123
test_filters: Vec<String>,
123124

124125
/// Print results live

test/test-manager/src/run_tests.rs

+23-17
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{
22
logging::{Logger, Panic, TestOutput, TestResult},
33
mullvad_daemon::{self, MullvadClientArgument, RpcClientProvider},
44
summary::SummaryLogger,
5-
tests::{self, config::TEST_CONFIG, get_tests, TestContext},
5+
tests::{self, config::TEST_CONFIG, get_tests, TestContext, TestMetadata},
66
vm,
77
};
88
use anyhow::{Context, Result};
@@ -103,7 +103,7 @@ impl TestHandler<'_> {
103103
pub async fn run(
104104
config: tests::config::TestConfig,
105105
instance: &dyn vm::VmInstance,
106-
test_filters: &[String],
106+
specified_tests: &[String],
107107
skip_wait: bool,
108108
print_failed_tests_only: bool,
109109
summary_logger: Option<SummaryLogger>,
@@ -141,21 +141,7 @@ pub async fn run(
141141
logger: Logger::get_or_init(),
142142
};
143143

144-
let mut tests = get_tests();
145-
146-
tests.retain(|test| test.should_run_on_os(TEST_CONFIG.os));
147-
148-
if !test_filters.is_empty() {
149-
tests.retain(|test| {
150-
for command in test_filters {
151-
let command = command.to_lowercase();
152-
if test.command.to_lowercase().contains(&command) {
153-
return true;
154-
}
155-
}
156-
false
157-
});
158-
}
144+
let tests = get_filtered_tests(specified_tests)?;
159145

160146
if TEST_CONFIG.app_package_to_upgrade_from_filename.is_some() {
161147
test_handler
@@ -192,6 +178,26 @@ pub async fn run(
192178
Ok(result)
193179
}
194180

181+
fn get_filtered_tests(specified_tests: &[String]) -> Result<Vec<&TestMetadata>, anyhow::Error> {
182+
let mut tests = get_tests();
183+
tests.retain(|test| test.should_run_on_os(TEST_CONFIG.os));
184+
if !specified_tests.is_empty() {
185+
specified_tests
186+
.iter()
187+
.map(|f| {
188+
tests
189+
.iter()
190+
.find(|t| t.command.eq_ignore_ascii_case(f))
191+
.cloned()
192+
.ok_or(anyhow::anyhow!("Test '{f}' not found"))
193+
})
194+
.collect()
195+
} else {
196+
// Keep all tests
197+
Ok(tests)
198+
}
199+
}
200+
195201
async fn register_test_result(
196202
test_result: TestResult,
197203
failed_tests: &mut Vec<&str>,

0 commit comments

Comments
 (0)