Mercurial > python-compiler.rs
comparison src/tests/test_parse_files.rs @ 94:e0368bea06a6
Refactor tests a little bit so it's easier to add more.
author | Bastien Orivel <eijebong@bananium.fr> |
---|---|
date | Tue, 14 Jun 2016 18:39:48 +0200 |
parents | c06d12a81637 |
children |
comparison
equal
deleted
inserted
replaced
93:c06d12a81637 | 94:e0368bea06a6 |
---|---|
1 use ast_convert; | 1 use ast_convert; |
2 use ast_dump; | 2 use ast_dump; |
3 use python_tb; | 3 use python_tb; |
4 use python_parse; | 4 use python_parse; |
5 use std::io::Read; | 5 use tests::utils::read_file; |
6 use std::fs::File; | |
7 | 6 |
8 fn test_parse_file(filename: &str) { | 7 fn test_parse_file(filename: &str) { |
9 let code = { | 8 let code = read_file(filename); |
10 let mut file = match File::open(filename) { | |
11 Ok(file) => file, | |
12 Err(err) => { | |
13 panic!(format!("Can't find {}: {}", filename, err)); | |
14 } | |
15 }; | |
16 let mut code = String::new(); | |
17 file.read_to_string(&mut code).unwrap(); | |
18 code | |
19 }; | |
20 | |
21 let module = match python_parse::parse_ast(code.clone()) { | 9 let module = match python_parse::parse_ast(code.clone()) { |
22 Ok(module) => module, | 10 Ok(module) => module, |
23 Err(err) => { | 11 Err(err) => { |
24 python_tb::traceback(err); | 12 python_tb::traceback(err); |
25 panic!(format!("Error while parsing file “{}”:", filename)); | 13 panic!(format!("Error while parsing file “{}”:", filename)); |