Skip to content

Commit

Permalink
first draft of a unified cross-platform test flow with cargo test
Browse files Browse the repository at this point in the history
  • Loading branch information
dherman committed Oct 25, 2017
1 parent cfb212a commit c774e52
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 77 deletions.
7 changes: 1 addition & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ addons:
- g++-4.8

script: |
cd cli && npm install && npm run transpile && cd .. &&
cd test/cli && npm install && npm run transpile && npm test && cd ../.. &&
cd test/dynamic && npm install && npm test && cd ../.. &&
if [[ "$TRAVIS_RUST_VERSION" == nightly* ]]; then
cd test/static && cargo test && cd ../..
fi
cargo test --release
jobs:
include:
Expand Down
5 changes: 1 addition & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ install:
build: false

test_script:
- cd cli && npm install && npm run transpile && cd ..
- cd test/cli && npm install && npm run transpile && npm test && cd ../..
- cd test/dynamic && npm install && npm test && cd ../..
- if %RUST_TOOLCHAIN% == nightly-x86_64-pc-windows-msvc (cd test/static && cargo test --release && cd ../..)
- cargo test --release

cache:
- target
Expand Down
119 changes: 52 additions & 67 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,83 +275,68 @@ macro_rules! declare_types {
#[cfg(all(windows, not(neon_profile = "release")))]
compile_error!("Neon only builds with --release. For tests, try `cargo test --release`.");

#[cfg(test)]
use std::path::{Path, PathBuf};

#[cfg(test)]
fn project_root() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR")).to_path_buf()
}

#[cfg(all(windows, test))]
fn run(cmd: &str, dir: &Path) {
use std::process::Command;

assert!(Command::new("cmd")
.current_dir(dir)
.args(&["/C", cmd])
.status()
.expect("failed to execute test command")
.success());
}

#[cfg(all(not(windows), test))]
fn run(cmd: &str, dir: &Path) {
use std::process::Command;

assert!(Command::new("sh")
.current_dir(dir)
.args(&["-c", cmd])
.status()
.expect("failed to execute test command")
.success());
}

#[test]
fn cli_test() {
use std::process::Command;
if cfg!(target_os = "windows") {
assert!(Command::new("cmd")
.args(&["/C", "echo Implement this later"])
.status()
.expect("failed to execute process")
.success());
assert!(Command::new("cmd")
.args(&["/C", "echo Implement this later"])
.status()
.expect("failed to execute process")
.success());
} else {
assert!(Command::new("sh")
.arg("-c")
.arg("cd cli && npm install && npm run transpile")
.status()
.expect("failed to execute process")
.success());
assert!(Command::new("sh")
.arg("-c")
.arg("cd test/cli && npm install && npm run transpile && npm test")
.status()
.expect("failed to execute process")
.success());
};
let cli = project_root().join("cli");
run("npm install", &cli);
run("npm run transpile", &cli);

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 static_test() {
use rustc_version::{version_meta, Channel};
#[cfg(windows)]
use std::env;

if version_meta().unwrap().channel != Channel::Nightly { return };
use std::process::Command;
if cfg!(target_os = "windows") {
assert!(Command::new("cmd")
.args(&["/C", "echo Implement this later"])
.status()
.expect("failed to execute process")
.success());
} else {
assert!(Command::new("sh")
.arg("-c")
.arg("cd test/static && cargo test")
.status()
.expect("failed to execute process")
.success());
};

if version_meta().unwrap().channel != Channel::Nightly {
return;
}

run("cargo test --release", &project_root().join("test").join("static"));
}

#[test]
fn dynamic_test() {
use std::process::Command;
#[cfg(windows)]
use std::env;

if cfg!(target_os = "windows") {
assert!(Command::new("cmd")
.args(&["/C", "echo Implement this later"])
.status()
.expect("failed to execute process")
.success());
assert!(Command::new("cmd")
.args(&["/C", "echo Implement this later"])
.status()
.expect("failed to execute process")
.success());
} else {
assert!(Command::new("sh")
.arg("-c")
.arg("cd cli && npm install && cd ../test/dynamic && npm install && npm test")
.status()
.expect("failed to execute process")
.success());
}
run("npm install", &project_root().join("cli"));

let test_dynamic = project_root().join("test").join("dynamic");

run("npm install", &test_dynamic);
run("npm test", &test_dynamic);
}

0 comments on commit c774e52

Please sign in to comment.