Skip to content

Commit 077286c

Browse files
committed
Remove must_succede test macro parameter
This simplifes handling of test results.
1 parent 06b2b35 commit 077286c

File tree

4 files changed

+13
-68
lines changed

4 files changed

+13
-68
lines changed

test/test-manager/src/run_tests.rs

+10-34
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{
22
logging::{Logger, Panic, TestOutput, TestResult},
33
mullvad_daemon::{self, MullvadClientArgument},
4-
summary::{self, maybe_log_test_result},
4+
summary::SummaryLogger,
55
tests::{self, config::TEST_CONFIG, get_tests, TestContext},
66
vm,
77
};
@@ -23,8 +23,8 @@ pub async fn run(
2323
test_filters: &[String],
2424
skip_wait: bool,
2525
print_failed_tests_only: bool,
26-
mut summary_logger: Option<summary::SummaryLogger>,
27-
) -> Result<()> {
26+
mut summary_logger: Option<SummaryLogger>,
27+
) -> Result<TestResult> {
2828
log::trace!("Setting test constants");
2929
TEST_CONFIG.init(config);
3030

@@ -127,38 +127,14 @@ pub async fn run(
127127

128128
test_output.print();
129129

130-
maybe_log_test_result(
131-
summary_logger.as_mut(),
130+
register_test_result(
131+
test_output.result,
132+
&mut failed_tests,
132133
test.name,
133-
if test_succeeded {
134-
summary::TestResult::Pass
135-
} else {
136-
summary::TestResult::Fail
137-
},
134+
&mut successful_tests,
135+
summary_logger.as_mut(),
138136
)
139-
.await
140-
.context("Failed to log test result")?;
141-
142-
match test_result.result {
143-
Err(panic) => {
144-
failed_tests.push(test.name);
145-
final_result = Err(panic).context("test panicked");
146-
if test.must_succeed {
147-
break;
148-
}
149-
}
150-
Ok(Err(failure)) => {
151-
failed_tests.push(test.name);
152-
final_result = Err(failure).context("test failed");
153-
if test.must_succeed {
154-
break;
155-
}
156-
}
157-
Ok(Ok(result)) => {
158-
successful_tests.push(test.name);
159-
final_result = final_result.and(Ok(result));
160-
}
161-
}
137+
.await?;
162138
}
163139

164140
log::info!("TESTS THAT SUCCEEDED:");
@@ -167,7 +143,7 @@ pub async fn run(
167143
}
168144

169145
log::info!("TESTS THAT FAILED:");
170-
for test in failed_tests {
146+
for test in &failed_tests {
171147
log::info!("{test}");
172148
}
173149

test/test-manager/src/summary.rs

+1-18
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,6 @@ impl SummaryLogger {
107107
}
108108
}
109109

110-
/// Convenience function that logs when there's a value, and is a no-op otherwise.
111-
// y u no trait async fn
112-
pub async fn maybe_log_test_result(
113-
summary_logger: Option<&mut SummaryLogger>,
114-
test_name: &str,
115-
test_result: TestResult,
116-
) -> Result<(), Error> {
117-
match summary_logger {
118-
Some(logger) => logger.log_test_result(test_name, test_result).await,
119-
None => Ok(()),
120-
}
121-
}
122-
123110
/// Parsed summary results
124111
pub struct Summary {
125112
/// Name of the configuration
@@ -263,11 +250,7 @@ pub async fn print_summary_table<P: AsRef<Path>>(summary_files: &[P]) {
263250
for test in &tests {
264251
println!("<tr>");
265252

266-
println!(
267-
"<td>{}{}</td>",
268-
test.name,
269-
if test.must_succeed { " *" } else { "" }
270-
);
253+
println!("<td>{}</td>", test.name,);
271254

272255
let mut failed_platforms = vec![];
273256
for summary in &summaries {

test/test-manager/src/tests/test_metadata.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ pub struct TestMetadata {
99
pub func: TestWrapperFunction,
1010
pub priority: Option<i32>,
1111
pub always_run: bool,
12-
pub must_succeed: bool,
1312
}
1413

1514
impl TestMetadata {

test/test-manager/test_macro/src/lib.rs

+2-15
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ use test_rpc::meta::Os;
2323
/// * `priority` - The order in which tests will be run where low numbers run before high numbers
2424
/// and tests with the same number run in undefined order. `priority` defaults to 0.
2525
///
26-
/// * `must_succeed` - If the testing suite stops running if this test fails. `must_succeed`
27-
/// defaults to false.
28-
///
2926
/// * `always_run` - If the test should always run regardless of what test filters are provided by
3027
/// the user. `always_run` defaults to false.
3128
///
@@ -51,10 +48,10 @@ use test_rpc::meta::Os;
5148
///
5249
/// ## Create a test with custom parameters
5350
///
54-
/// This test will run early in the test loop and must succeed and will always run.
51+
/// This test will run early in the test loop and will always run.
5552
///
5653
/// ```ignore
57-
/// #[test_function(priority = -1337, must_succeed = true, always_run = true)]
54+
/// #[test_function(priority = -1337, always_run = true)]
5855
/// pub async fn test_function(
5956
/// rpc: ServiceClient,
6057
/// mut mullvad_client: mullvad_management_interface::MullvadProxyClient,
@@ -109,7 +106,6 @@ fn parse_marked_test_function(
109106
fn get_test_macro_parameters(attributes: &syn::AttributeArgs) -> Result<MacroParameters> {
110107
let mut priority = None;
111108
let mut always_run = false;
112-
let mut must_succeed = false;
113109
let mut targets = vec![];
114110

115111
for attribute in attributes {
@@ -129,11 +125,6 @@ fn get_test_macro_parameters(attributes: &syn::AttributeArgs) -> Result<MacroPar
129125
Lit::Bool(lit_bool) => always_run = lit_bool.value(),
130126
_ => bail!(nv, "'always_run' should have a bool value"),
131127
}
132-
} else if nv.path.is_ident("must_succeed") {
133-
match lit {
134-
Lit::Bool(lit_bool) => must_succeed = lit_bool.value(),
135-
_ => bail!(nv, "'must_succeed' should have a bool value"),
136-
}
137128
} else if nv.path.is_ident("target_os") {
138129
let Lit::Str(lit_str) = lit else {
139130
bail!(nv, "'target_os' should have a string value");
@@ -157,7 +148,6 @@ fn get_test_macro_parameters(attributes: &syn::AttributeArgs) -> Result<MacroPar
157148
Ok(MacroParameters {
158149
priority,
159150
always_run,
160-
must_succeed,
161151
targets,
162152
})
163153
}
@@ -176,7 +166,6 @@ fn create_test(test_function: TestFunction) -> proc_macro2::TokenStream {
176166
.collect();
177167

178168
let always_run = test_function.macro_parameters.always_run;
179-
let must_succeed = test_function.macro_parameters.must_succeed;
180169

181170
let func_name = test_function.name;
182171
let function_mullvad_version = test_function.function_parameters.mullvad_client.version();
@@ -219,7 +208,6 @@ fn create_test(test_function: TestFunction) -> proc_macro2::TokenStream {
219208
func: #wrapper_closure,
220209
priority: #test_function_priority,
221210
always_run: #always_run,
222-
must_succeed: #must_succeed,
223211
});
224212
}
225213
}
@@ -233,7 +221,6 @@ struct TestFunction {
233221
struct MacroParameters {
234222
priority: Option<i32>,
235223
always_run: bool,
236-
must_succeed: bool,
237224
targets: Vec<Os>,
238225
}
239226

0 commit comments

Comments
 (0)