forked from asdf-vm/asdf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion_commands.bats
More file actions
117 lines (89 loc) · 2.77 KB
/
Copy pathversion_commands.bats
File metadata and controls
117 lines (89 loc) · 2.77 KB
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
109
110
111
112
113
114
115
116
117
#!/usr/bin/env bats
. $(dirname $BATS_TEST_DIRNAME)/lib/utils.sh
. $(dirname $BATS_TEST_DIRNAME)/lib/commands/version_commands.sh
setup() {
BASE_DIR=$(mktemp -dt asdf.XXXX)
HOME=$BASE_DIR/home
ASDF_DIR=$HOME/.asdf
OTHER_DIR=$BASE_DIR/other
mkdir -p $ASDF_DIR/plugins/foo $ASDF_DIR/plugins/bar $ASDF_DIR/installs/foo/1.0.0 $ASDF_DIR/installs/foo/1.1.0 $ASDF_DIR/installs/foo/1.2.0 $ASDF_DIR/installs/bar/1.0.0 $OTHER_DIR
cd $OTHER_DIR
echo 'foo 1.0.0' >> $HOME/.tool-versions
echo 'foo 1.1.0' >> .tool-versions
}
teardown() {
rm -rf $BASE_DIR
}
@test "local should emit an error when run in lookup mode and file does not exist" {
rm .tool-versions
run local_command
[ "$status" -eq 1 ]
[ "$output" = ".tool-versions does not exist" ]
}
@test "global should emit an error when run in lookup mode and file does not exist" {
rm $HOME/.tool-versions
run global_command "foo"
[ "$status" -eq 1 ]
[ "$output" = "version not set for foo" ]
}
@test "local should emit an error when plugin does not exist" {
run local_command "inexistent" "1.0.0"
[ "$status" -eq 1 ]
[ "$output" = "No such plugin" ]
}
@test "local should emit an error when plugin version does not exist" {
run local_command "foo" "0.0.1"
[ "$status" -eq 1 ]
[ "$output" = "version 0.0.1 is not installed for foo" ]
}
@test "local should return and set the local version" {
run local_command
[ "$status" -eq 0 ]
[ "$output" = "foo 1.1.0" ]
run local_command foo "1.2.0"
run local_command foo
[ "$status" -eq 0 ]
[ "$output" = "1.2.0" ]
run local_command bar
[ "$status" -eq 1 ]
run local_command bar 1.0.0
[ "$status" -eq 0 ]
run local_command bar
[ "$status" -eq 0 ]
[ "$output" = "1.0.0" ]
rm .tool-versions
run local_command foo 1.2.0
[ -f .tool-versions ]
run local_command foo
[ "$status" -eq 0 ]
[ "$output" = "1.2.0" ]
run global_command foo
[ "$output" = "1.0.0" ]
}
@test "local should fallback to legacy-file when enabled" {
echo 'legacy_version_file = yes' > $HOME/.asdfrc
mkdir -p $ASDF_DIR/plugins/foo/bin
echo 'echo 1.0.0' > $ASDF_DIR/plugins/foo/bin/get-version-from-legacy-file
rm .tool-versions
run local_command foo
[ "$status" -eq 0 ]
[ "$output" = "1.0.0" ]
}
@test "local should ignore legacy-file when disabled" {
mkdir -p $ASDF_DIR/plugins/foo/bin
echo 'cat 1.0.0' > $ASDF_DIR/plugins/foo/bin/get-version-from-legacy-file
rm .tool-versions
run local_command foo
[ "$status" -eq 1 ]
[ "$output" = "version not set for foo" ]
}
@test "global should return and set the global version" {
run global_command
[ "$status" -eq 0 ]
[ "$output" = "foo 1.0.0" ]
run global_command foo 1.2.0
[ "$status" -eq 0 ]
run global_command foo
[ "$status" -eq 0 ]
[ "$output" = "1.2.0" ]
}