Skip to content

Commit 067034c

Browse files
committed
fix(ci): support empty flags on Bash 3.2
1 parent d6c28ac commit 067034c

3 files changed

Lines changed: 88 additions & 6 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { spawnSync } from 'node:child_process'
2+
import {
3+
mkdirSync,
4+
mkdtempSync,
5+
readFileSync,
6+
rmSync,
7+
writeFileSync,
8+
} from 'node:fs'
9+
import { tmpdir } from 'node:os'
10+
import { join } from 'node:path'
11+
import { describe, expect, it } from 'vitest'
12+
import { REPO_ROOT } from './lib/repo-root.mjs'
13+
14+
describe('Go binding script test flags', () => {
15+
for (const platform of ['Darwin', 'Linux']) {
16+
for (const producer of [false, true]) {
17+
it(`${platform}, artifact producer=${producer}`, () => {
18+
const root = mkdtempSync(join(tmpdir(), 'go-binding-script-'))
19+
try {
20+
const bin = join(root, 'bin')
21+
const module = join(root, 'module with spaces')
22+
const log = join(root, 'commands.log')
23+
mkdirSync(bin)
24+
mkdirSync(module)
25+
writeFileSync(join(module, 'guest.wasm'), 'test guest')
26+
writeFileSync(join(bin, 'gofmt'), '#!/bin/sh\nexit 0\n', {
27+
mode: 0o755,
28+
})
29+
writeFileSync(
30+
join(bin, 'uname'),
31+
`#!/bin/sh\nprintf '%s\\n' '${platform}'\n`,
32+
{ mode: 0o755 },
33+
)
34+
writeFileSync(
35+
join(bin, 'go'),
36+
`#!/bin/sh
37+
printf '%s|%s|%s\\n' "\${GOOS:-}" "\${GOARCH:-}" "$*" >> "$GO_BINDING_LOG"
38+
`,
39+
{ mode: 0o755 },
40+
)
41+
// /bin/bash is the CI shell, including Bash 3.2 on macOS. Do not
42+
// accidentally test only a newer Homebrew shell found on PATH.
43+
const result = spawnSync(
44+
'/bin/bash',
45+
[
46+
join(REPO_ROOT, 'scripts/go-binding-test.sh'),
47+
module,
48+
'guest.wasm',
49+
],
50+
{
51+
env: {
52+
...process.env,
53+
PATH: `${bin}:${process.env.PATH}`,
54+
GO_BINDING_LOG: log,
55+
GOOS: '',
56+
GOARCH: '',
57+
STACK_CONFORMANCE_OUTPUT: producer
58+
? join(root, 'artifact.json')
59+
: '',
60+
},
61+
encoding: 'utf8',
62+
},
63+
)
64+
expect(result.status, result.stderr).toBe(0)
65+
const flags = producer ? '-count=1 ' : ''
66+
expect(readFileSync(log, 'utf8').trim().split('\n')).toEqual([
67+
'||vet ./...',
68+
'||test -v ./auth -run ^TestDeviceRefresh',
69+
`||test ${flags}./...`,
70+
platform === 'Linux'
71+
? `linux|386|test ${flags}./...`
72+
: 'linux|386|vet ./...',
73+
])
74+
} finally {
75+
rmSync(root, { recursive: true, force: true })
76+
}
77+
})
78+
}
79+
}
80+
})

‎scripts/__tests__/stack-conformance-ci.test.mjs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ describe('shared Stack Encrypt conformance is required in CI', () => {
6767
join(REPO_ROOT, 'scripts/go-binding-test.sh'),
6868
'utf8',
6969
)
70-
expect(goTests).toContain('conformance_flags=(-count=1)')
71-
expect(goTests).toMatch(/go test "\$\{conformance_flags\[@\]\}" \.\/\.\.\./)
70+
expect(goTests).toContain('set -- -count=1')
71+
expect(goTests).toContain('go test "$@" ./...')
7272
expect(steps[exchange].if).toBeUndefined()
7373
expect(steps[exchange]['continue-on-error']).toBeUndefined()
7474
})

‎scripts/go-binding-test.sh‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,20 @@ go vet ./...
4141
# independent guest instances sharing one auth.json.
4242
CGO_ENABLED=0 go test -v ./auth -run '^TestDeviceRefresh'
4343
# A producer must execute even if Go has cached a previous successful run.
44-
conformance_flags=()
44+
# The guest paths have been checked; reuse positional arguments for test flags.
45+
# Unlike an empty array, "$@" is safe under nounset in macOS's Bash 3.2.
46+
set --
4547
if [[ -n "${STACK_CONFORMANCE_OUTPUT:-}" ]]; then
46-
conformance_flags=(-count=1)
48+
set -- -count=1
4749
fi
48-
CGO_ENABLED=0 go test "${conformance_flags[@]}" ./...
50+
CGO_ENABLED=0 go test "$@" ./...
4951

5052
# The transport codec's u32-bound guards are load-bearing where int is 32
5153
# bits (vitaminc's vcffi runs this sweep too); the binding's own reflection
5254
# and buffer arithmetic must hold there as well. Linux hosts execute 386
5355
# natively; elsewhere the binary cannot run, so only vet.
5456
if [ "$(uname -s)" = "Linux" ]; then
55-
CGO_ENABLED=0 GOOS=linux GOARCH=386 go test "${conformance_flags[@]}" ./...
57+
CGO_ENABLED=0 GOOS=linux GOARCH=386 go test "$@" ./...
5658
else
5759
CGO_ENABLED=0 GOOS=linux GOARCH=386 go vet ./...
5860
fi

0 commit comments

Comments
 (0)