@@ -24,38 +24,27 @@ GO_CORE_URL="${GO_CORE_URL:-$_GO_CORE_DIR}"
2424
2525setup () {
2626 test_filter
27- mkdir " $TEST_GO_ROOTDIR "
28-
29- if [[ -e " $GO_CORE_URL /.git/shallow" ]]; then
30- skip " Can't clone shallow repositories"
31- fi
27+ export GO_SCRIPT_BASH_VERSION=" $_GO_CORE_VERSION "
28+ export GO_SCRIPTS_DIR=" $_GO_TEST_DIR /tmp/go-template-test-scripts"
29+ export GO_SCRIPT_BASH_REPO_URL=" $GO_CORE_URL "
3230}
3331
3432teardown () {
35- @go.remove_test_go_rootdir
33+ rm -rf " $_GO_ROOTDIR / $GO_SCRIPTS_DIR "
3634}
3735
38- create_template_script () {
39- local repo_url=" $1 "
40- local version=" $2 "
41- local template=" $( < " $_GO_CORE_DIR /go-template" ) "
42- local replacement
43-
44- if [[ " $template " =~ GO_SCRIPT_BASH_REPO_URL= [^$' \n ' ]+ ]]; then
45- replacement=" GO_SCRIPT_BASH_REPO_URL='$repo_url '"
46- template=" ${template/ ${BASH_REMATCH[0]} / $replacement } "
47- fi
48- if [[ " $template " =~ GO_SCRIPT_BASH_VERSION= [^$' \n ' ]+ ]]; then
49- replacement=" GO_SCRIPT_BASH_VERSION='$version '"
50- template=" ${template/ ${BASH_REMATCH[0]} / $replacement } "
51- fi
52- printf ' %s\n' " $template " > " $TEST_GO_ROOTDIR /go-template"
53- chmod 700 " $TEST_GO_ROOTDIR /go-template"
36+ @test " $SUITE : successfully run 'help' from its own directory" {
37+ GO_SCRIPT_BASH_CORE_DIR=" $_GO_CORE_DIR " GO_SCRIPTS_DIR=' scripts' \
38+ run " $_GO_CORE_DIR /go-template" ' help'
39+ assert_success
40+ assert_output_matches " Usage: $_GO_CORE_DIR /go-template <command>"
5441}
5542
5643@test " $SUITE : clone the go-script-bash repository from $GO_CORE_URL " {
57- create_template_script " $GO_CORE_URL " " $_GO_CORE_VERSION "
58- run " $TEST_GO_ROOTDIR /go-template"
44+ if [[ -e " $GO_CORE_URL /.git/shallow" ]]; then
45+ skip " Can't clone shallow repositories"
46+ fi
47+ run " $_GO_CORE_DIR /go-template"
5948
6049 # Without a command argument, the script will print the top-level help and
6150 # return an error, but the core repo should exist as expected.
@@ -64,20 +53,20 @@ create_template_script() {
6453
6554 # Use `.*/scripts/go-script-bash` to account for the fact that `git clone` on
6655 # MSYS2 will output `C:/Users/<user>/AppData/Local/Temp/` in place of `/tmp`.
67- assert_output_matches " Cloning into '.*/scripts /go-script-bash'\.\.\."
56+ assert_output_matches " Cloning into '.*/$GO_SCRIPTS_DIR /go-script-bash'\.\.\."
6857 assert_output_matches " Clone of '$GO_CORE_URL ' successful\." $' \n\n '
69- assert_output_matches " Usage: $TEST_GO_ROOTDIR /go-template <command>"
70- [[ -f " $TEST_GO_ROOTDIR /scripts /go-script-bash/go-core.bash" ]]
58+ assert_output_matches " Usage: $_GO_CORE_DIR /go-template <command>"
59+ [[ -f " $_GO_ROOTDIR / $GO_SCRIPTS_DIR /go-script-bash/go-core.bash" ]]
7160
72- cd " $TEST_GO_ROOTDIR /scripts /go-script-bash"
61+ cd " $_GO_ROOTDIR / $GO_SCRIPTS_DIR /go-script-bash"
7362 run git log --oneline -n 1
7463 assert_success
7564 assert_output_matches " go-script-bash $_GO_CORE_VERSION "
7665}
7766
7867@test " $SUITE : fail to clone a nonexistent repo" {
79- create_template_script ' bogus-repo-that-does-not-exist'
80- run " $TEST_GO_ROOTDIR /go-template"
68+ GO_SCRIPT_BASH_REPO_URL= ' bogus-repo-that-does-not-exist' \
69+ run " $_GO_CORE_DIR /go-template"
8170 assert_failure " Cloning framework from 'bogus-repo-that-does-not-exist'..." \
8271 " fatal: repository 'bogus-repo-that-does-not-exist' does not exist" \
8372 " Failed to clone 'bogus-repo-that-does-not-exist'; aborting."
0 commit comments