Skip to content

Commit bb8212a

Browse files
committed
fixup: add rstest
1 parent 6fabbac commit bb8212a

3 files changed

Lines changed: 143 additions & 80 deletions

File tree

Cargo.lock

Lines changed: 55 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ procfs = "0.17.0"
6262
temp-env = { version = "0.3.6", features = ["async_closure"] }
6363
insta = { version = "1.29.0", features = ["json", "redactions"] }
6464
test-with = { version = "0.15", default-features = false, features = [] }
65+
rstest = { version = "0.25.0", default-features = false }
6566

6667
[workspace.metadata.release]
6768
sign-tag = true

src/run/runner/tests.rs

Lines changed: 87 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,25 @@ use crate::run::runner::valgrind::executor::ValgrindExecutor;
66
use crate::run::{RunnerMode, runner::wall_time::executor::WallTimeExecutor};
77
use tempfile::TempDir;
88

9+
const SIMPLE_ECHO_SCRIPT: &str = "echo 'Hello, World!'";
910
const MULTILINE_ECHO_SCRIPT: &str = "echo \"Working\"
1011
echo \"with\"
1112
echo \"multiple lines\"";
12-
1313
const MULTILINE_ECHO_WITH_SEMICOLONS: &str = "echo \"Working\";
1414
echo \"with\";
1515
echo \"multiple lines\";";
16-
1716
const DIRECTORY_CHECK_SCRIPT: &str = "cd /tmp
1817
# Check that the directory is actually changed
1918
if [ $(basename $(pwd)) != \"tmp\" ]; then
2019
exit 1
2120
fi";
22-
23-
const BENCHMARK_COMMANDS: [&str; 5] = [
24-
"echo 'Hello, World!'",
25-
MULTILINE_ECHO_WITH_SEMICOLONS,
26-
MULTILINE_ECHO_WITH_SEMICOLONS,
27-
MULTILINE_ECHO_SCRIPT,
28-
DIRECTORY_CHECK_SCRIPT,
29-
];
30-
3121
const ENV_VAR_VALIDATION_SCRIPT: &str = "
3222
output=$(echo \"$MY_ENV_VAR\")
3323
if [ \"$output\" != \"Hello\" ]; then
3424
echo \"Assertion failed: Expected 'Hello' but got '$output'\"
3525
exit 1
3626
fi";
3727

38-
const ENV_COMMANDS: [(&str, &str, &str); 1] = [("MY_ENV_VAR", "Hello", ENV_VAR_VALIDATION_SCRIPT)];
39-
4028
async fn create_test_setup() -> (SystemInfo, RunData, TempDir) {
4129
let temp_dir = TempDir::new().unwrap();
4230

@@ -48,109 +36,128 @@ async fn create_test_setup() -> (SystemInfo, RunData, TempDir) {
4836
(system_info, run_data, temp_dir)
4937
}
5038

39+
#[rstest::rstest]
40+
#[case(SIMPLE_ECHO_SCRIPT)]
41+
#[case(MULTILINE_ECHO_WITH_SEMICOLONS)]
42+
#[case(MULTILINE_ECHO_SCRIPT)]
43+
#[case(DIRECTORY_CHECK_SCRIPT)]
5144
#[tokio::test]
52-
async fn test_valgrind_executor() {
45+
async fn test_valgrind_executor(#[case] cmd: &str) {
5346
let (system_info, run_data, _temp_dir) = create_test_setup().await;
5447

5548
let executor = ValgrindExecutor;
5649
executor.setup(&system_info).await.unwrap();
5750

58-
for cmd in BENCHMARK_COMMANDS {
59-
eprintln!("Running command: {cmd}");
51+
eprintln!("Running command: {cmd}");
6052

61-
let config = Config {
62-
mode: RunnerMode::Instrumentation,
63-
command: cmd.to_string(),
64-
..Config::test()
65-
};
53+
let config = Config {
54+
mode: RunnerMode::Instrumentation,
55+
command: cmd.to_string(),
56+
..Config::test()
57+
};
6658

67-
executor
68-
.run(&config, &system_info, &run_data, &None)
69-
.await
70-
.unwrap();
71-
executor
72-
.teardown(&config, &system_info, &run_data)
73-
.await
74-
.unwrap();
75-
}
59+
executor
60+
.run(&config, &system_info, &run_data, &None)
61+
.await
62+
.unwrap();
63+
executor
64+
.teardown(&config, &system_info, &run_data)
65+
.await
66+
.unwrap();
7667
}
7768

69+
#[rstest::rstest]
70+
#[case(SIMPLE_ECHO_SCRIPT, false)]
71+
#[case(SIMPLE_ECHO_SCRIPT, true)]
72+
#[case(MULTILINE_ECHO_WITH_SEMICOLONS, false)]
73+
#[case(MULTILINE_ECHO_WITH_SEMICOLONS, true)]
74+
#[case(MULTILINE_ECHO_SCRIPT, false)]
75+
#[case(MULTILINE_ECHO_SCRIPT, true)]
76+
#[case(DIRECTORY_CHECK_SCRIPT, false)]
77+
#[case(DIRECTORY_CHECK_SCRIPT, true)]
7878
#[tokio::test]
79-
async fn test_walltime_executor() {
79+
async fn test_walltime_executor(#[case] cmd: &str, #[case] enable_perf: bool) {
8080
let (system_info, run_data, _temp_dir) = create_test_setup().await;
8181

8282
let executor = WallTimeExecutor::new();
8383
executor.setup(&system_info).await.unwrap();
8484

85-
for enable_perf in [false, true] {
86-
for cmd in BENCHMARK_COMMANDS {
87-
eprintln!("Running command: {cmd}");
88-
89-
let config = Config {
90-
mode: RunnerMode::Walltime,
91-
command: cmd.to_string(),
92-
enable_perf,
93-
..Config::test()
94-
};
95-
96-
executor
97-
.run(&config, &system_info, &run_data, &None)
98-
.await
99-
.unwrap();
100-
101-
// Don't execute teardown since the cmds dont use the FIFO to set the integration metadata.
102-
}
103-
}
85+
eprintln!("Running command: {cmd}");
86+
87+
let config = Config {
88+
mode: RunnerMode::Walltime,
89+
command: cmd.to_string(),
90+
enable_perf,
91+
..Config::test()
92+
};
93+
94+
executor
95+
.run(&config, &system_info, &run_data, &None)
96+
.await
97+
.unwrap();
98+
99+
// Don't execute teardown since the cmds dont use the FIFO to set the integration metadata.
104100
}
105101

102+
#[rstest::rstest]
103+
#[case("MY_ENV_VAR", "Hello", ENV_VAR_VALIDATION_SCRIPT)]
106104
#[tokio::test]
107-
async fn test_valgrind_executor_with_env() {
105+
async fn test_valgrind_executor_with_env(
106+
#[case] env_var: &str,
107+
#[case] env_value: &str,
108+
#[case] cmd: &str,
109+
) {
108110
let (system_info, run_data, _temp_dir) = create_test_setup().await;
109111

110112
let executor = ValgrindExecutor;
111113
executor.setup(&system_info).await.unwrap();
112114

113115
let config = Config {
114116
mode: RunnerMode::Instrumentation,
117+
command: cmd.to_string(),
115118
..Config::test()
116119
};
117-
test_executor_with_env(&executor, config, &system_info, &run_data).await;
120+
121+
eprintln!("Running command: {cmd}");
122+
123+
temp_env::async_with_vars(&[(env_var, Some(env_value))], async {
124+
executor
125+
.run(&config, &system_info, &run_data, &None)
126+
.await
127+
.unwrap();
128+
})
129+
.await;
118130
}
119131

132+
#[rstest::rstest]
133+
#[case("MY_ENV_VAR", "Hello", ENV_VAR_VALIDATION_SCRIPT, false)]
134+
#[case("MY_ENV_VAR", "Hello", ENV_VAR_VALIDATION_SCRIPT, true)]
120135
#[tokio::test]
121-
async fn test_walltime_executor_with_env() {
136+
async fn test_walltime_executor_with_env(
137+
#[case] env_var: &str,
138+
#[case] env_value: &str,
139+
#[case] cmd: &str,
140+
#[case] enable_perf: bool,
141+
) {
122142
let (system_info, run_data, _temp_dir) = create_test_setup().await;
123143

124144
let executor = WallTimeExecutor::new();
125145
executor.setup(&system_info).await.unwrap();
126146

127-
for enable_perf in [false, true] {
128-
let config = Config {
129-
mode: RunnerMode::Walltime,
130-
enable_perf,
131-
..Config::test()
132-
};
147+
let config = Config {
148+
mode: RunnerMode::Walltime,
149+
command: cmd.to_string(),
150+
enable_perf,
151+
..Config::test()
152+
};
133153

134-
test_executor_with_env(&executor, config, &system_info, &run_data).await;
135-
}
136-
}
154+
eprintln!("Running command: {cmd}");
137155

138-
async fn test_executor_with_env(
139-
executor: &dyn Executor,
140-
mut config: Config,
141-
system_info: &SystemInfo,
142-
run_data: &RunData,
143-
) {
144-
for (env_var, env_value, cmd) in ENV_COMMANDS {
145-
eprintln!("Running command: {cmd}");
146-
config.command = cmd.to_string();
147-
148-
temp_env::async_with_vars(&[(env_var, Some(env_value))], async {
149-
executor
150-
.run(&config, system_info, run_data, &None)
151-
.await
152-
.unwrap();
153-
})
154-
.await;
155-
}
156+
temp_env::async_with_vars(&[(env_var, Some(env_value))], async {
157+
executor
158+
.run(&config, &system_info, &run_data, &None)
159+
.await
160+
.unwrap();
161+
})
162+
.await;
156163
}

0 commit comments

Comments
 (0)