Skip to content

Commit 0d8bd29

Browse files
committed
new: Fix tests under 3.2.57(1)-release
Under Bash 3.2.57(1)-release, `./go test new` was failing with: ``` ✗ new: tab complete --internal (in test file tests/new.bats, line 76) `touch "${internal_modules[@]}"' failed touch: (/var/folders/dl/0j29q1wd0w715j4gnz5ry_pc0000gn/T/test rootdir/scripts/lib/foo): No such file or directory ✗ new: tab complete --public (in test file tests/new.bats, line 94) `touch "${public_modules[@]}"' failed touch: (/var/folders/dl/0j29q1wd0w715j4gnz5ry_pc0000gn/T/test rootdir/lib/xyzzy): No such file or directory ✗ new: tab complete --test (in test file tests/new.bats, line 112) `touch "${test_files[@]}"' failed touch: (/var/folders/dl/0j29q1wd0w715j4gnz5ry_pc0000gn/T/test rootdir/tests/frotz.bats): No such file or directory ✗ new: tab complete --type (in test file tests/new.bats, line 130) `touch "${text_files[@]}"' failed touch: (/var/folders/dl/0j29q1wd0w715j4gnz5ry_pc0000gn/T/test rootdir/gue/wizard.txt): No such file or directory ``` At first I thought this was the "declare and initialize an array at the same time" bug from commit b421c73 and commit c6bf1cf, as the workaround was the same: declare the array on one line, and initialize it on another. After thinking it through, however, I realized this bug was different, since the earlier bug had to do with exported arrays not getting initialized, and these arrays were `local`. On top of that, it appeared that the brace expansion was to blame, since `touch` appeared to see only the final brace expansion value, and that value was wrapped in parentheses. To verify this, I added this line before one of the `touch` calls: printf 'ARG: %s\n' "${internal_modules[@]}" >&2 which produced: ✗ new: tab complete --internal (in test file tests/new.bats, line 77) `touch "${internal_modules[@]}"' failed ARG: (/var/folders/dl/0j29q1wd0w715j4gnz5ry_pc0000gn/T/test rootdir/scripts/lib/foo) touch: (/var/folders/dl/0j29q1wd0w715j4gnz5ry_pc0000gn/T/test rootdir/scripts/lib/foo): No such file or directory After reviewing https://tiswww.case.edu/php/chet/bash/CHANGES, this appeared to be the most likely culprit: This document details the changes between this version, bash-4.1-alpha, and the previous version, bash-4.0-release. bb. Fixed a bug that caused brace expansion to take place too soon in some compound array assignments. Using the methodology described in the log message for commit 99ab780, I downloaded the Bash 4.0 and 4.1 sources and patches, and confirmed that the bug manifested under Bash 4.0.44 (the highest patchlevel for 4.0) and did not manifest under Bash 4.1. Also, for future reference, the official Bash git repository is at: https://savannah.gnu.org/git/?group=bash http://git.savannah.gnu.org/cgit/bash.git However, neither the patches from https://mirrors.ocf.berkeley.edu/gnu/bash/ nor the Git repository show a specific change for the fix, and the diff between 4.0.44 and 4.1 is too large and difficult to parse to easily identify the fix.
1 parent bb21e63 commit 0d8bd29

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

tests/new.bats

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ assert_command_script_is_executable() {
8484
run "$TEST_GO_SCRIPT" complete 1 new '--i'
8585
assert_success '--internal '
8686

87-
local internal_modules=("$TEST_GO_SCRIPTS_DIR/lib/"{bar,baz,foo})
87+
local internal_modules
88+
internal_modules=("$TEST_GO_SCRIPTS_DIR/lib/"{bar,baz,foo})
8889
mkdir -p "$TEST_GO_SCRIPTS_DIR/lib/"
8990
touch "${internal_modules[@]}"
9091

@@ -102,7 +103,8 @@ assert_command_script_is_executable() {
102103
run "$TEST_GO_SCRIPT" complete 1 new '--p'
103104
assert_success '--public '
104105

105-
local public_modules=("$TEST_GO_ROOTDIR/lib/"{plugh,quux,xyzzy})
106+
local public_modules
107+
public_modules=("$TEST_GO_ROOTDIR/lib/"{plugh,quux,xyzzy})
106108
mkdir -p "$TEST_GO_ROOTDIR/lib/"
107109
touch "${public_modules[@]}"
108110

@@ -120,7 +122,8 @@ assert_command_script_is_executable() {
120122
run "$TEST_GO_SCRIPT" complete 1 new '--te'
121123
assert_success '--test '
122124

123-
local test_files=("$TEST_GO_ROOTDIR/tests/"{aimfiz,blorple,frotz}.bats)
125+
local test_files
126+
test_files=("$TEST_GO_ROOTDIR/tests/"{aimfiz,blorple,frotz}.bats)
124127
mkdir -p "$TEST_GO_ROOTDIR/tests/"
125128
touch "${test_files[@]}"
126129

@@ -138,7 +141,8 @@ assert_command_script_is_executable() {
138141
run "$TEST_GO_SCRIPT" complete 1 new '--ty'
139142
assert_success '--type '
140143

141-
local text_files=("$TEST_GO_ROOTDIR/gue/"{dungeonmaster,thief,wizard}.txt)
144+
local text_files
145+
text_files=("$TEST_GO_ROOTDIR/gue/"{dungeonmaster,thief,wizard}.txt)
142146
mkdir -p "$TEST_GO_ROOTDIR/gue"
143147
touch "${text_files[@]}"
144148

0 commit comments

Comments
 (0)