forked from asdf-vm/asdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwhich_command.bats
108 lines (83 loc) · 2.67 KB
/
which_command.bats
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env bats
load test_helpers
setup() {
setup_asdf_dir
install_dummy_plugin
run asdf install dummy 1.0
run asdf install dummy 1.1
PROJECT_DIR="$HOME/project"
mkdir -p "$PROJECT_DIR"
echo 'dummy 1.0' >>"$PROJECT_DIR/.tool-versions"
}
teardown() {
clean_asdf_dir
}
@test "which should show dummy 1.0 main binary" {
cd "$PROJECT_DIR"
run asdf which "dummy"
[ "$status" -eq 0 ]
[ "$output" = "$ASDF_DIR/installs/dummy/1.0/bin/dummy" ]
}
@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?" ]
}
@test "which should show dummy 1.0 other binary" {
cd "$PROJECT_DIR"
echo "echo bin bin/subdir" >"$ASDF_DIR/plugins/dummy/bin/list-bin-paths"
chmod +x "$ASDF_DIR/plugins/dummy/bin/list-bin-paths"
run asdf reshim dummy 1.0
run asdf which "other_bin"
[ "$status" -eq 0 ]
[ "$output" = "$ASDF_DIR/installs/dummy/1.0/bin/subdir/other_bin" ]
}
@test "which should show path of system version" {
echo 'dummy system' >"$PROJECT_DIR/.tool-versions"
cd "$PROJECT_DIR"
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"
[ "$status" -eq 0 ]
[ "$output" = "$PROJECT_DIR/sys/dummy" ]
}
@test "which report when missing executable on system version" {
echo 'dummy system' >"$PROJECT_DIR/.tool-versions"
cd "$PROJECT_DIR"
run asdf which "dummy"
[ "$status" -eq 1 ]
[ "$output" = "No dummy executable found for dummy system" ]
}
@test "which should inform when no binary is found" {
cd "$PROJECT_DIR"
run asdf which "bazbat"
[ "$status" -eq 1 ]
[ "$output" = "unknown command: bazbat. Perhaps you have to reshim?" ]
}
@test "which should use path returned by exec-path when present" {
cd "$PROJECT_DIR"
install_dummy_exec_path_script "dummy"
run asdf which "dummy"
[ "$status" -eq 0 ]
[ "$output" = "$ASDF_DIR/installs/dummy/1.0/bin/custom/dummy" ]
}
@test "which should return the path set by the legacy file" {
cd "$PROJECT_DIR"
echo 'dummy 1.0' >>"$HOME/.tool-versions"
echo '1.1' >>"$PROJECT_DIR/.dummy-version"
rm "$PROJECT_DIR/.tool-versions"
echo 'legacy_version_file = yes' >"$HOME/.asdfrc"
run asdf which "dummy"
[ "$status" -eq 0 ]
[ "$output" = "$ASDF_DIR/installs/dummy/1.1/bin/dummy" ]
}
@test "which should not return shim path" {
cd "$PROJECT_DIR"
echo 'dummy 1.0' >"$PROJECT_DIR/.tool-versions"
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" ]
}