Skip to content

Commit

Permalink
chore: Shard testscript tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KapJI committed Nov 9, 2024
1 parent 9fe2cad commit d608691
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,14 @@ jobs:
name: chezmoi-windows-amd64
path: dist/chezmoi-nocgo_windows_amd64_v1/chezmoi.exe
test-ubuntu:
name: test-ubuntu-umask${{ matrix.umask }}-${{ matrix.test-index }}
strategy:
fail-fast: false
matrix:
umask:
- "022"
- "002"
test-index: [0, 1, 2]
needs: changes
runs-on: ubuntu-20.04 # use older Ubuntu for older glibc
permissions:
Expand Down Expand Up @@ -318,8 +320,15 @@ jobs:
if: github.event_name == 'push' || needs.changes.outputs.code == 'true'
env:
CHEZMOI_GITHUB_TOKEN: ${{ secrets.CHEZMOI_GITHUB_TOKEN }}
run: |
go test -ldflags="-X github.com/twpayne/chezmoi/v2/internal/chezmoitest.umaskStr=0o${{ matrix.umask }}" -race -timeout=1h ./...
TEST_FLAGS: '-ldflags="-X github.com/twpayne/chezmoi/v2/internal/chezmoitest.umaskStr=0o${{ matrix.umask }}" -race -timeout=1h'
run: |
if [ ${{ matrix.test-index }} -eq 0 ]; then
go test ./... -short ${{ env.TEST_FLAGS }}
elif [ ${{ matrix.test-index }} -eq 1 ]; then
go test ./internal/cmd -run=TestScript -filter='^[0-9a-hA-h]' -v ${{ env.TEST_FLAGS }}
else
go test ./internal/cmd -run=TestScript -filter='^[i-zI-Z]' -v ${{ env.TEST_FLAGS }}
fi
test-website:
runs-on: ubuntu-22.04
permissions:
Expand Down
8 changes: 5 additions & 3 deletions internal/cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ var (
)

func TestMain(m *testing.M) {
flag.StringVar(&filterRegex, "filter", "", "regex to filter test scripts")
flag.Parse()
if strings.HasSuffix(os.Args[0], "test") {
flag.StringVar(&filterRegex, "filter", "", "regex to filter test scripts")
flag.Parse()
}
os.Exit(testscript.RunMain(m, map[string]func() int{
"chezmoi": func() int {
return cmd.Main(cmd.VersionInfo{
Expand Down Expand Up @@ -77,7 +79,7 @@ func TestScript(t *testing.T) {
}
var filteredFiles []string
for _, f := range files {
baseName := filepath.Base(f)
baseName := strings.Split(filepath.Base(f), ".")[0]
if re.MatchString(baseName) {
filteredFiles = append(filteredFiles, f)
}
Expand Down

0 comments on commit d608691

Please sign in to comment.