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,17 +3,20 @@
|
|||||||
//! 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.
|
||||||
|
|
||||||
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() {
|
fn main() {
|
||||||
build_and_generate_tests()
|
#[cfg(features = "test-programs")]
|
||||||
|
wasi_tests::build_and_generate_tests()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn 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 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
|
||||||
let bin_tests = std::fs::read_dir("wasi-tests/src/bin").unwrap();
|
let bin_tests = std::fs::read_dir("wasi-tests/src/bin").unwrap();
|
||||||
@@ -28,15 +31,16 @@ 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");
|
||||||
test_directory(&mut out, "wasi-tests", &out_dir).expect("generating tests");
|
test_directory(&mut out, "wasi-tests", &out_dir).expect("generating tests");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_tests(testsuite: &str, out_dir: &Path) -> io::Result<()> {
|
fn build_tests(testsuite: &str, out_dir: &Path) -> io::Result<()> {
|
||||||
let mut cmd = Command::new("cargo");
|
let mut cmd = Command::new("cargo");
|
||||||
cmd.args(&[
|
cmd.args(&[
|
||||||
"build",
|
"build",
|
||||||
@@ -59,9 +63,9 @@ fn build_tests(testsuite: &str, out_dir: &Path) -> io::Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_directory(out: &mut File, testsuite: &str, out_dir: &Path) -> io::Result<()> {
|
fn test_directory(out: &mut File, testsuite: &str, out_dir: &Path) -> io::Result<()> {
|
||||||
let mut dir_entries: Vec<_> = read_dir(out_dir.join("wasm32-wasi/release"))
|
let mut dir_entries: Vec<_> = read_dir(out_dir.join("wasm32-wasi/release"))
|
||||||
.expect("reading testsuite directory")
|
.expect("reading testsuite directory")
|
||||||
.map(|r| r.expect("reading testsuite directory entry"))
|
.map(|r| r.expect("reading testsuite directory entry"))
|
||||||
@@ -102,9 +106,13 @@ fn test_directory(out: &mut File, testsuite: &str, out_dir: &Path) -> io::Result
|
|||||||
}
|
}
|
||||||
writeln!(out, "}}")?;
|
writeln!(out, "}}")?;
|
||||||
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()
|
||||||
@@ -149,9 +157,9 @@ fn write_testsuite_tests(out: &mut File, dir_entry: DirEntry, testsuite: &str) -
|
|||||||
writeln!(out, " }}")?;
|
writeln!(out, " }}")?;
|
||||||
writeln!(out)?;
|
writeln!(out)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg_if::cfg_if! {
|
cfg_if::cfg_if! {
|
||||||
if #[cfg(not(windows))] {
|
if #[cfg(not(windows))] {
|
||||||
/// Ignore tests that aren't supported yet.
|
/// Ignore tests that aren't supported yet.
|
||||||
fn ignore(_testsuite: &str, _name: &str) -> bool {
|
fn ignore(_testsuite: &str, _name: &str) -> bool {
|
||||||
@@ -176,10 +184,10 @@ cfg_if::cfg_if! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mark tests which do not require preopens
|
/// Mark tests which do not require preopens
|
||||||
fn no_preopens(testsuite: &str, name: &str) -> bool {
|
fn no_preopens(testsuite: &str, name: &str) -> bool {
|
||||||
if testsuite == "wasi-tests" {
|
if testsuite == "wasi-tests" {
|
||||||
match name {
|
match name {
|
||||||
"big_random_buf" => true,
|
"big_random_buf" => true,
|
||||||
@@ -190,4 +198,5 @@ fn no_preopens(testsuite: &str, name: &str) -> bool {
|
|||||||
} else {
|
} else {
|
||||||
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