Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
build: ensure tests stay contained and self-clean
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwalker committed Oct 28, 2020
1 parent 0d43f9e commit 054d639
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 40 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/x86_64-apple-darwin-compiler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,7 @@ jobs:
args: |
test -- --package liblumen_otp lib:: -- --skip lumen::otp
- name: Run spawn-chain tests
working-directory: examples/spawn-chain/cli
run: make test
uses: actions-rs/cargo@v1
with:
command: make
args: test-spawn-chain
6 changes: 4 additions & 2 deletions .github/workflows/x86_64-unknown-linux-gnu-compiler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ jobs:
args: |
test -- --package liblumen_otp lib:: -- --skip lumen::otp
- name: Run spawn-chain tests
working-directory: examples/spawn-chain/cli
run: make test
uses: actions-rs/cargo@v1
with:
command: make
args: test-spawn-chain
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
!/.vscode/tasks.json
!/.vscode/launch.json
/.vscode/*
_build

*.beam
.#*
Expand Down
24 changes: 21 additions & 3 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ args = ["clean"]
[tasks.test]
category = "Test"
description = "Runs all tests"
dependencies = ["test-rust"]
dependencies = ["test-rust", "test-cleanup"]

[tasks.test-rust]
category = "Test"
Expand All @@ -260,6 +260,16 @@ dependencies = [
"lumen-tblgen",
]

[tasks.test-cleanup]
private = true
#condition = { env = { CARGO_MAKE_CI = "true" } }
script = ['''
#!@duckscript
rm -r ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/lumen/tests/_build
rm -r ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/native_implemented/otp/tests/_build
''']

[tasks.rebuild]
command = "cargo"
category = "Build"
Expand Down Expand Up @@ -522,14 +532,22 @@ condition = { files_not_exist = ["${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/exam
command = "git"
args = ["clone", "--depth", "1", "--branch", "develop", "https://github.com/lumen/examples", "examples"]

[tasks.spawn-chain]
[tasks.spawn-chain-web]
category = "Examples"
description = "Builds spawn-chain example program"
description = "Builds spawn-chain example program (wasm32)"
command = "wasm-pack"
args = ["build", "examples/spawn-chain/wasm"]
dependencies = ["checkout-interpreter", "checkout-examples", "lumen-tblgen"]

[tasks.test-spawn-chain]
category = "Examples"
description = "Tests spawn-chain example program (x86_64)"
cwd = "examples/spawn-chain/cli"
command = "make"
args = ["test"]
dependencies = ["checkout-interpreter", "checkout-examples", "lumen-tblgen"]

[tasks.test-spawn-chain-wasm]
category = "Test"
description = "Runs the spawn-chain example tests"
command = "wasm-pack"
Expand Down
13 changes: 7 additions & 6 deletions lumen/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ mod cli {
fn without_arguments_prints_nothing_to_say() {
ensure_compiled();

let cli_output = Command::new("./cli").stdin(Stdio::null()).output().unwrap();
let cli_output = Command::new("tests/_build/cli")
.stdin(Stdio::null())
.output()
.unwrap();

let stdout = String::from_utf8_lossy(&cli_output.stdout);
let stderr = String::from_utf8_lossy(&cli_output.stderr);
Expand All @@ -24,7 +27,7 @@ mod cli {
fn with_false_argument_prints_nothing_to_say() {
ensure_compiled();

let cli_output = Command::new("./cli")
let cli_output = Command::new("tests/_build/cli")
.arg("false")
.stdin(Stdio::null())
.output()
Expand All @@ -44,7 +47,7 @@ mod cli {
fn with_true_argument_prints_nothing_to_say() {
ensure_compiled();

let cli_output = Command::new("./cli")
let cli_output = Command::new("tests/_build/cli")
.arg("true")
.stdin(Stdio::null())
.output()
Expand Down Expand Up @@ -73,10 +76,8 @@ mod cli {

command
.arg("compile")
.arg("--output-dir")
.arg("_build")
.arg("--output")
.arg("cli")
.arg("tests/_build/cli")
// Turn off optimizations as work-around for debug info bug in EIR
.arg("-O0");

Expand Down
8 changes: 4 additions & 4 deletions lumen/tests/global_dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::sync::Once;
fn without_arguments_calls_global_dynamic_functions() {
ensure_compiled();

let cli_output = Command::new("./global_dynamic")
let cli_output = Command::new("tests/_build/global_dynamic")
.stdin(Stdio::null())
.output()
.unwrap();
Expand All @@ -31,14 +31,14 @@ fn ensure_compiled() {
}

fn compile() {
std::fs::create_dir_all("tests/_build").unwrap();

let mut command = Command::new("../bin/lumen");

command
.arg("compile")
.arg("--output-dir")
.arg("_build")
.arg("--output")
.arg("global_dynamic")
.arg("tests/_build/global_dynamic")
// Turn off optimizations as work-around for debug info bug in EIR
.arg("-O0");

Expand Down
8 changes: 4 additions & 4 deletions lumen/tests/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ mod hello_world {

#[test]
fn prints_hello_world() {
std::fs::create_dir_all("tests/_build").unwrap();

let mut command = Command::new("../bin/lumen");

command
.arg("compile")
.arg("--output-dir")
.arg("_build")
.arg("--output")
.arg("hello_world")
.arg("tests/_build/hello_world")
// Turn off optimizations as work-around for debug info bug in EIR
.arg("-O0");

Expand All @@ -27,7 +27,7 @@ mod hello_world {
String::from_utf8_lossy(&compile_output.stderr)
);

let hello_world_output = Command::new("./hello_world").output().unwrap();
let hello_world_output = Command::new("tests/_build/hello_world").output().unwrap();
let hello_world_stdout = String::from_utf8_lossy(&hello_world_output.stdout);
let hello_world_stderr = String::from_utf8_lossy(&hello_world_output.stderr);

Expand Down
33 changes: 14 additions & 19 deletions native_implemented/otp/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ fn compile<F>(file: &str, name: &str, compilation_mutator: F) -> Result<PathBuf,
where
F: FnOnce(Compilation),
{
let cwd = std::env::current_dir().unwrap();
let build_path = cwd.join("tests/_build");
let bin_path = build_path.join(name);

// `file!()` starts with path relative to workspace root, but the `current_dir` will be inside
// the crate root, so need to strip the relative crate root.
let file_path = Path::new(file);
Expand All @@ -167,35 +171,24 @@ where
let file_stem = file_path.file_stem().unwrap();
let test_directory_path = directory_path.join(file_stem).join(name);

let build_path_buf = test_directory_path.join("_build");

let mut command = Command::new("../../bin/lumen");

let bin_path_buf = test_directory_path.join("bin");
let output_path_buf = bin_path_buf.join(name);

command
.arg("compile")
.arg("--output-dir")
.arg(build_path_buf)
.arg("--output")
.arg(&output_path_buf)
// Turn off optimizations as work-around for debug info bug in EIR
.arg("-O0")
.arg("--emit=all");
.arg(&bin_path)
.arg("-O0");

if std::env::var_os("DEBUG").is_some() {
command.arg("--emit=all");
}

compilation_mutator(Compilation {
command: &mut command,
test_directory_path: &test_directory_path,
});

timeout(
"Compilation",
std::env::current_dir().unwrap(),
command,
Duration::from_secs(30),
)
.map(|_| output_path_buf)
timeout("Compilation", cwd, command, Duration::from_secs(30)).map(|_| bin_path)
}

pub fn timeout(
Expand Down Expand Up @@ -259,7 +252,7 @@ pub fn output(file: &str, name: &str) -> (Command, Output) {
},
);

let mut command = Command::new(bin_path_buf);
let mut command = Command::new(&bin_path_buf);

let process = command
.stdin(Stdio::null())
Expand All @@ -276,6 +269,8 @@ pub fn output(file: &str, name: &str) -> (Command, Output) {
.unwrap()
.unwrap();

std::fs::remove_file(&bin_path_buf).ok();

(command, output)
}

Expand Down

0 comments on commit 054d639

Please sign in to comment.