Skip to content

Commit c5017f0

Browse files
Result handling for typechecking tests
1 parent 419e3d6 commit c5017f0

File tree

1 file changed

+21
-51
lines changed

1 file changed

+21
-51
lines changed

src/typecheck.rs

Lines changed: 21 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -225,87 +225,57 @@ mod tests {
225225
});
226226
}
227227

228-
#[test]
229-
fn test_add_transaction() {
228+
fn test_helper(test_name: &str, file_name: &str) {
230229
let mut handler = DiagnosticHandler::new();
231-
let trs = parse_file("tests/add_struct.prot", &mut handler);
232-
type_check(trs.unwrap(), &mut handler);
233-
234-
let content = strip_str(handler.error_string());
230+
let result = parser::parse_file(file_name, &mut handler);
231+
let content = match result {
232+
Ok(trs) => {
233+
type_check(trs, &mut handler);
234+
strip_str(handler.error_string())
235+
}
236+
Err(_) => strip_str(handler.error_string()),
237+
};
238+
snap(test_name, content);
239+
}
235240

236-
snap("add_struct", content);
241+
#[test]
242+
fn test_add_transaction() {
243+
test_helper("add_struct", "tests/add_struct.prot");
237244
}
238245

239246
#[test]
240247
fn test_invalid_step_arg_transaction() {
241-
let mut handler = DiagnosticHandler::new();
242-
let trs = parser::parse_file("tests/invalid_step_arg.prot", &mut handler);
243-
type_check(trs.unwrap(), &mut handler);
244-
245-
let content = strip_str(handler.error_string());
246-
247-
snap("invalid_step_arg", content);
248+
test_helper("invalid_step_arg", "tests/invalid_step_arg.prot");
248249
}
249250

250251
#[test]
251252
fn typecheck_aes128_transaction() {
252-
let mut handler = DiagnosticHandler::new();
253-
let trs = parser::parse_file("tests/aes128.prot", &mut handler);
254-
type_check(trs.unwrap(), &mut handler);
255-
let content = strip_str(handler.error_string());
256-
257-
snap("aes128", content);
253+
test_helper("aes128", "tests/aes128.prot");
258254
}
259255

260256
#[test]
261257
fn typecheck_aes128_expand_key_transaction() {
262-
let mut handler = DiagnosticHandler::new();
263-
let trs = parser::parse_file("tests/aes128_expand_key.prot", &mut handler);
264-
type_check(trs.unwrap(), &mut handler);
265-
let content = strip_str(handler.error_string());
266-
267-
snap("aes128_expand_key", content);
258+
test_helper("aes128_expand_key", "tests/aes128_expand_key.prot");
268259
}
269260

270261
#[test]
271262
fn typecheck_aes128_round_transaction() {
272-
let mut handler = DiagnosticHandler::new();
273-
let trs = parser::parse_file("tests/aes128_round.prot", &mut handler);
274-
type_check(trs.unwrap(), &mut handler);
275-
let content = strip_str(handler.error_string());
276-
277-
snap("aes128_round", content);
263+
test_helper("aes128_round", "tests/aes128_round.prot");
278264
}
279265

280266
#[test]
281267
fn typecheck_mul_transaction() {
282-
let mut handler = DiagnosticHandler::new();
283-
let trs = parser::parse_file("tests/mul.prot", &mut handler);
284-
type_check(trs.unwrap(), &mut handler);
285-
let content = strip_str(handler.error_string());
286-
287-
snap("mul", content);
268+
test_helper("mul", "tests/mul.prot");
288269
}
289270

290271
#[test]
291272
fn typecheck_cond_transaction() {
292-
let mut handler = DiagnosticHandler::new();
293-
let trs = parser::parse_file("tests/cond.prot", &mut handler);
294-
type_check(trs.unwrap(), &mut handler);
295-
let content = strip_str(handler.error_string());
296-
297-
snap("cond", content);
273+
test_helper("cond", "tests/cond.prot");
298274
}
299275

300276
#[test]
301277
fn test_calyx_go_done_transaction() {
302-
let mut handler = DiagnosticHandler::new();
303-
let trs = parse_file("tests/calyx_go_done_struct.prot", &mut handler);
304-
type_check(trs.unwrap(), &mut handler);
305-
306-
let content = strip_str(handler.error_string());
307-
308-
snap("calyx_go_done_struct", content);
278+
test_helper("calyx_go_done_struct", "tests/calyx_go_done_struct.prot");
309279
}
310280

311281
// Specific Tests

0 commit comments

Comments
 (0)