just 1.57.0

🤖 Just a command runner
Documentation
use super::*;

#[test]
fn fallback_from_subdir_bugfix() {
  Test::new()
    .justfile("")
    .write(
      "sub/justfile",
      "
        set fallback

        @default:
          echo foo
      ",
    )
    .args(["sub/default"])
    .stdout("foo\n")
    .success();
}

#[test]
fn fallback_from_subdir_message() {
  Test::new()
    .justfile("bar:\n echo bar")
    .write(
      "sub/justfile",
      "
        set fallback

        @foo:
          echo foo
      ",
    )
    .args(["sub/bar"])
    .stderr(path("echo bar\n"))
    .stdout("bar\n")
    .success();
}

#[test]
fn fallback_from_subdir_verbose_message() {
  Test::new()
    .justfile("bar:\n echo bar")
    .write(
      "sub/justfile",
      "
        set fallback

        @foo:
          echo foo
      ",
    )
    .args(["--verbose", "sub/bar"])
    .stderr(path(
      "
      Trying ../justfile
      ===> running recipe `bar`...
      echo bar
      ",
    ))
    .stdout("bar\n")
    .success();
}

#[test]
fn runs_recipe_in_parent_if_not_found_in_current() {
  Test::new()
    .write(
      "bar/justfile",
      "
        set fallback := true

        baz:
          echo subdir
      ",
    )
    .justfile(
      "
        foo:
          echo root
      ",
    )
    .args(["foo"])
    .current_dir("bar")
    .stderr(
      "
        echo root
      ",
    )
    .stdout("root\n")
    .success();
}

#[test]
fn setting_accepts_value() {
  Test::new()
    .write(
      "bar/justfile",
      "
        set fallback := true

        baz:
          echo subdir
      ",
    )
    .justfile(
      "
        foo:
          echo root
      ",
    )
    .args(["foo"])
    .current_dir("bar")
    .stderr(
      "
        echo root
      ",
    )
    .stdout("root\n")
    .success();
}

#[test]
fn print_error_from_parent_if_recipe_not_found_in_current() {
  Test::new()
    .write(
      "bar/justfile",
      "
        set fallback := true

        baz:
          echo subdir
      ",
    )
    .justfile("foo:\n echo {{bar}}")
    .args(["foo"])
    .current_dir("bar")
    .stderr(
      "
        error: variable `bar` not defined
         ——▶ justfile:2:9
          │
        2 │  echo {{bar}}
          │         ^^^
      ",
    )
    .failure();
}

#[test]
fn requires_setting() {
  Test::new()
    .write(
      "bar/justfile",
      "
        baz:
          echo subdir
      ",
    )
    .justfile(
      "
        foo:
          echo root
      ",
    )
    .args(["foo"])
    .current_dir("bar")
    .stderr("error: justfile does not contain recipe `foo`\n")
    .failure();
}

#[test]
fn works_with_provided_search_directory() {
  Test::new()
    .write(
      "bar/justfile",
      "
        set fallback := true

        baz:
          echo subdir
      ",
    )
    .justfile(
      "
        foo:
          echo root
      ",
    )
    .args(["./foo"])
    .stdout("root\n")
    .stderr(
      "
        echo root
      ",
    )
    .current_dir("bar")
    .success();
}

#[test]
fn doesnt_work_with_justfile() {
  Test::new()
    .write(
      "bar/justfile",
      "
        baz:
          echo subdir
      ",
    )
    .justfile(
      "
        foo:
          echo root
      ",
    )
    .args(["--justfile", "justfile", "foo"])
    .current_dir("bar")
    .stderr("error: justfile does not contain recipe `foo`\n")
    .failure();
}

#[test]
fn doesnt_work_with_justfile_and_working_directory() {
  Test::new()
    .write(
      "bar/justfile",
      "
        baz:
          echo subdir
      ",
    )
    .justfile(
      "
        foo:
          echo root
      ",
    )
    .args(["--justfile", "justfile", "--working-directory", ".", "foo"])
    .current_dir("bar")
    .stderr("error: justfile does not contain recipe `foo`\n")
    .failure();
}

#[test]
fn prints_correct_error_message_when_recipe_not_found() {
  Test::new()
    .write(
      "bar/justfile",
      "
        set fallback := true

        bar:
          echo subdir
      ",
    )
    .justfile(
      "
        bar:
          echo root
      ",
    )
    .args(["foo"])
    .current_dir("bar")
    .stderr(
      "
        error: justfile does not contain recipe `foo`
      ",
    )
    .failure();
}

#[test]
fn multiple_levels_of_fallback_work() {
  Test::new()
    .write(
      "a/b/justfile",
      "
        set fallback := true

        foo:
          echo subdir
      ",
    )
    .write(
      "a/justfile",
      "
        set fallback := true

        bar:
          echo subdir
      ",
    )
    .justfile(
      "
        baz:
          echo root
      ",
    )
    .args(["baz"])
    .current_dir("a/b")
    .stdout("root\n")
    .stderr(
      "
        echo root
      ",
    )
    .success();
}

#[test]
fn stop_fallback_when_fallback_is_false() {
  Test::new()
    .write(
      "a/b/justfile",
      "
        set fallback := true

        foo:
          echo subdir
      ",
    )
    .write(
      "a/justfile",
      "
        bar:
          echo subdir
      ",
    )
    .justfile(
      "
        baz:
          echo root
      ",
    )
    .args(["baz"])
    .current_dir("a/b")
    .stderr(
      "
        error: justfile does not contain recipe `baz`
        Did you mean `bar`?
      ",
    )
    .failure();
}

#[test]
fn works_with_modules() {
  Test::new()
    .write("bar/justfile", "set fallback := true")
    .write(
      "foo.just",
      "
        baz:
         @echo BAZ
      ",
    )
    .justfile("mod foo")
    .args(["foo::baz"])
    .current_dir("bar")
    .stdout("BAZ\n")
    .success();
}

#[test]
fn report_non_not_found_errors() {
  Test::new()
    .justfile(
      "
        bar:
          @echo bar
      ",
    )
    .write(".justfile", "bar:\n")
    .write("sub/justfile", "set fallback\n\nfoo:\n")
    .current_dir("sub")
    .arg("bar")
    .stderr_regex(
      r"error: multiple candidate justfiles found in `.*`: `\.justfile` and `justfile`\n",
    )
    .status(1);
}