forked from asdf-vm/asdf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_command.bats
More file actions
164 lines (129 loc) · 4.33 KB
/
Copy pathinstall_command.bats
File metadata and controls
164 lines (129 loc) · 4.33 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env bats
load test_helpers
setup() {
setup_asdf_dir
install_dummy_plugin
PROJECT_DIR=$HOME/project
mkdir $PROJECT_DIR
}
teardown() {
clean_asdf_dir
}
@test "install_command installs the correct version" {
run asdf install dummy 1.1
[ "$status" -eq 0 ]
[ $(cat $ASDF_DIR/installs/dummy/1.1/version) = "1.1" ]
}
@test "install_command installs even if the user is terrible and does not use newlines" {
cd $PROJECT_DIR
echo -n 'dummy 1.2' > ".tool-versions"
run asdf install
[ "$status" -eq 0 ]
[ $(cat $ASDF_DIR/installs/dummy/1.2/version) = "1.2" ]
}
@test "install_command set ASDF_CONCURRENCY" {
run asdf install dummy 1.0
[ "$status" -eq 0 ]
[ -f $ASDF_DIR/installs/dummy/1.0/env ]
run grep ASDF_CONCURRENCY $ASDF_DIR/installs/dummy/1.0/env
[ "$status" -eq 0 ]
}
@test "install_command should work in directory containing whitespace" {
WHITESPACE_DIR="$PROJECT_DIR/whitespace\ dir"
mkdir -p "$WHITESPACE_DIR"
cd "$WHITESPACE_DIR"
echo 'dummy 1.2' >> "$WHITESPACE_DIR/.tool-versions"
run asdf install
[ "$status" -eq 0 ]
[ $(cat $ASDF_DIR/installs/dummy/1.2/version) = "1.2" ]
}
@test "install_command should create a shim with asdf-plugin metadata" {
run asdf install dummy 1.0
[ "$status" -eq 0 ]
[ -f $ASDF_DIR/installs/dummy/1.0/env ]
run grep "asdf-plugin: dummy 1.0" $ASDF_DIR/shims/dummy
[ "$status" -eq 0 ]
}
@test "install_command on two versions should create a shim with asdf-plugin metadata" {
run asdf install dummy 1.1
[ "$status" -eq 0 ]
run grep "asdf-plugin: dummy 1.1" $ASDF_DIR/shims/dummy
[ "$status" -eq 0 ]
run grep "asdf-plugin: dummy 1.0" $ASDF_DIR/shims/dummy
[ "$status" -eq 1 ]
run asdf install dummy 1.0
[ "$status" -eq 0 ]
run grep "asdf-plugin: dummy 1.0" $ASDF_DIR/shims/dummy
[ "$status" -eq 0 ]
run grep "# asdf-plugin: dummy 1.0"$'\n'"# asdf-plugin: dummy 1.1" $ASDF_DIR/shims/dummy
[ "$status" -eq 0 ]
lines_count=$(grep "asdf-plugin: dummy 1.1" $ASDF_DIR/shims/dummy | wc -l)
[ "$lines_count" -eq "1" ]
}
@test "install_command should not generate shim for subdir" {
cd $PROJECT_DIR
echo 'dummy 1.0' > $PROJECT_DIR/.tool-versions
run asdf install
[ "$status" -eq 0 ]
[ -f "$ASDF_DIR/shims/dummy" ]
[ ! -f "$ASDF_DIR/shims/subdir" ]
}
@test "install_command generated shim should pass all arguments to executable" {
# asdf lib needed to run generated shims
cp -rf $BATS_TEST_DIRNAME/../{bin,lib} $ASDF_DIR/
cd $PROJECT_DIR
echo 'dummy 1.0' > $PROJECT_DIR/.tool-versions
run asdf install
# execute the generated shim
run $ASDF_DIR/shims/dummy world hello
[ "$status" -eq 0 ]
[ "$output" == "This is Dummy 1.0! hello world" ]
}
@test "install_command fails when the name or version are not specified" {
run asdf install dummy
[ "$status" -eq 1 ]
[ "$output" = "You must specify a name and a version to install" ]
[ ! -f $ASDF_DIR/installs/dummy/1.1/version ]
run asdf install 1.1
[ "$status" -eq 1 ]
[ "$output" = "You must specify a name and a version to install" ]
[ ! -f $ASDF_DIR/installs/dummy/1.1/version ]
}
@test "install_command uses a parent directory .tool-versions file if present" {
# asdf lib needed to run generated shims
cp -rf $BATS_TEST_DIRNAME/../{bin,lib} $ASDF_DIR/
echo 'dummy 1.0' > $PROJECT_DIR/.tool-versions
mkdir -p $PROJECT_DIR/child
cd $PROJECT_DIR/child
run asdf install
# execute the generated shim
[ "$($ASDF_DIR/shims/dummy world hello)" == "This is Dummy 1.0! hello world" ]
[ "$status" -eq 0 ]
}
@test "install_command doesn't install system version" {
run asdf install dummy system
[ "$status" -eq 0 ]
[ ! -f $ASDF_DIR/installs/dummy/system/version ]
}
@test "install command executes configured pre plugin install hook" {
cat > $HOME/.asdfrc <<-'EOM'
pre_asdf_install_dummy = echo will install dummy $1
EOM
run asdf install dummy 1.0
[ "$output" == "will install dummy 1.0" ]
}
@test "install command executes configured post plugin install hook" {
cat > $HOME/.asdfrc <<-'EOM'
post_asdf_install_dummy = echo HEY $version FROM $plugin_name
EOM
run asdf install dummy 1.0
[ "$output" == "HEY 1.0 FROM dummy" ]
}
@test "install_command skips comments in .tool-versions file" {
cd $PROJECT_DIR
echo -n '# dummy 1.2' > ".tool-versions"
run asdf install
[ "$status" -eq 0 ]
[ "$output" == "" ]
[ ! -f $ASDF_DIR/installs/dummy/1.2/version ]
}