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
116 lines (94 loc) · 3.42 KB
/
Copy pathversion_commands.bats
File metadata and controls
116 lines (94 loc) · 3.42 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
#!/usr/bin/env bats
load test_helpers
. $(dirname $BATS_TEST_DIRNAME)/lib/commands/version_commands.sh
setup() {
setup_asdf_dir
install_dummy_plugin
install_dummy_version "1.0.0"
install_dummy_version "1.1.0"
PROJECT_DIR=$HOME/project
mkdir -p $PROJECT_DIR
cd $PROJECT_DIR
}
teardown() {
clean_asdf_dir
}
# Warn users who invoke the old style command without arguments.
@test "local should emit an error when called with incorrect arity" {
run local_command "dummy"
[ "$status" -eq 1 ]
[ "$output" = "Usage: asdf local <name> <version>" ]
}
@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 "dummy" "0.0.1"
[ "$status" -eq 1 ]
[ "$output" = "version 0.0.1 is not installed for dummy" ]
}
@test "local should create a local .tool-versions file if it doesn't exist" {
run local_command "dummy" "1.1.0"
[ "$status" -eq 0 ]
[ "$(cat $PROJECT_DIR/.tool-versions)" = "dummy 1.1.0" ]
}
@test "local should allow multiple versions" {
run local_command "dummy" "1.1.0" "1.0.0"
[ "$status" -eq 0 ]
[ "$(cat $PROJECT_DIR/.tool-versions)" = "dummy 1.1.0 1.0.0" ]
}
@test "local should create a local .tool-versions file if it doesn't exist when the directory name contains whitespace" {
WHITESPACE_DIR="$PROJECT_DIR/whitespace\ dir"
mkdir -p "$WHITESPACE_DIR"
cd "$WHITESPACE_DIR"
run local_command "dummy" "1.1.0"
tool_version_contents=$(cat "$WHITESPACE_DIR/.tool-versions")
[ "$status" -eq 0 ]
[ "$tool_version_contents" = "dummy 1.1.0" ]
}
@test "local should overwrite the existing version if it's set" {
echo 'dummy 1.0.0' >> $PROJECT_DIR/.tool-versions
run local_command "dummy" "1.1.0"
[ "$status" -eq 0 ]
[ "$(cat $PROJECT_DIR/.tool-versions)" = "dummy 1.1.0" ]
}
@test "local should fail to set a path:dir if dir does not exists " {
run local_command "dummy" "path:$PROJECT_DIR/local"
[ "$output" = "version path:$PROJECT_DIR/local is not installed for dummy" ]
[ "$status" -eq 1 ]
}
@test "local should set a path:dir if dir exists " {
mkdir -p $PROJECT_DIR/local
run local_command "dummy" "path:$PROJECT_DIR/local"
[ "$status" -eq 0 ]
[ "$(cat $PROJECT_DIR/.tool-versions)" = "dummy path:$PROJECT_DIR/local" ]
}
@test "global should create a global .tool-versions file if it doesn't exist" {
run global_command "dummy" "1.1.0"
[ "$status" -eq 0 ]
[ "$(cat $HOME/.tool-versions)" = "dummy 1.1.0" ]
}
@test "global should accept multiple versions" {
run global_command "dummy" "1.1.0" "1.0.0"
[ "$status" -eq 0 ]
[ "$(cat $HOME/.tool-versions)" = "dummy 1.1.0 1.0.0" ]
}
@test "global should overwrite the existing version if it's set" {
echo 'dummy 1.0.0' >> $HOME/.tool-versions
run global_command "dummy" "1.1.0"
[ "$status" -eq 0 ]
[ "$(cat $HOME/.tool-versions)" = "dummy 1.1.0" ]
}
@test "global should fail to set a path:dir if dir does not exists " {
run global_command "dummy" "path:$PROJECT_DIR/local"
[ "$output" = "version path:$PROJECT_DIR/local is not installed for dummy" ]
[ "$status" -eq 1 ]
}
@test "global should set a path:dir if dir exists " {
mkdir -p $PROJECT_DIR/local
run global_command "dummy" "path:$PROJECT_DIR/local"
[ "$status" -eq 0 ]
[ "$(cat $HOME/.tool-versions)" = "dummy path:$PROJECT_DIR/local" ]
}