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:
Jakub Konka
2019-11-19 13:00:55 +01:00
committed by Jakub Konka
parent 3cb238366d
commit a58709d99e
2 changed files with 172 additions and 162 deletions

View File

@@ -3,16 +3,19 @@
//! By generating a separate `#[test]` test for each file, we allow cargo test
//! 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::fs::{read_dir, DirEntry, File};
use std::io::{self, Write};
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
fn main() {
build_and_generate_tests()
}
fn build_and_generate_tests() {
// Validate if any of test sources are present and if they changed
// 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)
let out_dir =
PathBuf::from(env::var("OUT_DIR").expect("The OUT_DIR environment variable must be set"));
let out_dir = PathBuf::from(
env::var("OUT_DIR").expect("The OUT_DIR environment variable must be set"),
);
let mut out =
File::create(out_dir.join("wasi_tests.rs")).expect("error generating test source file");
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(())
}
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 stemstr = path
.file_stem()
@@ -191,3 +199,4 @@ fn no_preopens(testsuite: &str, name: &str) -> bool {
unreachable!()
}
}
}

View File

@@ -1,3 +1,4 @@
#![cfg(features = "test-programs")]
mod runtime;
mod utils;