Skip to content

Commit

Permalink
simplify test path
Browse files Browse the repository at this point in the history
  • Loading branch information
MashPlant committed Sep 30, 2019
1 parent f000928 commit cf5fe9a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
1 change: 0 additions & 1 deletion driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ tac = { path = "../tac" }
tacgen = { path = "../tacgen" }
tacopt = { path = "../tacopt" }
codegen = { path = "../codegen" }
duct = "0.12.0"
typed-arena = "1.4.1"
tacvm = { git = "https://github.com/MashPlant/tacvm" }
colored = "1.8"
Expand Down
2 changes: 1 addition & 1 deletion driver/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use driver::*;

fn main() {
for result in test_all("testcase", "pa5", Pa::Pa5).unwrap() {
for result in test_all("testcase/S1", Pa::Pa1a).unwrap() {
println!("{:?}", result);
}
}
12 changes: 6 additions & 6 deletions driver/src/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ const SPIM_INFO_LINE: usize = 1;

// `folder` should be the path of folder containing `pa_path` and other tools
// `pa_path` should be relevant to `folder`, i.e., `folder`/`pa_path` is the real path to pa folder
pub fn test_all(folder: impl AsRef<Path>, pa_path: impl AsRef<Path>, pa: Pa) -> io::Result<Vec<TestResult>> {
pub fn test_all(path: impl AsRef<Path>, pa: Pa) -> io::Result<Vec<TestResult>> {
// make color work properly on windows(powershell)
// if it still doesn't work, or you simply dislike the color, add `colored::control::set_override(false);` before calling `test_all`
#[cfg(target_os = "windows")] let _ = control::set_virtual_terminal(true);

let folder = folder.as_ref().join(pa_path);
let ans = folder.join("result");
let out = folder.join("out");
let path = path.as_ref();
let ans = path.join("result");
let out = path.join("out");
if !out.exists() { fs::create_dir_all(&out)?; }

let mut files = fs::read_dir(&folder)?.filter_map(|f| {
let mut files = fs::read_dir(path)?.filter_map(|f| {
let path = f.ok()?.path();
let name = path.file_name()?.to_str()?; // in normal case none of the above 3 ? will fail
if path.is_file() && name.ends_with(".decaf") { Some(name.to_owned()) } else { None }
}).collect::<Vec<_>>();
files.sort_unstable(); // the order of fs::read_dir may be strange, sort them for better debugging
let ret = files.iter().map(|f| {
test_one_caught(folder.join(f), out.join(f).with_extension("result"), ans.join(f).with_extension("result"), pa)
test_one_caught(path.join(f), out.join(f).with_extension("result"), ans.join(f).with_extension("result"), pa)
}).collect();
Ok(ret)
}
Expand Down

0 comments on commit cf5fe9a

Please sign in to comment.