From 383754d2fb186de3948c11f276dbb8b3d44a6980 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 28 Oct 2016 19:38:03 -0700 Subject: [PATCH] More tests --- Cargo.toml | 5 ----- justfile | 10 ++-------- notes | 3 --- src/integration.rs | 35 +++++++++++++++++++++++++++++------ src/lib.rs | 5 ++++- src/{tests.rs => unit.rs} | 0 6 files changed, 35 insertions(+), 23 deletions(-) rename src/{tests.rs => unit.rs} (100%) diff --git a/Cargo.toml b/Cargo.toml index 49441cd..e53e0b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,8 +13,3 @@ 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 f23a44f..d16fcec 100644 --- a/justfile +++ b/justfile @@ -1,12 +1,6 @@ -test-all: test test-integration - test: cargo test --lib -test-integration: build - cargo test --test integration - - test-quine: cargo run -- quine clean @@ -46,12 +40,12 @@ quine: create diff tmp/gen1.c tmp/gen2.c @echo 'It was a quine!' -quine-text = "'int printf(const char*, ...); int main() { char *s = \"int printf(const char*, ...); int main() { char *s = %c%s%c; printf(s, 34, s, 34); return 0; }\"; printf(s, 34, s, 34); return 0; }'" +quine-text = "int printf(const char*, ...); int main() { char *s = \"int printf(const char*, ...); int main() { char *s = %c%s%c; printf(s, 34, s, 34); return 0; }\"; printf(s, 34, s, 34); return 0; }" # create our quine create: mkdir -p tmp - echo {{quine-text}} > tmp/gen0.c + echo '{{quine-text}}' > tmp/gen0.c # clean up clean: diff --git a/notes b/notes index fc113b8..f2213f7 100644 --- a/notes +++ b/notes @@ -2,9 +2,6 @@ notes ----- - integration testing - . get value of variable --evaluate --variable - . run app with command line options and test full output (stderr and stdout) - . exercise all features and all command line options . underline problem token in error messages - figure out argument passing: diff --git a/src/integration.rs b/src/integration.rs index 16a0aa3..316e6ce 100644 --- a/src/integration.rs +++ b/src/integration.rs @@ -2,7 +2,7 @@ extern crate tempdir; extern crate brev; use tempdir::TempDir; -use std::process::Command; +use super::std::process::Command; fn integration_test( name: &str, @@ -17,7 +17,7 @@ fn integration_test( let mut path = tmp.path().to_path_buf(); path.push("justfile"); brev::dump(path, justfile); - let mut binary = std::env::current_dir().unwrap(); + let mut binary = super::std::env::current_dir().unwrap(); binary.push("./target/debug/j"); let output = Command::new(binary) .current_dir(tmp.path()) @@ -33,15 +33,15 @@ fn integration_test( failure = true; } - let stdout = std::str::from_utf8(&output.stdout).unwrap(); + let stdout = super::std::str::from_utf8(&output.stdout).unwrap(); if stdout != expected_stdout { - println!("bad stdout: {:?} != {:?}", stdout, expected_stdout); + println!("bad stdout:\ngot:\n{}\n\nexpected:\n{}", stdout, expected_stdout); failure = true; } - let stderr = std::str::from_utf8(&output.stderr).unwrap(); + let stderr = super::std::str::from_utf8(&output.stderr).unwrap(); if stderr != expected_stderr { - println!("bad stderr: {:?} != {:?}", stderr, expected_stderr); + println!("bad stdout:\ngot:\n{}\n\nexpected:\n{}", stderr, expected_stderr); failure = true; } @@ -160,6 +160,29 @@ recipe: ); } +#[test] +fn debug() { + let text = +r#"hello = "foo" +bar = hello + hello +recipe: + echo {{hello + "bar" + bar}}"#; + integration_test( + "debug", + &["--debug"], + text, + 0, + r#"bar = hello + hello # "foofoo" + +hello = "foo" # "foo" + +recipe: + echo {{hello + "bar" + bar # "foobarfoofoo"}} +"#, + "", + ); +} + #[test] fn status() { let text = diff --git a/src/lib.rs b/src/lib.rs index 3ef5b04..da6bcfa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,8 @@ #[cfg(test)] -mod tests; +mod unit; + +#[cfg(test)] +mod integration; mod app; diff --git a/src/tests.rs b/src/unit.rs similarity index 100% rename from src/tests.rs rename to src/unit.rs