mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 18:58:36 +00:00
Speed up compiler syntax tests
Use rayon to run the compiler syntax tests in parallel. On my machine that reduces the time from 11 seconds to 1.5 seconds.
This commit is contained in:
parent
d2fdd161e9
commit
3498ccbc91
2 changed files with 19 additions and 2 deletions
|
@ -71,3 +71,4 @@ i-slint-parser-test-macro = { path = "./parser-test-macro" }
|
|||
|
||||
regex = "1.3.7"
|
||||
spin_on = "0.1"
|
||||
rayon = "1.5.3"
|
||||
|
|
|
@ -19,6 +19,8 @@ use std::path::{Path, PathBuf};
|
|||
|
||||
#[test]
|
||||
fn syntax_tests() -> std::io::Result<()> {
|
||||
use rayon::prelude::*;
|
||||
|
||||
if let Some(specific_test) = std::env::args()
|
||||
.skip(1)
|
||||
.skip_while(|arg| arg.starts_with("--") || arg == "syntax_tests")
|
||||
|
@ -30,7 +32,8 @@ fn syntax_tests() -> std::io::Result<()> {
|
|||
assert!(process_file(&path)?);
|
||||
return Ok(());
|
||||
}
|
||||
let mut success = true;
|
||||
|
||||
let mut test_entries = Vec::new();
|
||||
for entry in std::fs::read_dir(format!("{}/tests/syntax", env!("CARGO_MANIFEST_DIR")))? {
|
||||
let entry = entry?;
|
||||
let path = entry.path();
|
||||
|
@ -40,13 +43,26 @@ fn syntax_tests() -> std::io::Result<()> {
|
|||
let path = test_entry.path();
|
||||
if let Some(ext) = path.extension() {
|
||||
if ext == "60" || ext == "slint" {
|
||||
success &= process_file(&path)?;
|
||||
test_entries.push(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let success = test_entries
|
||||
.par_iter()
|
||||
.try_fold(
|
||||
|| true,
|
||||
|mut success, path| {
|
||||
success &= process_file(&path)?;
|
||||
Ok::<bool, std::io::Error>(success)
|
||||
},
|
||||
)
|
||||
.try_reduce(|| true, |success, result| Ok(success & result))?;
|
||||
|
||||
assert!(success);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue