From aba6a689a4c4a204456a15bbdba647b0ed907ff3 Mon Sep 17 00:00:00 2001 From: Viacheslav Poturaev Date: Tue, 4 Apr 2023 00:11:09 +0200 Subject: [PATCH] Update CI for go1.20 (#552) --- .github/workflows/release-assets.yml | 2 +- .github/workflows/test.yml | 2 +- godog.go | 1 + internal/builder/builder_go113_test.go | 5 +++-- internal/builder/builder_go_module_test.go | 6 +----- internal/storage/fs_test.go | 5 +++-- stacktrace.go | 12 ++++++------ suite_context_test.go | 19 ++++++++++++------- 8 files changed, 28 insertions(+), 24 deletions(-) diff --git a/.github/workflows/release-assets.yml b/.github/workflows/release-assets.yml index 9fa678d..c4da102 100644 --- a/.github/workflows/release-assets.yml +++ b/.github/workflows/release-assets.yml @@ -15,7 +15,7 @@ jobs: - name: Install Go uses: actions/setup-go@v4 with: - go-version: 1.17.x + go-version: 1.20.x - name: Checkout code uses: actions/checkout@v3 - name: Build artifacts diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d1c9fa0..aebd31b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ jobs: test: strategy: matrix: - go-version: [ 1.16.x, 1.17.x ] + go-version: [ 1.16.x, 1.17.x, 1.19.x, 1.20.x ] # Lowest supported and current stable versions. runs-on: ubuntu-latest steps: - name: Install Go diff --git a/godog.go b/godog.go index c97f33b..dda5014 100644 --- a/godog.go +++ b/godog.go @@ -14,6 +14,7 @@ For example, imagine you're about to create the famous UNIX ls command. Before you begin, you describe how the feature should work, see the example below.. Example: + Feature: ls In order to see the directory structure As a UNIX user diff --git a/internal/builder/builder_go113_test.go b/internal/builder/builder_go113_test.go index 9a77272..6413985 100644 --- a/internal/builder/builder_go113_test.go +++ b/internal/builder/builder_go113_test.go @@ -24,8 +24,9 @@ func testWithVendoredGodogAndMod(t *testing.T) { "go.mod": builderModFile, } - builderTC.goModCmds = make([]*exec.Cmd, 1) - builderTC.goModCmds[0] = exec.Command("go", "mod", "vendor") + builderTC.goModCmds = make([]*exec.Cmd, 2) + builderTC.goModCmds[0] = exec.Command("go", "mod", "tidy") + builderTC.goModCmds[1] = exec.Command("go", "mod", "vendor") builderTC.testCmdEnv = append(envVarsWithoutGopath(), "GOPATH="+gopath) builderTC.run(t) diff --git a/internal/builder/builder_go_module_test.go b/internal/builder/builder_go_module_test.go index bce33a4..48c5698 100644 --- a/internal/builder/builder_go_module_test.go +++ b/internal/builder/builder_go_module_test.go @@ -1,13 +1,10 @@ package builder_test import ( - "fmt" "os" "os/exec" "path/filepath" "testing" - - "github.com/cucumber/godog" ) func testOutsideGopathAndHavingOnlyFeature(t *testing.T) { @@ -21,8 +18,7 @@ func testOutsideGopathAndHavingOnlyFeature(t *testing.T) { builderTC.goModCmds = make([]*exec.Cmd, 2) builderTC.goModCmds[0] = exec.Command("go", "mod", "init", "godogs") - godogDependency := fmt.Sprintf("github.com/cucumber/godog@%s", godog.Version) - builderTC.goModCmds[1] = exec.Command("go", "mod", "edit", "-require", godogDependency) + builderTC.goModCmds[1] = exec.Command("go", "mod", "tidy") builderTC.run(t) } diff --git a/internal/storage/fs_test.go b/internal/storage/fs_test.go index 164fe4d..461bb0a 100644 --- a/internal/storage/fs_test.go +++ b/internal/storage/fs_test.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "os" "path/filepath" + "strings" "testing" "testing/fstest" @@ -72,7 +73,7 @@ func TestStorage_Open_OS(t *testing.T) { expData: []byte("hello worlds"), }, "nil fs falls back on os": { - expError: errors.New("open /tmp/TestStorage_Open_OS/nil_fs_falls_back_on_os/godogs/testfile: no such file or directory"), + expError: errors.New("open %baseDir%/testfile: no such file or directory"), }, } @@ -95,7 +96,7 @@ func TestStorage_Open_OS(t *testing.T) { f, err := (storage.FS{}).Open(filepath.Join(baseDir, "testfile")) if test.expError != nil { assert.Error(t, err) - assert.EqualError(t, err, test.expError.Error()) + assert.EqualError(t, err, strings.ReplaceAll(test.expError.Error(), "%baseDir%", baseDir)) return } diff --git a/stacktrace.go b/stacktrace.go index ed594c9..686c6b0 100644 --- a/stacktrace.go +++ b/stacktrace.go @@ -48,15 +48,15 @@ func (f stackFrame) line() int { // Format formats the frame according to the fmt.Formatter interface. // -// %s source file -// %d source line -// %n function name -// %v equivalent to %s:%d +// %s source file +// %d source line +// %n function name +// %v equivalent to %s:%d // // Format accepts flags that alter the printing of some verbs, as follows: // -// %+s path of source file relative to the compile time GOPATH -// %+v equivalent to %+s:%d +// %+s path of source file relative to the compile time GOPATH +// %+v equivalent to %+s:%d func (f stackFrame) Format(s fmt.State, verb rune) { funcname := func(name string) string { i := strings.LastIndex(name, "/") diff --git a/suite_context_test.go b/suite_context_test.go index e25b3bb..36675c4 100644 --- a/suite_context_test.go +++ b/suite_context_test.go @@ -704,13 +704,13 @@ func (tc *godogFeaturesScenario) theseEventsHadToBeFiredForNumberOfTimes(tbl *Ta func (tc *godogFeaturesScenario) theRenderJSONWillBe(docstring *DocString) error { expectedSuiteCtxReg := regexp.MustCompile(`suite_context.go:\d+`) - actualSuiteCtxReg := regexp.MustCompile(`suite_context_test.go:\d+`) + actualSuiteCtxReg := regexp.MustCompile(`(suite_context_test\.go|\\u003cautogenerated\\u003e):\d+`) expectedString := docstring.Content - expectedString = expectedSuiteCtxReg.ReplaceAllString(expectedString, `suite_context_test.go:0`) + expectedString = expectedSuiteCtxReg.ReplaceAllString(expectedString, `:0`) actualString := tc.out.String() - actualString = actualSuiteCtxReg.ReplaceAllString(actualString, `suite_context_test.go:0`) + actualString = actualSuiteCtxReg.ReplaceAllString(actualString, `:0`) var expected []formatters.CukeFeatureJSON if err := json.Unmarshal([]byte(expectedString), &expected); err != nil { @@ -726,8 +726,8 @@ func (tc *godogFeaturesScenario) theRenderJSONWillBe(docstring *DocString) error } func (tc *godogFeaturesScenario) theRenderOutputWillBe(docstring *DocString) error { - expectedSuiteCtxReg := regexp.MustCompile(`suite_context.go:\d+`) - actualSuiteCtxReg := regexp.MustCompile(`suite_context_test.go:\d+`) + expectedSuiteCtxReg := regexp.MustCompile(`(suite_context\.go|suite_context_test\.go):\d+`) + actualSuiteCtxReg := regexp.MustCompile(`(suite_context_test\.go|\):\d+`) expectedSuiteCtxFuncReg := regexp.MustCompile(`SuiteContext.func(\d+)`) actualSuiteCtxFuncReg := regexp.MustCompile(`github.com/cucumber/godog.InitializeScenario.func(\d+)`) @@ -736,12 +736,12 @@ func (tc *godogFeaturesScenario) theRenderOutputWillBe(docstring *DocString) err expected := docstring.Content expected = trimAllLines(expected) - expected = expectedSuiteCtxReg.ReplaceAllString(expected, "suite_context_test.go:0") + expected = expectedSuiteCtxReg.ReplaceAllString(expected, ":0") expected = expectedSuiteCtxFuncReg.ReplaceAllString(expected, "InitializeScenario.func$1") expected = suiteCtxPtrReg.ReplaceAllString(expected, "*godogFeaturesScenario") actual := tc.out.String() - actual = actualSuiteCtxReg.ReplaceAllString(actual, "suite_context_test.go:0") + actual = actualSuiteCtxReg.ReplaceAllString(actual, ":0") actual = actualSuiteCtxFuncReg.ReplaceAllString(actual, "InitializeScenario.func$1") actualTrimmed := actual actual = trimAllLines(actual) @@ -769,6 +769,11 @@ func (tc *godogFeaturesScenario) theRenderXMLWillBe(docstring *DocString) error func assertExpectedAndActual(a expectedAndActualAssertion, expected, actual interface{}, msgAndArgs ...interface{}) error { var t asserter a(&t, expected, actual, msgAndArgs...) + + if t.err != nil { + return t.err + } + return t.err }