@@ -25,18 +25,23 @@ GO_CORE_URL="${GO_CORE_URL:-$_GO_CORE_DIR}"
25
25
setup () {
26
26
test_filter
27
27
export GO_SCRIPT_BASH_VERSION=" $_GO_CORE_VERSION "
28
- export GO_SCRIPTS_DIR=" $_GO_TEST_DIR /tmp/go-template-test-scripts"
29
28
export GO_SCRIPT_BASH_REPO_URL=" https://github.com/mbland/go-script-bash.git"
30
29
export GO_SCRIPT_BASH_DOWNLOAD_URL=" ${GO_SCRIPT_BASH_REPO_URL% .git} /archive"
30
+
31
+ # Set up the template to run from `TEST_GO_ROOTDIR`. Add a dummy script to
32
+ # ensure it doesn't return nonzero due to no scripts being present. This will
33
+ # also create `TEST_GO_ROOTDIR` and `TEST_GO_ROOTDIR/scripts`.
34
+ @go.create_test_command_script ' foo' ' printf "%s\n" "Hello, World!"'
35
+ cp " $_GO_CORE_DIR /go-template" " $TEST_GO_ROOTDIR "
31
36
}
32
37
33
38
teardown () {
34
- rm -rf " $_GO_ROOTDIR / $GO_SCRIPTS_DIR "
39
+ @go.remove_test_go_rootdir
35
40
}
36
41
37
42
assert_go_core_unpacked () {
38
43
set " $DISABLE_BATS_SHELL_OPTIONS "
39
- local go_core=" $_GO_ROOTDIR / $GO_SCRIPTS_DIR /go-script-bash/go-core.bash"
44
+ local go_core=" $TEST_GO_SCRIPTS_DIR /go-script-bash/go-core.bash"
40
45
local result=' 0'
41
46
42
47
if [[ ! -f " $go_core " ]]; then
@@ -47,31 +52,29 @@ assert_go_core_unpacked() {
47
52
}
48
53
49
54
@test " $SUITE : successfully run 'help' from its own directory" {
50
- GO_SCRIPT_BASH_CORE_DIR=" $_GO_CORE_DIR " GO_SCRIPTS_DIR=' scripts' \
51
- run " $_GO_CORE_DIR /go-template" ' help'
55
+ # Use `_GO_CORE_DIR` to avoid the download attempt in this test.
56
+ GO_SCRIPT_BASH_CORE_DIR=" $_GO_CORE_DIR " \
57
+ run " $TEST_GO_ROOTDIR /go-template" ' help'
52
58
assert_success
53
- assert_output_matches " Usage: $_GO_CORE_DIR /go-template <command>"
59
+ assert_output_matches " Usage: $TEST_GO_ROOTDIR /go-template <command>"
54
60
}
55
61
56
62
@test " $SUITE : download the go-script-bash release from $GO_SCRIPT_BASH_REPO_URL " {
57
- run " $_GO_CORE_DIR /go-template"
63
+ run " $TEST_GO_ROOTDIR /go-template"
58
64
59
65
# Without a command argument, the script will print the top-level help and
60
66
# return an error, but the core repo should exist as expected.
61
67
assert_failure
62
68
assert_output_matches " Downloading framework from '${GO_SCRIPT_BASH_REPO_URL% .git} .*.tar.gz'\.\.\."
63
-
64
- # Use `.*/scripts/go-script-bash` to account for the fact that `git clone` on
65
- # MSYS2 will output `C:/Users/<user>/AppData/Local/Temp/` in place of `/tmp`.
66
69
assert_output_matches " Download of '${GO_SCRIPT_BASH_REPO_URL% .git} .*.tar.gz' successful."
67
- assert_output_matches " Usage: $_GO_CORE_DIR /go-template <command>"
70
+ assert_output_matches " Usage: $TEST_GO_ROOTDIR /go-template <command>"
68
71
assert_go_core_unpacked
69
72
}
70
73
71
74
@test " $SUITE : fail to download a nonexistent repo" {
72
75
GO_SCRIPT_BASH_REPO_URL=' bogus-repo-that-does-not-exist' \
73
76
GO_SCRIPT_BASH_DOWNLOAD_URL=' bogus-url-that-does-not-exist' \
74
- run " $_GO_CORE_DIR /go-template"
77
+ run " $TEST_GO_ROOTDIR /go-template"
75
78
assert_failure " Downloading framework from 'bogus-url-that-does-not-exist/$GO_SCRIPT_BASH_VERSION .tar.gz'..." \
76
79
" curl: (6) Could not resolve host: bogus-url-that-does-not-exist" \
77
80
" Failed to download from 'bogus-url-that-does-not-exist/$GO_SCRIPT_BASH_VERSION .tar.gz'." \
@@ -83,13 +86,13 @@ assert_go_core_unpacked() {
83
86
84
87
@test " $SUITE : fail to download a nonexistent version" {
85
88
GO_SCRIPT_BASH_VERSION=' vnonexistent' \
86
- run " $_GO_CORE_DIR /go-template"
89
+ run " $TEST_GO_ROOTDIR /go-template"
87
90
assert_failure " Downloading framework from 'https://github.com/mbland/go-script-bash/archive/vnonexistent.tar.gz'..." \
88
91
" curl: (22) The requested URL returned error: 404 Not Found" \
89
92
" Failed to download from 'https://github.com/mbland/go-script-bash/archive/vnonexistent.tar.gz'." \
90
93
" Using git clone as fallback" \
91
94
" Cloning framework from 'https://github.com/mbland/go-script-bash.git'..." \
92
- " Cloning into '$PWD / $GO_SCRIPTS_DIR /go-script-bash'..." \
95
+ " Cloning into '$TEST_GO_SCRIPTS_DIR /go-script-bash'..." \
93
96
" warning: Could not find remote branch vnonexistent to clone." \
94
97
" fatal: Remote branch vnonexistent not found in upstream origin" \
95
98
" Failed to clone 'https://github.com/mbland/go-script-bash.git'; aborting."
@@ -98,23 +101,20 @@ assert_go_core_unpacked() {
98
101
@test " $SUITE : fail to find curl uses git clone" {
99
102
PATH=" $BATS_TEST_BINDIR :$PATH "
100
103
stub_program_in_path curl " exit 1"
101
- run " $_GO_CORE_DIR /go-template"
104
+ run " $TEST_GO_ROOTDIR /go-template"
102
105
restore_program_in_path curl
103
106
104
107
# Without a command argument, the script will print the top-level help and
105
108
# return an error, but the core repo should exist as expected.
106
109
assert_output_matches " Failed to find cURL or tar"
107
110
assert_output_matches " Using git clone as fallback"
108
- assert_output_matches " Cloning framework from '$GO_SCRIPT_BASH_REPO_URL '\.\.\."
109
-
110
- # Use `.*/scripts/go-script-bash` to account for the fact that `git clone` on
111
- # MSYS2 will output `C:/Users/<user>/AppData/Local/Temp/` in place of `/tmp`.
112
- assert_output_matches " Cloning into '.*/$GO_SCRIPTS_DIR /go-script-bash'\.\.\."
111
+ assert_output_matches " Cloning framework from '$GO_SCRIPT_BASH_REPO_URL '"
112
+ assert_output_matches " Cloning into '$TEST_GO_SCRIPTS_DIR /go-script-bash'"
113
113
assert_output_matches " Clone of '$GO_SCRIPT_BASH_REPO_URL ' successful\." $' \n\n '
114
- assert_output_matches " Usage: $_GO_CORE_DIR /go-template <command>"
114
+ assert_output_matches " Usage: $TEST_GO_ROOTDIR /go-template <command>"
115
115
assert_go_core_unpacked
116
116
117
- cd " $_GO_ROOTDIR / $GO_SCRIPTS_DIR /go-script-bash"
117
+ cd " $TEST_GO_SCRIPTS_DIR /go-script-bash"
118
118
run git log --oneline -n 1
119
119
assert_success
120
120
assert_output_matches " go-script-bash $_GO_CORE_VERSION "
@@ -123,23 +123,20 @@ assert_go_core_unpacked() {
123
123
@test " $SUITE : fail to find tar uses git clone" {
124
124
PATH=" $BATS_TEST_BINDIR :$PATH "
125
125
stub_program_in_path tar " exit 1"
126
- run " $_GO_CORE_DIR /go-template"
126
+ run " $TEST_GO_ROOTDIR /go-template"
127
127
restore_program_in_path tar
128
128
129
129
# Without a command argument, the script will print the top-level help and
130
130
# return an error, but the core repo should exist as expected.
131
131
assert_output_matches " Failed to find cURL or tar"
132
132
assert_output_matches " Using git clone as fallback"
133
- assert_output_matches " Cloning framework from '$GO_SCRIPT_BASH_REPO_URL '\.\.\."
134
-
135
- # Use `.*/scripts/go-script-bash` to account for the fact that `git clone` on
136
- # MSYS2 will output `C:/Users/<user>/AppData/Local/Temp/` in place of `/tmp`.
137
- assert_output_matches " Cloning into '.*/$GO_SCRIPTS_DIR /go-script-bash'\.\.\."
133
+ assert_output_matches " Cloning framework from '$GO_SCRIPT_BASH_REPO_URL '"
134
+ assert_output_matches " Cloning into '$TEST_GO_SCRIPTS_DIR /go-script-bash'"
138
135
assert_output_matches " Clone of '$GO_SCRIPT_BASH_REPO_URL ' successful\." $' \n\n '
139
- assert_output_matches " Usage: $_GO_CORE_DIR /go-template <command>"
136
+ assert_output_matches " Usage: $TEST_GO_ROOTDIR /go-template <command>"
140
137
assert_go_core_unpacked
141
138
142
- cd " $_GO_ROOTDIR / $GO_SCRIPTS_DIR /go-script-bash"
139
+ cd " $TEST_GO_SCRIPTS_DIR /go-script-bash"
143
140
run git log --oneline -n 1
144
141
assert_success
145
142
assert_output_matches " go-script-bash $_GO_CORE_VERSION "
@@ -148,24 +145,26 @@ assert_go_core_unpacked() {
148
145
@test " $SUITE : fail to create directory uses git clone" {
149
146
PATH=" $BATS_TEST_BINDIR :$PATH "
150
147
stub_program_in_path mkdir " exit 1"
151
- run " $_GO_CORE_DIR /go-template"
148
+ run " $TEST_GO_ROOTDIR /go-template"
152
149
restore_program_in_path mkdir
153
150
154
151
# Without a command argument, the script will print the top-level help and
155
152
# return an error, but the core repo should exist as expected.
156
153
assert_output_matches " Downloading framework from '${GO_SCRIPT_BASH_REPO_URL% .git} .*.tar.gz'\.\.\."
157
- assert_output_matches " Failed to create scripts dir '$GO_SCRIPTS_DIR '"
158
- assert_output_matches " Using git clone as fallback"
159
- assert_output_matches " Cloning framework from '$GO_SCRIPT_BASH_REPO_URL '\.\.\."
160
154
161
- # Use `.*/scripts/go-script-bash` to account for the fact that `git clone` on
162
- # MSYS2 will output `C:/Users/<user>/AppData/Local/Temp/` in place of `/tmp`.
163
- assert_output_matches " Cloning into '.*/$GO_SCRIPTS_DIR /go-script-bash'\.\.\."
155
+ # Note that the go-template defines `GO_SCRIPTS_DIR`, but the framework's own
156
+ # `go` script doesn't. Hence, we use `TEST_GO_SCRIPTS_RELATIVE_DIR` below,
157
+ # which should always match the default `GO_SCRIPTS_DIR` in the template.
158
+ assert_output_matches \
159
+ " Failed to create scripts dir '$TEST_GO_SCRIPTS_RELATIVE_DIR '"
160
+ assert_output_matches " Using git clone as fallback"
161
+ assert_output_matches " Cloning framework from '$GO_SCRIPT_BASH_REPO_URL '"
162
+ assert_output_matches " Cloning into '$TEST_GO_SCRIPTS_DIR /go-script-bash'."
164
163
assert_output_matches " Clone of '$GO_SCRIPT_BASH_REPO_URL ' successful\." $' \n\n '
165
- assert_output_matches " Usage: $_GO_CORE_DIR /go-template <command>"
164
+ assert_output_matches " Usage: $TEST_GO_ROOTDIR /go-template <command>"
166
165
assert_go_core_unpacked
167
166
168
- cd " $_GO_ROOTDIR / $GO_SCRIPTS_DIR /go-script-bash"
167
+ cd " $TEST_GO_SCRIPTS_DIR /go-script-bash"
169
168
run git log --oneline -n 1
170
169
assert_success
171
170
assert_output_matches " go-script-bash $_GO_CORE_VERSION "
@@ -174,24 +173,21 @@ assert_go_core_unpacked() {
174
173
@test " $SUITE : fail to move extracted directory uses git clone" {
175
174
PATH=" $BATS_TEST_BINDIR :$PATH "
176
175
stub_program_in_path mv " exit 1"
177
- run " $_GO_CORE_DIR /go-template"
176
+ run " $TEST_GO_ROOTDIR /go-template"
178
177
restore_program_in_path mv
179
178
180
179
# Without a command argument, the script will print the top-level help and
181
180
# return an error, but the core repo should exist as expected.
182
181
assert_output_matches " Downloading framework from '${GO_SCRIPT_BASH_REPO_URL% .git} .*.tar.gz'\.\.\."
183
- assert_output_matches " Failed to install downloaded directory in '.*/ $GO_SCRIPTS_DIR /go-script-bash'"
182
+ assert_output_matches " Failed to install downloaded directory in '$TEST_GO_SCRIPTS_DIR /go-script-bash'"
184
183
assert_output_matches " Using git clone as fallback"
185
- assert_output_matches " Cloning framework from '$GO_SCRIPT_BASH_REPO_URL '\.\.\."
186
-
187
- # Use `.*/scripts/go-script-bash` to account for the fact that `git clone` on
188
- # MSYS2 will output `C:/Users/<user>/AppData/Local/Temp/` in place of `/tmp`.
189
- assert_output_matches " Cloning into '.*/$GO_SCRIPTS_DIR /go-script-bash'\.\.\."
184
+ assert_output_matches " Cloning framework from '$GO_SCRIPT_BASH_REPO_URL '"
185
+ assert_output_matches " Cloning into '$TEST_GO_SCRIPTS_DIR /go-script-bash'"
190
186
assert_output_matches " Clone of '$GO_SCRIPT_BASH_REPO_URL ' successful\." $' \n\n '
191
- assert_output_matches " Usage: $_GO_CORE_DIR /go-template <command>"
187
+ assert_output_matches " Usage: $TEST_GO_ROOTDIR /go-template <command>"
192
188
assert_go_core_unpacked
193
189
194
- cd " $_GO_ROOTDIR / $GO_SCRIPTS_DIR /go-script-bash"
190
+ cd " $TEST_GO_SCRIPTS_DIR /go-script-bash"
195
191
run git log --oneline -n 1
196
192
assert_success
197
193
assert_output_matches " go-script-bash $_GO_CORE_VERSION "
0 commit comments