Skip to content

Commit 660f995

Browse files
Ph0enixKMlens0021
authored andcommitted
refactor: test_amber
1 parent cabc2ea commit 660f995

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/tests/mod.rs

+17-12
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,26 @@ pub fn eval_amber_code(code: &str) -> Result<String, Message> {
2626

2727
/// Tests script output in case of success or failure
2828
pub fn test_amber(code: &str, result: &str, target: TestOutcomeTarget) {
29+
let evaluated = eval_amber_code(code);
2930
match target {
30-
TestOutcomeTarget::Success => {
31-
match eval_amber_code(code) {
32-
Ok(eval_result) => assert_eq!(
33-
eval_result.trim_end_matches('\n'),
31+
TestOutcomeTarget::Success => match evaluated {
32+
Ok(stdout) => {
33+
assert_eq!(
34+
stdout.trim_end_matches('\n'),
3435
result.trim_end_matches('\n'),
35-
),
36-
Err(err) => panic!("ERROR: {}", err.message.unwrap()),
37-
}
36+
)
37+
},
38+
Err(err) => {
39+
panic!("ERROR: {}", err.message.unwrap())
40+
},
3841
}
39-
TestOutcomeTarget::Failure => {
40-
match eval_amber_code(code) {
41-
Ok(eval_result) => panic!("Expected error, got: {}", eval_result),
42-
Err(err) => assert_eq!(err.message.expect("Error message expected"), result),
43-
}
42+
TestOutcomeTarget::Failure => match evaluated {
43+
Ok(stdout) => {
44+
panic!("Expected error, got: {}", stdout)
45+
},
46+
Err(err) => {
47+
assert_eq!(err.message.expect("Error message expected"), result)
48+
},
4449
}
4550
}
4651
}

0 commit comments

Comments
 (0)