Skip to content

Commit

Permalink
1) tests grouped into a test module and 2) force sequential running of
Browse files Browse the repository at this point in the history
tests with a mutex
  • Loading branch information
dherman committed Oct 25, 2017
1 parent 04a6c4b commit 0a7c672
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ addons:
- g++-4.8

script: |
cargo test --release -- --test-threads 1
cargo test --release
jobs:
include:
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ neon-build = { version = "=0.1.20", path = "crates/neon-build" }

[dev-dependencies]
rustc_version = "0.2"
lazy_static = "0.2.8"

[dependencies]
cslice = "0.2"
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ install:
build: false

test_script:
- cargo test --release -- --test-threads 1
- cargo test --release

cache:
- target
Expand Down
105 changes: 60 additions & 45 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ extern crate semver;
#[cfg(test)]
extern crate rustc_version;

#[cfg(test)]
#[macro_use]
extern crate lazy_static;

pub mod mem;
pub mod vm;
pub mod scope;
Expand Down Expand Up @@ -276,61 +280,72 @@ macro_rules! declare_types {
compile_error!("Neon only builds with --release. For tests, try `cargo test --release`.");

#[cfg(test)]
use std::path::{Path, PathBuf};
mod tests {
use std::path::{Path, PathBuf};
use std::process::Command;
use std::sync::Mutex;

#[cfg(test)]
fn project_root() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR")).to_path_buf()
}
use rustc_version::{version_meta, Channel};

#[cfg(test)]
fn run(cmd: &str, dir: &Path) {
use std::process::Command;
// Create a mutex to enforce sequential running of the tests.
lazy_static! {
static ref TEST_MUTEX: Mutex<()> = Mutex::new(());
}

let (shell, command_flag) = if cfg!(windows) {
("cmd", "/C")
} else {
("sh", "-c")
};
fn project_root() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR")).to_path_buf()
}

assert!(Command::new(&shell)
.current_dir(dir)
.args(&[&command_flag, cmd])
.status()
.expect("failed to execute test command")
.success());
}
fn run(cmd: &str, dir: &Path) {
let (shell, command_flag) = if cfg!(windows) {
("cmd", "/C")
} else {
("sh", "-c")
};

#[test]
fn cli_test() {
let cli = project_root().join("cli");
run("npm install", &cli);
run("npm run transpile", &cli);
assert!(Command::new(&shell)
.current_dir(dir)
.args(&[&command_flag, cmd])
.status()
.expect("failed to execute test command")
.success());
}

let test_cli = project_root().join("test").join("cli");
run("npm install", &test_cli);
run("npm run transpile", &test_cli);
run("npm test", &test_cli);
}
#[test]
fn cli_test() {
let _guard = TEST_MUTEX.lock();

#[test]
fn static_test() {
use rustc_version::{version_meta, Channel};
let cli = project_root().join("cli");
run("npm install", &cli);
run("npm run transpile", &cli);

if version_meta().unwrap().channel != Channel::Nightly {
return;
let test_cli = project_root().join("test").join("cli");
run("npm install", &test_cli);
run("npm run transpile", &test_cli);
run("npm test", &test_cli);
}

run("cargo test --release", &project_root().join("test").join("static"));
}
#[test]
fn static_test() {
let _guard = TEST_MUTEX.lock();

#[test]
fn dynamic_test() {
let cli = project_root().join("cli");
run("npm install", &cli);
run("npm run transpile", &cli);
if version_meta().unwrap().channel != Channel::Nightly {
return;
}

let test_dynamic = project_root().join("test").join("dynamic");
run("npm install", &test_dynamic);
run("npm test", &test_dynamic);
run("cargo test --release", &project_root().join("test").join("static"));
}

#[test]
fn dynamic_test() {
let _guard = TEST_MUTEX.lock();

let cli = project_root().join("cli");
run("npm install", &cli);
run("npm run transpile", &cli);

let test_dynamic = project_root().join("test").join("dynamic");
run("npm install", &test_dynamic);
run("npm test", &test_dynamic);
}
}

0 comments on commit 0a7c672

Please sign in to comment.