From a1722fe241834bc53e95b8c5d382da91f23f76a4 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 28 Oct 2016 15:25:59 -0700 Subject: [PATCH] Add integration tests --- Cargo.lock | 17 +++++++++++++ Cargo.toml | 6 +++++ justfile | 9 +++++++ notes | 28 ++++++++++----------- src/integration.rs | 63 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 108 insertions(+), 15 deletions(-) create mode 100644 src/integration.rs diff --git a/Cargo.lock b/Cargo.lock index cf5ba01..09d5645 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,7 @@ name = "j" version = "0.2.4" dependencies = [ + "brev 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.16.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)", @@ -26,6 +27,15 @@ name = "bitflags" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "brev" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "clap" version = "2.16.2" @@ -41,6 +51,11 @@ dependencies = [ "vec_map 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "glob" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "kernel32-sys" version = "0.2.2" @@ -167,7 +182,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum aho-corasick 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ca972c2ea5f742bfce5687b9aef75506a764f61d37f8f649047846a9686ddb66" "checksum ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23ac7c30002a5accbf7e8987d0632fa6de155b7c3d39d0067317a391e00a2ef6" "checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" +"checksum brev 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "79571b60a8aa293f43b46370d8ba96fed28a5bee1303ea0e015d175ed0c63b40" "checksum clap 2.16.2 (registry+https://github.com/rust-lang/crates.io-index)" = "08aac7b078ec0a58e1d4b43cfb11d47001f8eb7c6f6f2bda4f5eed43c82491f1" +"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "49247ec2a285bb3dcb23cbd9c35193c025e7251bfce77c1d5da97e6362dffe7f" "checksum libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)" = "408014cace30ee0f767b1c4517980646a573ec61a57957aeeabcac8ac0a02e8d" diff --git a/Cargo.toml b/Cargo.toml index b2659ed..49441cd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,3 +12,9 @@ regex = "^0.1.77" clap = "^2.0.0" tempdir = "^0.3.5" lazy_static = "^0.2.1" +brev = "^0.1.6" + +[[test]] + +name = "integration" +path = "src/integration.rs" diff --git a/justfile b/justfile index f1db8df..023f69f 100644 --- a/justfile +++ b/justfile @@ -1,12 +1,21 @@ test: cargo test --lib +test-integration: build + cargo test --test integration + test-quine: cargo run -- quine clean +test-integ: + cargo run -- --justfile integration-tests/justfile --working-directory integration-tests + backtrace: RUST_BACKTRACE=1 cargo test --lib +build: + cargo build + publish: clippy # make sure version is up to date grep 'version("'`sed -En 's/version = "([^"]+)"/\1/p' Cargo.toml`'")' src/app.rs diff --git a/notes b/notes index 94a3bc3..83570b2 100644 --- a/notes +++ b/notes @@ -1,19 +1,16 @@ notes ----- -- get weird of that weird extra printing - - integration testing - . run app with command line options and test output + . --show should not display variable and expression values + . test --list + . test that status code of failing test is reported + . run app with command line options and test full output (stderr and stdout) . exercise all features and all command line options . test that first recipe runs by default . test that a few error messages are correct - -- underline problem token in error messages - -- add context to unexpected_token error - "while parsing a recipe" - "while parsing an expression" + . test full output + . underline problem token in error messages - figure out argument passing: . flag: j build --set a=hello @@ -31,7 +28,8 @@ notes - before release: - rewrite grammar.txt -- make it clear it's beta +- make it clear it's beta, mention that, as a command runner + there is probably a higher than normal chance of disaster - change name back to 'just', suggest j as alias - change description to "a polyglot command runner"? - update readme @@ -57,7 +55,7 @@ notes for contributing - vim and emacs syntax hilighting (use makefile syntax hilighting for now) - make sure there isn't any unused code -- ask users to contribute their justfiles +- ask users to contribute their justfiles as tests - try to get some users . facebook friends . irc @@ -65,13 +63,13 @@ notes enhancements: -- add post requirements: - # do c then a then b - a: c b~ +- save result of commands in variables +- iteration: {{x for x in y}} - allow calling recipes in a justfile in a different directory: . just ../foo # ../justfile:foo . just xyz/foo # xyz/justfile:foo . just xyz/ # xyz/justfile:DEFAULT - . get all directories, if more than one, fork just for each - allow setting and exporting environment variables - indentation or slash for line continuation +- figure out some way to allow changing directories in + plain recipes diff --git a/src/integration.rs b/src/integration.rs new file mode 100644 index 0000000..0675383 --- /dev/null +++ b/src/integration.rs @@ -0,0 +1,63 @@ +extern crate tempdir; +extern crate brev; + +use tempdir::TempDir; +use std::process::Command; + +fn integration_test( + name: &str, + args: &[&str], + justfile: &str, + expected_status: i32, + expected_stdout: &str, + expected_stderr: &str, +) { + let tmp = TempDir::new(name) + .unwrap_or_else(|err| panic!("tmpdir: failed to create temporary directory: {}", err)); + let mut path = tmp.path().to_path_buf(); + path.push("justfile"); + brev::dump(path, justfile); + let mut binary = std::env::current_dir().unwrap(); + binary.push("./target/debug/j"); + let output = Command::new(binary) + .current_dir(tmp.path()) + .args(args) + .output() + .expect("j invocation failed"); + + let mut failure = false; + + let status = output.status.code().unwrap(); + if status != expected_status { + println!("bad status: {} != {}", status, expected_status); + failure = true; + } + + let stdout = std::str::from_utf8(&output.stdout).unwrap(); + if stdout != expected_stdout { + println!("bad stdout: {:?} != {:?}", stdout, expected_stdout); + failure = true; + } + + let stderr = std::str::from_utf8(&output.stderr).unwrap(); + if stderr != expected_stderr { + println!("bad stderr: {:?} != {:?}", stderr, expected_stderr); + failure = true; + } + + if failure { + panic!("test failed"); + } +} + +#[test] +fn simple() { + integration_test( + "simple", + &[], + "default:\n echo hello", + 0, + "hello\n", + "echo hello\n", + ) +}