Skip to content

Commit 1ef2185

Browse files
committed
Use more idiomatic Rust for tests
1 parent 008f700 commit 1ef2185

File tree

1 file changed

+39
-61
lines changed

1 file changed

+39
-61
lines changed

cobalt-cli/src/tests/hello_world.rs

Lines changed: 39 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,18 @@ fn test_hello_world_aot() {
55
let input_path_str = "src/tests/inputs/hello_world.co";
66
let output_path_str = "src/tests/outputs/hello_world";
77

8-
let input = clio::Input::new(input_path_str);
9-
assert!(
10-
input.is_ok(),
11-
"(clio) failed to load input: {:?}",
12-
&input.err()
13-
);
14-
let output = clio::OutputPath::new(output_path_str);
15-
assert!(
16-
output.is_ok(),
17-
"(clio) failed to load output: {:?}",
18-
&output.err()
19-
);
8+
let input = match clio::Input::new(input_path_str) {
9+
Ok(p) => p,
10+
Err(err) => panic!("(clio) failed to load input: {err}"),
11+
};
12+
let output = match clio::OutputPath::new(output_path_str) {
13+
Ok(p) => p,
14+
Err(err) => panic!("(clio) failed to load output: {err}"),
15+
};
2016

2117
let cli = Cli::Aot {
22-
input: input.unwrap(),
23-
output: Some(output.unwrap()),
18+
input: input,
19+
output: Some(output),
2420
linked: vec![],
2521
link_dirs: vec![],
2622
headers: vec![],
@@ -33,12 +29,9 @@ fn test_hello_world_aot() {
3329
timings: false,
3430
};
3531

36-
let result = driver(cli);
37-
assert!(
38-
result.is_ok(),
39-
"failure while compiling file: {:?}",
40-
&result.err()
41-
);
32+
if let Err(err) = driver(cli) {
33+
panic!("failure while compiling file: {err}")
34+
};
4235

4336
let command_output = Command::new(output_path_str)
4437
.output()
@@ -60,23 +53,18 @@ fn test_hello_world_aot_linked() {
6053
));
6154
// ---
6255

63-
let input_lib = clio::Input::new(input_lib_path_str);
64-
assert!(
65-
input_lib.is_ok(),
66-
"(clio) failed to load input: {:?}",
67-
&input_lib.unwrap_err()
68-
);
69-
70-
let output_lib = clio::OutputPath::new(&output_lib_path_str);
71-
assert!(
72-
output_lib.is_ok(),
73-
"(clio) failed to load output: {:?}",
74-
&output_lib.unwrap_err()
75-
);
56+
let input_lib = match clio::Input::new(input_lib_path_str) {
57+
Ok(p) => p,
58+
Err(err) => panic!("(clio) failed to load input: {err}"),
59+
};
60+
let output_lib = match clio::OutputPath::new(&output_lib_path_str) {
61+
Ok(p) => p,
62+
Err(err) => panic!("(clio) failed to load output: {err}"),
63+
};
7664

7765
let cli_lib = Cli::Aot {
78-
input: input_lib.unwrap(),
79-
output: Some(output_lib.unwrap()),
66+
input: input_lib,
67+
output: Some(output_lib),
8068
linked: vec![],
8169
link_dirs: vec![],
8270
headers: vec![],
@@ -89,31 +77,24 @@ fn test_hello_world_aot_linked() {
8977
timings: false,
9078
};
9179

92-
let result_lib = driver(cli_lib);
93-
assert!(
94-
result_lib.is_ok(),
95-
"failure while compiling library file: {:?}",
96-
&result_lib.err()
97-
);
80+
if let Err(err) = driver(cli_lib) {
81+
panic!("failure while compiling file: {err}")
82+
};
9883

9984
// ---
10085

101-
let input_main = clio::Input::new(input_main_path_str);
102-
assert!(
103-
input_main.is_ok(),
104-
"(clio) failed to load input: {:?}",
105-
&input_main.err()
106-
);
107-
let output_main = clio::OutputPath::new(output_main_path_str);
108-
assert!(
109-
output_main.is_ok(),
110-
"(clio) failed to load output: {:?}",
111-
&output_main.err()
112-
);
86+
let input_main = match clio::Input::new(input_main_path_str) {
87+
Ok(p) => p,
88+
Err(err) => panic!("(clio) failed to load input: {err}"),
89+
};
90+
let output_main = match clio::OutputPath::new(output_main_path_str) {
91+
Ok(p) => p,
92+
Err(err) => panic!("(clio) failed to load output: {err}"),
93+
};
11394

11495
let cli_main = Cli::Aot {
115-
input: input_main.unwrap(),
116-
output: Some(output_main.unwrap()),
96+
input: input_main,
97+
output: Some(output_main),
11798
linked: vec!["hello_world_linked".to_string()],
11899
link_dirs: vec!["src/tests/outputs".into()],
119100
headers: vec![],
@@ -126,12 +107,9 @@ fn test_hello_world_aot_linked() {
126107
timings: false,
127108
};
128109

129-
let result_main = driver(cli_main);
130-
assert!(
131-
result_main.is_ok(),
132-
"failure while compiling main file: {:?}",
133-
&result_main.err()
134-
);
110+
if let Err(err) = driver(cli_main) {
111+
panic!("failure while compiling file: {err}")
112+
};
135113

136114
// ---
137115

0 commit comments

Comments
 (0)