Feature-gate test-programs
This commit feature-gates `test-programs` as a workaround for `cargo test` not allowing for optional dev-dependencies. This commit addresses #595.
This commit is contained in:
@@ -3,16 +3,19 @@
|
|||||||
//! By generating a separate `#[test]` test for each file, we allow cargo test
|
//! By generating a separate `#[test]` test for each file, we allow cargo test
|
||||||
//! to automatically run the files in parallel.
|
//! to automatically run the files in parallel.
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
#[cfg(features = "test-programs")]
|
||||||
|
wasi_tests::build_and_generate_tests()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(features = "test-programs")]
|
||||||
|
mod wasi_tests {
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs::{read_dir, DirEntry, File};
|
use std::fs::{read_dir, DirEntry, File};
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::{Command, Stdio};
|
use std::process::{Command, Stdio};
|
||||||
|
|
||||||
fn main() {
|
|
||||||
build_and_generate_tests()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn build_and_generate_tests() {
|
fn build_and_generate_tests() {
|
||||||
// Validate if any of test sources are present and if they changed
|
// Validate if any of test sources are present and if they changed
|
||||||
// This should always work since there is no submodule to init anymore
|
// This should always work since there is no submodule to init anymore
|
||||||
@@ -28,8 +31,9 @@ fn build_and_generate_tests() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Build tests to OUT_DIR (target/*/build/wasi-common-*/out/wasm32-wasi/release/*.wasm)
|
// Build tests to OUT_DIR (target/*/build/wasi-common-*/out/wasm32-wasi/release/*.wasm)
|
||||||
let out_dir =
|
let out_dir = PathBuf::from(
|
||||||
PathBuf::from(env::var("OUT_DIR").expect("The OUT_DIR environment variable must be set"));
|
env::var("OUT_DIR").expect("The OUT_DIR environment variable must be set"),
|
||||||
|
);
|
||||||
let mut out =
|
let mut out =
|
||||||
File::create(out_dir.join("wasi_tests.rs")).expect("error generating test source file");
|
File::create(out_dir.join("wasi_tests.rs")).expect("error generating test source file");
|
||||||
build_tests("wasi-tests", &out_dir).expect("building tests");
|
build_tests("wasi-tests", &out_dir).expect("building tests");
|
||||||
@@ -104,7 +108,11 @@ fn test_directory(out: &mut File, testsuite: &str, out_dir: &Path) -> io::Result
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_testsuite_tests(out: &mut File, dir_entry: DirEntry, testsuite: &str) -> io::Result<()> {
|
fn write_testsuite_tests(
|
||||||
|
out: &mut File,
|
||||||
|
dir_entry: DirEntry,
|
||||||
|
testsuite: &str,
|
||||||
|
) -> io::Result<()> {
|
||||||
let path = dir_entry.path();
|
let path = dir_entry.path();
|
||||||
let stemstr = path
|
let stemstr = path
|
||||||
.file_stem()
|
.file_stem()
|
||||||
@@ -191,3 +199,4 @@ fn no_preopens(testsuite: &str, name: &str) -> bool {
|
|||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#![cfg(features = "test-programs")]
|
||||||
mod runtime;
|
mod runtime;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user