From 15f4d4d14134f0e16522d5e01bcc32ce1de29a8f Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sun, 8 Jan 2023 00:20:12 -0800 Subject: [PATCH] Add integration tests --- tests/includes.rs | 60 +++++++++++++++++++++++++++++++++++++++++++++++ tests/lib.rs | 1 + tests/test.rs | 19 +++++++++------ 3 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 tests/includes.rs diff --git a/tests/includes.rs b/tests/includes.rs new file mode 100644 index 0000000000..291d8e9d65 --- /dev/null +++ b/tests/includes.rs @@ -0,0 +1,60 @@ +use super::*; +use temptree::temptree; + +#[test] +fn include_fails_without_unstable() { + let justfile_contents = r#" + # Include include.justfile + !include ./include.justfile + + recipe_a: recipe_b + echo "A" + "#; + + let include_justfile_contents = unindent( + r#" + recipe_b: + echo "B" + "#, + ); + + let tmp = temptree! { + "include.justfile": include_justfile_contents, + }; + + Test::with_tempdir(tmp) + .justfile(justfile_contents) + .status(EXIT_FAILURE) + .stderr("error: Expected character `=`\n |\n2 | !include ./include.justfile\n | ^\n") + .run(); +} + +#[test] +fn include_succeeds_with_unstable() { + let justfile_contents = r#" + # Include include.justfile + !include ./include.justfile + + recipe_a: recipe_b + @echo "A" + "#; + + let include_justfile_contents = unindent( + r#" + recipe_b: + @echo "B" + "#, + ); + + let tmp = temptree! { + "include.justfile": include_justfile_contents, + }; + + Test::with_tempdir(tmp) + .justfile(justfile_contents) + .arg("--unstable") + .arg("recipe_a") + .status(EXIT_SUCCESS) + .stdout("B\nA\n") + .run(); +} diff --git a/tests/lib.rs b/tests/lib.rs index ce24668825..6e7a8ae24e 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -51,6 +51,7 @@ mod fallback; mod fmt; mod functions; mod ignore_comments; +mod includes; mod init; #[cfg(unix)] mod interrupts; diff --git a/tests/test.rs b/tests/test.rs index 62bc0895bc..fe3d534d0a 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -165,6 +165,8 @@ impl Test { impl Test { pub(crate) fn run(self) -> TempDir { + let unstable = self.args.iter().any(|item| item.as_str() == "--unstable"); + if let Some(justfile) = &self.justfile { let justfile = unindent(justfile); fs::write(self.justfile_path(), justfile).unwrap(); @@ -246,7 +248,7 @@ impl Test { } if self.status == EXIT_SUCCESS { - test_round_trip(self.tempdir.path()); + test_round_trip(self.tempdir.path(), unstable); } self.tempdir @@ -260,14 +262,17 @@ struct Output<'a> { status: i32, } -fn test_round_trip(tmpdir: &Path) { +fn test_round_trip(tmpdir: &Path, unstable: bool) { println!("Reparsing..."); - let output = Command::new(executable_path("just")) - .current_dir(tmpdir) - .arg("--dump") - .output() - .expect("just invocation failed"); + let mut command = Command::new(executable_path("just")); + command.current_dir(tmpdir).arg("--dump"); + + if unstable { + command.arg("--unstable"); + } + + let output = command.output().expect("just invocation failed"); if !output.status.success() { panic!("dump failed: {}", output.status);