From e4fe373a711e3d22e31783d0dbe76493816a77f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Sun, 11 Jun 2023 23:26:15 +0200 Subject: [PATCH 1/3] assert/cmd/gty-migrate-from-testify: fix TestRun The test TestRun of the gty-migrate-from-testify tool apparently needs to have the original packages available to run. So let's install them ("go get" in GOPATH mode, in a temporary directory) before running the migration test. --- assert/cmd/gty-migrate-from-testify/main_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/assert/cmd/gty-migrate-from-testify/main_test.go b/assert/cmd/gty-migrate-from-testify/main_test.go index d7f5968..dfc93d7 100644 --- a/assert/cmd/gty-migrate-from-testify/main_test.go +++ b/assert/cmd/gty-migrate-from-testify/main_test.go @@ -2,6 +2,7 @@ package main import ( "os" + "os/exec" "testing" "github.com/google/go-cmp/cmp" @@ -11,6 +12,14 @@ import ( "gotest.tools/v3/golden" ) +func goGet(t *testing.T, pkg string) { + t.Log("go get", pkg) + cmd := exec.Command("go", "get", pkg) + if err := cmd.Run(); err != nil { + t.Fatal(err) + } +} + func TestRun(t *testing.T) { setupLogging(&options{}) dir := fs.NewDir(t, "test-run", @@ -19,6 +28,13 @@ func TestRun(t *testing.T) { defer env.Patch(t, "GO111MODULE", "off")() defer env.Patch(t, "GOPATH", dir.Path())() + + // Fetch dependencies in GOPATH mode + // Check list in testdata/full/some_test.go + goGet(t, "github.com/go-check/check") + goGet(t, "github.com/stretchr/testify/assert") + goGet(t, "github.com/stretchr/testify/require") + err := run(options{ pkgs: []string{"example.com/example"}, showLoaderErrors: true, From 97ac965ef945030c06a71bba07707f2b260c47bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Sun, 11 Jun 2023 23:51:13 +0200 Subject: [PATCH 2/3] assert/cmd/gty-migrate-from-testify: fix incorrect import path for go-check Fix incorrect import path for go-check in gty-migrate-from-testify test: github.com/go-check/check => gopkg.in/check.v1 --- assert/cmd/gty-migrate-from-testify/main_test.go | 2 +- .../testdata/full-expected/some_test.go | 2 +- assert/cmd/gty-migrate-from-testify/testdata/full/some_test.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/assert/cmd/gty-migrate-from-testify/main_test.go b/assert/cmd/gty-migrate-from-testify/main_test.go index dfc93d7..2d526c2 100644 --- a/assert/cmd/gty-migrate-from-testify/main_test.go +++ b/assert/cmd/gty-migrate-from-testify/main_test.go @@ -31,7 +31,7 @@ func TestRun(t *testing.T) { // Fetch dependencies in GOPATH mode // Check list in testdata/full/some_test.go - goGet(t, "github.com/go-check/check") + goGet(t, "gopkg.in/check.v1") goGet(t, "github.com/stretchr/testify/assert") goGet(t, "github.com/stretchr/testify/require") diff --git a/assert/cmd/gty-migrate-from-testify/testdata/full-expected/some_test.go b/assert/cmd/gty-migrate-from-testify/testdata/full-expected/some_test.go index 1cbdf0f..b0d450a 100644 --- a/assert/cmd/gty-migrate-from-testify/testdata/full-expected/some_test.go +++ b/assert/cmd/gty-migrate-from-testify/testdata/full-expected/some_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "github.com/go-check/check" + "gopkg.in/check.v1" "gotest.tools/v3/assert" "gotest.tools/v3/assert/cmp" ) diff --git a/assert/cmd/gty-migrate-from-testify/testdata/full/some_test.go b/assert/cmd/gty-migrate-from-testify/testdata/full/some_test.go index f510038..600ec8e 100644 --- a/assert/cmd/gty-migrate-from-testify/testdata/full/some_test.go +++ b/assert/cmd/gty-migrate-from-testify/testdata/full/some_test.go @@ -4,9 +4,9 @@ import ( "fmt" "testing" - "github.com/go-check/check" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "gopkg.in/check.v1" ) type mystruct struct { From fcde373fd36f2df6d120657d343b9eedbf15c69b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Mon, 12 Jun 2023 00:59:18 +0200 Subject: [PATCH 3/3] assert/cmd/gty-migrate-from-testify: fix use of gopkg.in/check.v1 in test Fix test to use the gopkg.in/check.v1 API correctly. The func TestWithChecker(c *check.C) was incompatible with "go test". --- .../testdata/full-expected/some_test.go | 8 ++++++-- .../gty-migrate-from-testify/testdata/full/some_test.go | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/assert/cmd/gty-migrate-from-testify/testdata/full-expected/some_test.go b/assert/cmd/gty-migrate-from-testify/testdata/full-expected/some_test.go index b0d450a..78ae524 100644 --- a/assert/cmd/gty-migrate-from-testify/testdata/full-expected/some_test.go +++ b/assert/cmd/gty-migrate-from-testify/testdata/full-expected/some_test.go @@ -134,9 +134,13 @@ func TestTableTest(t *testing.T) { } } -func TestWithChecker(c *check.C) { +type MySuite struct{} + +var _ = check.Suite(&MySuite{}) + +func (s *MySuite) TestWithChecker(c *check.C) { var err error - assert.Check(c, err) + c.Assert(err, check.Equals, nil) } func HelperWithAssertTestingT(t assert.TestingT) { diff --git a/assert/cmd/gty-migrate-from-testify/testdata/full/some_test.go b/assert/cmd/gty-migrate-from-testify/testdata/full/some_test.go index 600ec8e..f7adb02 100644 --- a/assert/cmd/gty-migrate-from-testify/testdata/full/some_test.go +++ b/assert/cmd/gty-migrate-from-testify/testdata/full/some_test.go @@ -135,9 +135,13 @@ func TestTableTest(t *testing.T) { } } -func TestWithChecker(c *check.C) { +type MySuite struct{} + +var _ = check.Suite(&MySuite{}) + +func (s *MySuite) TestWithChecker(c *check.C) { var err error - assert.NoError(c, err) + c.Assert(err, check.Equals, nil) } func HelperWithAssertTestingT(t assert.TestingT) {