Skip to content

Commit

Permalink
Add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
neunenak committed Jan 8, 2023
1 parent 2cad61b commit 15f4d4d
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 7 deletions.
60 changes: 60 additions & 0 deletions tests/includes.rs
Original file line number Diff line number Diff line change
@@ -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();
}
1 change: 1 addition & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ mod fallback;
mod fmt;
mod functions;
mod ignore_comments;
mod includes;
mod init;
#[cfg(unix)]
mod interrupts;
Expand Down
19 changes: 12 additions & 7 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down

0 comments on commit 15f4d4d

Please sign in to comment.