Skip to content

Commit 30b5c07

Browse files
fix(tests): keep the yq programs out of checkbashisms' source heuristic
checkbashisms reads a `.` adjacent to a quote as a POSIX `source` with arguments, so a yq program beginning or ending with one flags the file that carries it. The two added by the disabled-mode tests were new findings against main, which sh_posix_gate denies on commit and push. Both are rewritten to start at `select(` instead of a bare `.` and are held in variables rather than inlined, which keeps the command line free of the `.'file'` shape as well. Behaviour is unchanged: the tests still pass and the programs select the same fields. Assisted-By: Claude <[email protected]> Signed-off-by: Myasnikov Daniil <[email protected]>
1 parent 8efb067 commit 30b5c07

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

‎hack/select-install_test.bats‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,13 @@ YAML
251251
# Unique metadata.name, not a file count: the script partitions names, and a
252252
# sources file holding two documents would make a file count disagree for a
253253
# reason that has nothing to do with the complement.
254-
total=$(yq -rN '.metadata.name | select(. != null and . != "")' \
255-
packages/core/platform/sources/*.yaml | sort -u | wc -l | tr -d ' ')
254+
# Two shapes here are deliberate, both to keep checkbashisms quiet: the yq
255+
# program starts with `select(` rather than a bare `.`, and it is held in a
256+
# variable rather than inlined. checkbashisms reads a leading or trailing
257+
# `.` next to a quote as a POSIX `source`, and sh_posix_gate denies a commit
258+
# that adds one.
259+
names_q='select(.metadata.name != null and .metadata.name != "") | .metadata.name'
260+
total=$(yq -rN "$names_q" packages/core/platform/sources/*.yaml | sort -u | wc -l | tr -d ' ')
256261
keep=$(hack/select-install.sh "postgres" | wc -w | tr -d ' ')
257262
drop=$(hack/select-install.sh --disabled "postgres" | wc -w | tr -d ' ')
258263
sum=$((keep + drop))
@@ -279,8 +284,8 @@ YAML
279284
# backupstrategy-controller), so the test asserted nothing at all.
280285
@test "disabled mode: no kept package has a dependency in the complement" {
281286
deps=$(mktemp)
282-
yq -rN '.metadata.name as $n | .spec.variants[]?.dependsOn[]? | select(. != null and . != "") | $n + " " + .' \
283-
packages/core/platform/sources/*.yaml > "$deps"
287+
edges_q='select(.metadata.name != null) | .metadata.name as $n | .spec.variants[]?.dependsOn[]? | select(length > 0) | $n + " " + .'
288+
yq -rN "$edges_q" packages/core/platform/sources/*.yaml > "$deps"
284289

285290
for suite in $(find hack/e2e-chainsaw -mindepth 2 -maxdepth 2 -name chainsaw-test.yaml \
286291
| sed -e 's,^hack/e2e-chainsaw/,,' -e 's,/chainsaw-test\.yaml$,,'); do

0 commit comments

Comments
 (0)