2017-03-15 20:57:15 -07:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load test_helpers
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
setup_asdf_dir
|
|
|
|
install_dummy_plugin
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf install dummy 1.0
|
2019-03-14 13:08:13 -07:00
|
|
|
run asdf install dummy 1.1
|
2017-03-15 20:57:15 -07:00
|
|
|
|
|
|
|
PROJECT_DIR="$HOME/project"
|
|
|
|
mkdir -p "$PROJECT_DIR"
|
2022-06-24 02:20:27 -07:00
|
|
|
echo 'dummy 1.0' >>"$PROJECT_DIR/.tool-versions"
|
2017-03-15 20:57:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
teardown() {
|
|
|
|
clean_asdf_dir
|
|
|
|
}
|
|
|
|
|
2018-10-20 20:47:13 -07:00
|
|
|
@test "which should show dummy 1.0 main binary" {
|
2017-03-15 20:57:15 -07:00
|
|
|
cd "$PROJECT_DIR"
|
|
|
|
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf which "dummy"
|
2017-03-15 20:57:15 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "$ASDF_DIR/installs/dummy/1.0/bin/dummy" ]
|
|
|
|
}
|
|
|
|
|
2019-01-20 13:02:22 -07:00
|
|
|
@test "which should fail for unknown binary" {
|
|
|
|
cd "$PROJECT_DIR"
|
|
|
|
|
|
|
|
run asdf which "sunny"
|
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
[ "$output" = "unknown command: sunny. Perhaps you have to reshim?" ]
|
|
|
|
}
|
|
|
|
|
2018-10-20 20:47:13 -07:00
|
|
|
@test "which should show dummy 1.0 other binary" {
|
2018-02-25 16:34:39 -07:00
|
|
|
cd "$PROJECT_DIR"
|
|
|
|
|
2022-06-24 02:20:27 -07:00
|
|
|
echo "echo bin bin/subdir" >"$ASDF_DIR/plugins/dummy/bin/list-bin-paths"
|
2019-01-20 13:02:22 -07:00
|
|
|
chmod +x "$ASDF_DIR/plugins/dummy/bin/list-bin-paths"
|
|
|
|
run asdf reshim dummy 1.0
|
|
|
|
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf which "other_bin"
|
2018-10-20 20:47:13 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "$ASDF_DIR/installs/dummy/1.0/bin/subdir/other_bin" ]
|
2018-02-25 16:34:39 -07:00
|
|
|
}
|
|
|
|
|
2019-01-20 13:02:22 -07:00
|
|
|
@test "which should show path of system version" {
|
2022-06-24 02:20:27 -07:00
|
|
|
echo 'dummy system' >"$PROJECT_DIR/.tool-versions"
|
2018-11-28 17:31:31 -07:00
|
|
|
cd "$PROJECT_DIR"
|
|
|
|
|
2019-01-20 13:02:22 -07:00
|
|
|
mkdir "$PROJECT_DIR/sys"
|
|
|
|
touch "$PROJECT_DIR/sys/dummy"
|
|
|
|
chmod +x "$PROJECT_DIR/sys/dummy"
|
|
|
|
|
|
|
|
run env "PATH=$PATH:$PROJECT_DIR/sys" asdf which "dummy"
|
2018-11-28 17:31:31 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2019-01-20 13:02:22 -07:00
|
|
|
[ "$output" = "$PROJECT_DIR/sys/dummy" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "which report when missing executable on system version" {
|
2022-06-24 02:20:27 -07:00
|
|
|
echo 'dummy system' >"$PROJECT_DIR/.tool-versions"
|
2019-01-20 13:02:22 -07:00
|
|
|
cd "$PROJECT_DIR"
|
|
|
|
|
|
|
|
run asdf which "dummy"
|
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
[ "$output" = "No dummy executable found for dummy system" ]
|
2018-11-28 17:31:31 -07:00
|
|
|
}
|
|
|
|
|
2018-10-20 20:47:13 -07:00
|
|
|
@test "which should inform when no binary is found" {
|
|
|
|
cd "$PROJECT_DIR"
|
|
|
|
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf which "bazbat"
|
2017-03-15 20:57:15 -07:00
|
|
|
[ "$status" -eq 1 ]
|
2019-01-20 13:02:22 -07:00
|
|
|
[ "$output" = "unknown command: bazbat. Perhaps you have to reshim?" ]
|
2017-03-15 20:57:15 -07:00
|
|
|
}
|
2019-01-05 08:54:02 -07:00
|
|
|
|
|
|
|
@test "which should use path returned by exec-path when present" {
|
|
|
|
cd "$PROJECT_DIR"
|
|
|
|
install_dummy_exec_path_script "dummy"
|
|
|
|
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf which "dummy"
|
2019-01-05 08:54:02 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "$ASDF_DIR/installs/dummy/1.0/bin/custom/dummy" ]
|
|
|
|
}
|
2019-03-14 13:08:13 -07:00
|
|
|
|
|
|
|
@test "which should return the path set by the legacy file" {
|
|
|
|
cd "$PROJECT_DIR"
|
|
|
|
|
2022-06-24 02:20:27 -07:00
|
|
|
echo 'dummy 1.0' >>"$HOME/.tool-versions"
|
|
|
|
echo '1.1' >>"$PROJECT_DIR/.dummy-version"
|
2019-03-14 13:08:13 -07:00
|
|
|
rm "$PROJECT_DIR/.tool-versions"
|
2022-06-24 02:20:27 -07:00
|
|
|
echo 'legacy_version_file = yes' >"$HOME/.asdfrc"
|
2019-03-14 13:08:13 -07:00
|
|
|
|
|
|
|
run asdf which "dummy"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "$ASDF_DIR/installs/dummy/1.1/bin/dummy" ]
|
|
|
|
}
|
2019-12-21 13:24:55 -07:00
|
|
|
|
|
|
|
@test "which should not return shim path" {
|
|
|
|
cd "$PROJECT_DIR"
|
2022-06-24 02:20:27 -07:00
|
|
|
echo 'dummy 1.0' >"$PROJECT_DIR/.tool-versions"
|
2019-12-21 13:24:55 -07:00
|
|
|
rm "$ASDF_DIR/installs/dummy/1.0/bin/dummy"
|
|
|
|
|
|
|
|
run env PATH="$PATH:$ASDF_DIR/shims" asdf which dummy
|
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
[ "$output" = "No dummy executable found for dummy 1.0" ]
|
|
|
|
}
|