From f971df9fbe88dc18e109a81080bbbd3dfe47963a Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Tue, 26 Apr 2022 18:56:44 -0700 Subject: [PATCH] ci: add go 1.17.x and 1.18.x, fix failing test One test is failing with Go 1.17+ since it now panics instead of returning an error. Catch the panic and consider the test passed. With that out of the door, add Go 1.17.x and 1.18.x to the testing matrix. While at it, do not use && in run since it is executed by a shell with set -e, thus making && redundant. Signed-off-by: Kir Kolyshkin --- .github/workflows/cli.yml | 11 +++-------- app_test.go | 8 ++++++++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/cli.yml b/.github/workflows/cli.yml index f95ee2e607..d5e5029c1f 100644 --- a/.github/workflows/cli.yml +++ b/.github/workflows/cli.yml @@ -16,12 +16,7 @@ jobs: matrix: os: [ubuntu-latest, macos-latest] go: - - 1.16.x - # NOTE: tests fail with panic at - # TestApp_RunAsSubCommandIncorrectUsage on these - # versions: - # - 1.17.x - # - 1.18.x + - [1.16.x, 1.17.x, 1.18.x] name: ${{ matrix.os }} @ Go ${{ matrix.go }} runs-on: ${{ matrix.os }} steps: @@ -38,6 +33,6 @@ jobs: - name: Run Tests run: - go run build.go vet && - go run build.go test && + go run build.go vet + go run build.go test go run build.go toc docs/v1/manual.md diff --git a/app_test.go b/app_test.go index b9aa34a2dd..9aac30cb83 100644 --- a/app_test.go +++ b/app_test.go @@ -508,6 +508,14 @@ func TestApp_RunAsSubcommandParseFlags(t *testing.T) { } func TestApp_RunAsSubCommandIncorrectUsage(t *testing.T) { + // Go 1.17+ panics when invalid flag is given. + // Catch it here and consider the test passed. + defer func() { + if err := recover(); err == nil { + t.Fatal("expected error, got nothing") + } + }() + a := App{ Flags: []Flag{ StringFlag{Name: "--foo"},