Skip wasm testing packages that do not have wasm tests (https://github.com/enso-org/ide/pull/1832)

Original commit: 3c17eb7f28
This commit is contained in:
Michał Wawrzyniec Urbańczyk 2021-09-09 23:51:56 +02:00 committed by GitHub
parent ade0e2b91e
commit 8bc81b4af2
2 changed files with 35 additions and 7 deletions

View File

@ -7,4 +7,5 @@ edition = "2018"
[workspace]
[dependencies]
glob = "0.3.0"
toml = "0.5.5"

View File

@ -10,6 +10,12 @@ const PACKAGE_BLACKLIST:[&str;2] = [
"ide/file-manager/mock-server"
];
/// Attributes that denote WASM tests.
const WASM_TEST_ATTRIBUTES:[&str;2] = ["#[wasm_bindgen_test]", "#[wasm_bindgen_test(async)]"];
/// Subdirectories in the crate directory that contain sources for the crate.
const SOURCE_SUBDIRECTORIES:[&str;4] = ["src", "benches", "examples", "tests"];
/// Lists members of given Cargo.toml workspace.
fn get_workspace_members(cargo_toml_root:toml::Value) -> Vec<String> {
let workspace = cargo_toml_root.get("workspace").expect("not a workspace");
@ -31,6 +37,27 @@ fn parse_toml(path:impl AsRef<Path>) -> toml::Value {
data.parse().unwrap()
}
/// Check if the given line of source code is an attribute denoting wasm test.
fn is_wasm_test_attribute(line:&str) -> bool {
WASM_TEST_ATTRIBUTES.contains(&line.trim())
}
/// Check if the given workspace member contains any wasm tests in the sources.
fn has_wasm_tests(member:&str) -> bool {
// We go over selected subdirectories only to avoid entering into sources of other crates that
// are nested within this crate subtree.
for subdir in SOURCE_SUBDIRECTORIES {
let pattern = format!("{}/{}/**/*.rs", member,subdir);
for entry in glob::glob(&pattern).unwrap() {
let contents = std::fs::read_to_string(entry.unwrap()).unwrap();
if contents.lines().any(is_wasm_test_attribute) {
return true
}
}
}
false
}
/// Checks if the given member is blacklisted from running the tests.
fn blacklisted(memeber:&str) -> bool {
PACKAGE_BLACKLIST.contains(&memeber)
@ -38,7 +65,7 @@ fn blacklisted(memeber:&str) -> bool {
/// Checks if for the given workspace member wasm-pack test should be run.
fn to_be_tested(member:&str) -> bool {
!blacklisted(member) && !is_proc_macro_crate(member)
has_wasm_tests(member) && !blacklisted(member) && !is_proc_macro_crate(member)
}
/// Checks if given workspace member is a proc-macro crate.
@ -64,13 +91,13 @@ fn main() {
let tested_members = all_members.iter().filter(|p| to_be_tested(&p));
for member in tested_members {
println!("Running tests for {}:", member);
let status = std::process::Command::new("wasm-pack")
.arg("test")
.arg(&member)
println!("Running tests for {}", member);
let mut command = std::process::Command::new("wasm-pack");
command.arg("test")
.args(&wasm_pack_args)
.status()
.unwrap();
.arg(&member);
println!("{:?}",command);
let status = command.status().unwrap();
if !status.success() {
panic!("Process for {} failed!{}", member, match status.code() {
Some(code) => format!(" Code: {}", code),