@@ -75,6 +75,25 @@ assert_go_core_unpacked() {
75
75
restore_bats_shell_options " $result "
76
76
}
77
77
78
+ # Skips the current test if zero of the listed system programs are present.
79
+ #
80
+ # Arguments:
81
+ # $@: System programs of which at least one must be present to run the test
82
+ skip_if_none_present_on_system () {
83
+ local missing
84
+
85
+ if ! command -v " $@ " > /dev/null; then
86
+ if [[ " $# " -eq ' 1' ]]; then
87
+ skip " $1 isn't installed on the system"
88
+ elif [[ " $# " -eq ' 2' ]]; then
89
+ skip " Neither $1 nor $2 are installed on the system"
90
+ else
91
+ printf -v missing ' %s, ' " ${@: 1: $(($# - 1))} "
92
+ skip " None of ${missing% } or ${@: $# } are installed on the system"
93
+ fi
94
+ fi
95
+ }
96
+
78
97
# Converts a Unix path or 'file://' URL to a Git for Windows native path.
79
98
#
80
99
# This is useful when passing file paths or URLs to native programs on Git for
@@ -123,11 +142,11 @@ create_fake_tarball_if_not_using_real_url() {
123
142
elif ! mkdir -p " $full_dir " ; then
124
143
printf ' Failed to create fake content dir %s\n' " $full_dir " >&2
125
144
result=' 1'
126
- elif ! tar xf < ( tar cf - go-core.bash lib libexec) -C " $full_dir " ; then
145
+ elif ! tar - xf - -C " $full_dir " < < ( tar - cf - go-core.bash lib libexec) ; then
127
146
printf ' Failed to mirror %s to fake tarball dir %s\n' \
128
147
" $_GO_ROOTDIR " " $full_dir " >&2
129
148
result=' 1'
130
- elif ! tar cfz " $tarball " -C " $TEST_GO_ROOTDIR " " $dirname " ; then
149
+ elif ! tar -czf " $tarball " -C " $TEST_GO_ROOTDIR " " $dirname " ; then
131
150
printf ' Failed to create fake tarball %s\n from dir %s\n' \
132
151
" $tarball " " $full_dir " >&2
133
152
result=' 1'
@@ -202,6 +221,8 @@ run_with_download_program() {
202
221
}
203
222
204
223
@test " $SUITE : download $GO_SCRIPT_BASH_VERSION from $FULL_DOWNLOAD_URL " {
224
+ skip_if_none_present_on_system ' curl' ' fetch' ' wget'
225
+ skip_if_system_missing ' tar'
205
226
create_fake_tarball_if_not_using_real_url
206
227
run " $TEST_GO_ROOTDIR /go-template"
207
228
@@ -215,6 +236,7 @@ run_with_download_program() {
215
236
}
216
237
217
238
@test " $SUITE : download locally using curl" {
239
+ skip_if_system_missing ' tar'
218
240
run_with_download_program ' curl'
219
241
assert_output_matches " Downloading framework from '$NATIVE_LOCAL_URL '\.\.\."
220
242
assert_output_matches " Download of '$NATIVE_LOCAL_URL ' successful." $' \n\n '
@@ -223,6 +245,7 @@ run_with_download_program() {
223
245
}
224
246
225
247
@test " $SUITE : download locally using fetch" {
248
+ skip_if_system_missing ' tar'
226
249
run_with_download_program ' fetch'
227
250
assert_output_matches " Downloading framework from '$NATIVE_LOCAL_URL '\.\.\."
228
251
assert_output_matches " Download of '$NATIVE_LOCAL_URL ' successful." $' \n\n '
@@ -231,6 +254,7 @@ run_with_download_program() {
231
254
}
232
255
233
256
@test " $SUITE : download locally using cat" {
257
+ skip_if_system_missing ' tar'
234
258
# We'll actually use `cat` with `file://` URLs, since `wget` only supports
235
259
# HTTP, HTTPS, and FTP.
236
260
run_with_download_program ' cat'
@@ -241,6 +265,7 @@ run_with_download_program() {
241
265
}
242
266
243
267
@test " $SUITE : download locally using wget" {
268
+ skip_if_system_missing ' tar'
244
269
# As mentioned in the above test case, we'll actually use `cat` with `file://`
245
270
# URLs, but we're simulating `wget` by pretending `cat` doesn't exist.
246
271
run_with_download_program ' wget'
@@ -252,6 +277,8 @@ run_with_download_program() {
252
277
253
278
@test " $SUITE : download into nonstandard GO_SCRIPTS_DIR" {
254
279
local core_dir=" $TEST_GO_ROOTDIR /foobar"
280
+ skip_if_none_present_on_system ' curl' ' fetch' ' wget'
281
+ skip_if_system_missing ' tar'
255
282
create_fake_tarball_if_not_using_real_url
256
283
257
284
# Create a command script in the normal `TEST_GO_SCRIPTS_DIR`.
@@ -265,6 +292,8 @@ run_with_download_program() {
265
292
}
266
293
267
294
@test " $SUITE : download uses existing GO_SCRIPTS_DIR" {
295
+ skip_if_none_present_on_system ' curl' ' fetch' ' wget'
296
+ skip_if_system_missing ' tar'
268
297
create_fake_tarball_if_not_using_real_url
269
298
mkdir -p " $TEST_GO_SCRIPTS_DIR "
270
299
stub_program_in_path mkdir " exit 1"
@@ -280,6 +309,9 @@ run_with_download_program() {
280
309
@test " $SUITE : fail to download a nonexistent repo" {
281
310
local url=' https://bogus-url-that-does-not-exist'
282
311
local repo=' bogus-repo-that-does-not-exist'
312
+
313
+ skip_if_none_present_on_system ' curl' ' fetch' ' wget'
314
+ skip_if_system_missing ' git' ' tar'
283
315
GO_SCRIPT_BASH_DOWNLOAD_URL=" $url " GO_SCRIPT_BASH_REPO_URL=" $repo " \
284
316
run " $TEST_GO_ROOTDIR /go-template"
285
317
assert_failure
@@ -294,6 +326,9 @@ run_with_download_program() {
294
326
@test " $SUITE : fail to download a nonexistent version" {
295
327
local url=" $GO_SCRIPT_BASH_DOWNLOAD_URL /vnonexistent.tar.gz"
296
328
local branch=' vnonexistent'
329
+
330
+ skip_if_none_present_on_system ' curl' ' fetch' ' wget'
331
+ skip_if_system_missing ' git' ' tar'
297
332
GO_SCRIPT_BASH_VERSION=" $branch " run " $TEST_GO_ROOTDIR /go-template"
298
333
assert_failure
299
334
assert_output_matches ' Using git clone as fallback'
@@ -307,6 +342,7 @@ run_with_download_program() {
307
342
@test " $SUITE : use git clone if GO_SCRIPT_BASH_DOWNLOAD_URL lacks a protocol" {
308
343
local url=' bogus-url-with-no-protocol'
309
344
345
+ skip_if_system_missing ' git'
310
346
GO_SCRIPT_BASH_DOWNLOAD_URL=" $url " run " $TEST_GO_ROOTDIR /go-template"
311
347
312
348
assert_output_matches " GO_SCRIPT_BASH_DOWNLOAD_URL has no protocol: $url "
@@ -325,6 +361,7 @@ run_with_download_program() {
325
361
}
326
362
327
363
@test " $SUITE : fail to find download program uses git clone" {
364
+ skip_if_system_missing ' git'
328
365
PATH=" $BATS_TEST_BINDIR " run " $BASH " " $TEST_GO_ROOTDIR /go-template"
329
366
330
367
assert_output_matches " Failed to find cURL, wget, or fetch"
@@ -335,7 +372,8 @@ run_with_download_program() {
335
372
}
336
373
337
374
@test " $SUITE : fail to find tar uses git clone" {
338
- # If none of these are installed on the system, the test will fail.
375
+ skip_if_none_present_on_system ' curl' ' fetch' ' wget'
376
+ skip_if_system_missing ' git'
339
377
create_forwarding_script ' curl'
340
378
create_forwarding_script ' wget'
341
379
create_forwarding_script ' fetch'
@@ -350,6 +388,8 @@ run_with_download_program() {
350
388
}
351
389
352
390
@test " $SUITE : fail to create directory uses git clone" {
391
+ skip_if_none_present_on_system ' curl' ' fetch' ' wget'
392
+ skip_if_system_missing ' git' ' tar'
353
393
create_fake_tarball_if_not_using_real_url
354
394
stub_program_in_path mkdir " exit 1"
355
395
run " $TEST_GO_ROOTDIR /go-template"
@@ -371,6 +411,8 @@ run_with_download_program() {
371
411
@test " $SUITE : fail to move extracted directory uses git clone" {
372
412
local target=" $TEST_GO_SCRIPTS_DIR /go-script-bash"
373
413
414
+ skip_if_none_present_on_system ' curl' ' fetch' ' wget'
415
+ skip_if_system_missing ' git' ' tar'
374
416
create_fake_tarball_if_not_using_real_url
375
417
stub_program_in_path mv " exit 1"
376
418
run " $TEST_GO_ROOTDIR /go-template"
0 commit comments