From 63670232e7e6c17d3690f35db72f080f9b9656dc Mon Sep 17 00:00:00 2001 From: "Sean R. Abraham" Date: Tue, 4 Apr 2023 10:12:57 -0600 Subject: [PATCH] upgrade deps, update to go 1.18 go 1.18 is the most recent supported version of Go, so it seems reasonable to upgrade to that. This upgrade is needed to pull in the latest version of smartystreets/assertions, which I want in here for this fix of mine: https://github.com/smartystreets/assertions/commit/a83f75f344d7f8c0681e5c699c5f747cd41cd93f This also replaces all "interface{}" with "any", since go 1.18 added that. That was already done in the assertions repo the other day. Note that this command passes: go test -timeout=1s -race -cover -short -count=1 ./... but the integration test file fails. That failure is already in the repo at HEAD though. --- convey/context.go | 24 +++++++-------- convey/discovery.go | 16 +++++----- convey/doc.go | 38 ++++++++++++------------ convey/reporting/printer.go | 6 ++-- convey/reporting/reports.go | 4 +-- convey/reporting_hooks_test.go | 4 +-- convey/story_conventions_test.go | 2 +- go.mod | 13 +++++--- go.sum | 21 ++++++------- web/server/parser/package_parser_test.go | 2 +- 10 files changed, 68 insertions(+), 62 deletions(-) diff --git a/convey/context.go b/convey/context.go index 4b0d28dc..626cc4c6 100644 --- a/convey/context.go +++ b/convey/context.go @@ -9,14 +9,14 @@ import ( type conveyErr struct { fmt string - params []interface{} + params []any } func (e *conveyErr) Error() string { return fmt.Sprintf(e.fmt, e.params...) } -func conveyPanic(fmt string, params ...interface{}) { +func conveyPanic(fmt string, params ...any) { panic(&conveyErr{fmt, params}) } @@ -85,7 +85,7 @@ type context struct { // rootConvey is the main entry point to a test suite. This is called when // there's no context in the stack already, and items must contain a `t` object, // or this panics. -func rootConvey(items ...interface{}) { +func rootConvey(items ...any) { entry := discover(items) if entry.Test == nil { @@ -117,15 +117,15 @@ func rootConvey(items ...interface{}) { //////////////////////////////////// Methods //////////////////////////////////// -func (ctx *context) SkipConvey(items ...interface{}) { +func (ctx *context) SkipConvey(items ...any) { ctx.Convey(items, skipConvey) } -func (ctx *context) FocusConvey(items ...interface{}) { +func (ctx *context) FocusConvey(items ...any) { ctx.Convey(items, focusConvey) } -func (ctx *context) Convey(items ...interface{}) { +func (ctx *context) Convey(items ...any) { entry := discover(items) // we're a branch, or leaf (on the wind) @@ -168,11 +168,11 @@ func (ctx *context) Convey(items ...interface{}) { } } -func (ctx *context) SkipSo(stuff ...interface{}) { +func (ctx *context) SkipSo(stuff ...any) { ctx.assertionReport(reporting.NewSkipReport()) } -func (ctx *context) So(actual interface{}, assert Assertion, expected ...interface{}) { +func (ctx *context) So(actual any, assert Assertion, expected ...any) { if result := assert(actual, expected...); result == assertionSuccess { ctx.assertionReport(reporting.NewSuccessReport()) } else { @@ -180,7 +180,7 @@ func (ctx *context) So(actual interface{}, assert Assertion, expected ...interfa } } -func (ctx *context) SoMsg(msg string, actual interface{}, assert Assertion, expected ...interface{}) { +func (ctx *context) SoMsg(msg string, actual any, assert Assertion, expected ...any) { if result := assert(actual, expected...); result == assertionSuccess { ctx.assertionReport(reporting.NewSuccessReport()) return @@ -196,17 +196,17 @@ func (ctx *context) Reset(action func()) { ctx.resets = append(ctx.resets, action) } -func (ctx *context) Print(items ...interface{}) (int, error) { +func (ctx *context) Print(items ...any) (int, error) { fmt.Fprint(ctx.reporter, items...) return fmt.Print(items...) } -func (ctx *context) Println(items ...interface{}) (int, error) { +func (ctx *context) Println(items ...any) (int, error) { fmt.Fprintln(ctx.reporter, items...) return fmt.Println(items...) } -func (ctx *context) Printf(format string, items ...interface{}) (int, error) { +func (ctx *context) Printf(format string, items ...any) (int, error) { fmt.Fprintf(ctx.reporter, format, items...) return fmt.Printf(format, items...) } diff --git a/convey/discovery.go b/convey/discovery.go index 5e6d1f68..4694d10d 100644 --- a/convey/discovery.go +++ b/convey/discovery.go @@ -34,7 +34,7 @@ func newSuite(situation string, failureMode FailureMode, stackMode StackMode, f return ret } -func discover(items []interface{}) *suite { +func discover(items []any) *suite { name, items := parseName(items) test, items := parseGoTest(items) failure, items := parseFailureMode(items) @@ -48,38 +48,38 @@ func discover(items []interface{}) *suite { return newSuite(name, failure, stack, action, test, specifier) } -func item(items []interface{}) interface{} { +func item(items []any) any { if len(items) == 0 { conveyPanic(parseError) } return items[0] } -func parseName(items []interface{}) (string, []interface{}) { +func parseName(items []any) (string, []any) { if name, parsed := item(items).(string); parsed { return name, items[1:] } conveyPanic(parseError) panic("never get here") } -func parseGoTest(items []interface{}) (t, []interface{}) { +func parseGoTest(items []any) (t, []any) { if test, parsed := item(items).(t); parsed { return test, items[1:] } return nil, items } -func parseFailureMode(items []interface{}) (FailureMode, []interface{}) { +func parseFailureMode(items []any) (FailureMode, []any) { if mode, parsed := item(items).(FailureMode); parsed { return mode, items[1:] } return FailureInherits, items } -func parseStackMode(items []interface{}) (StackMode, []interface{}) { +func parseStackMode(items []any) (StackMode, []any) { if mode, parsed := item(items).(StackMode); parsed { return mode, items[1:] } return StackInherits, items } -func parseAction(items []interface{}) (func(C), []interface{}) { +func parseAction(items []any) (func(C), []any) { switch x := item(items).(type) { case nil: return nil, items[1:] @@ -91,7 +91,7 @@ func parseAction(items []interface{}) (func(C), []interface{}) { conveyPanic(parseError) panic("never get here") } -func parseSpecifier(items []interface{}) (actionSpecifier, []interface{}) { +func parseSpecifier(items []any) (actionSpecifier, []any) { if len(items) == 0 { return noSpecifier, items } diff --git a/convey/doc.go b/convey/doc.go index b8522358..2a9d55d1 100644 --- a/convey/doc.go +++ b/convey/doc.go @@ -19,19 +19,19 @@ import "github.com/smartystreets/goconvey/convey/reporting" // All methods in this context behave identically to the global functions of the // same name in this package. type C interface { - Convey(items ...interface{}) - SkipConvey(items ...interface{}) - FocusConvey(items ...interface{}) + Convey(items ...any) + SkipConvey(items ...any) + FocusConvey(items ...any) - So(actual interface{}, assert Assertion, expected ...interface{}) - SoMsg(msg string, actual interface{}, assert Assertion, expected ...interface{}) - SkipSo(stuff ...interface{}) + So(actual any, assert Assertion, expected ...any) + SoMsg(msg string, actual any, assert Assertion, expected ...any) + SkipSo(stuff ...any) Reset(action func()) - Println(items ...interface{}) (int, error) - Print(items ...interface{}) (int, error) - Printf(format string, items ...interface{}) (int, error) + Println(items ...any) (int, error) + Print(items ...any) (int, error) + Printf(format string, items ...any) (int, error) } // Convey is the method intended for use when declaring the scopes of @@ -71,7 +71,7 @@ type C interface { // Convey(description string, mode FailureMode, action func()) // // See the examples package for, well, examples. -func Convey(items ...interface{}) { +func Convey(items ...any) { if ctx := getCurrentContext(); ctx == nil { rootConvey(items...) } else { @@ -82,7 +82,7 @@ func Convey(items ...interface{}) { // SkipConvey is analogous to Convey except that the scope is not executed // (which means that child scopes defined within this scope are not run either). // The reporter will be notified that this step was skipped. -func SkipConvey(items ...interface{}) { +func SkipConvey(items ...any) { Convey(append(items, skipConvey)...) } @@ -93,7 +93,7 @@ func SkipConvey(items ...interface{}) { // repeatedly as you can disable all but one of that function // without swaths of `SkipConvey` calls, just a targeted chain of calls // to FocusConvey. -func FocusConvey(items ...interface{}) { +func FocusConvey(items ...any) { Convey(append(items, focusConvey)...) } @@ -109,7 +109,7 @@ func Reset(action func()) { // method can handle. Any future or custom assertions should conform to this // method signature. The return value should be an empty string if the assertion // passes and a well-formed failure message if not. -type Assertion func(actual interface{}, expected ...interface{}) string +type Assertion func(actual any, expected ...any) string const assertionSuccess = "" @@ -122,18 +122,18 @@ const assertionSuccess = "" // documentation on specific assertion methods. A failing assertion will // cause t.Fail() to be invoked--you should never call this method (or other // failure-inducing methods) in your test code. Leave that to GoConvey. -func So(actual interface{}, assert Assertion, expected ...interface{}) { +func So(actual any, assert Assertion, expected ...any) { mustGetCurrentContext().So(actual, assert, expected...) } // SoMsg is an extension of So that allows you to specify a message to report on error. -func SoMsg(msg string, actual interface{}, assert Assertion, expected ...interface{}) { +func SoMsg(msg string, actual any, assert Assertion, expected ...any) { mustGetCurrentContext().SoMsg(msg, actual, assert, expected...) } // SkipSo is analogous to So except that the assertion that would have been passed // to So is not executed and the reporter is notified that the assertion was skipped. -func SkipSo(stuff ...interface{}) { +func SkipSo(stuff ...any) { mustGetCurrentContext().SkipSo() } @@ -222,19 +222,19 @@ func SetDefaultStackMode(mode StackMode) { // Print is analogous to fmt.Print (and it even calls fmt.Print). It ensures that // output is aligned with the corresponding scopes in the web UI. -func Print(items ...interface{}) (written int, err error) { +func Print(items ...any) (written int, err error) { return mustGetCurrentContext().Print(items...) } // Print is analogous to fmt.Println (and it even calls fmt.Println). It ensures that // output is aligned with the corresponding scopes in the web UI. -func Println(items ...interface{}) (written int, err error) { +func Println(items ...any) (written int, err error) { return mustGetCurrentContext().Println(items...) } // Print is analogous to fmt.Printf (and it even calls fmt.Printf). It ensures that // output is aligned with the corresponding scopes in the web UI. -func Printf(format string, items ...interface{}) (written int, err error) { +func Printf(format string, items ...any) (written int, err error) { return mustGetCurrentContext().Printf(format, items...) } diff --git a/convey/reporting/printer.go b/convey/reporting/printer.go index 3dac0d4d..e4bd8bac 100644 --- a/convey/reporting/printer.go +++ b/convey/reporting/printer.go @@ -11,12 +11,12 @@ type Printer struct { prefix string } -func (self *Printer) Println(message string, values ...interface{}) { +func (self *Printer) Println(message string, values ...any) { formatted := self.format(message, values...) + newline self.out.Write([]byte(formatted)) } -func (self *Printer) Print(message string, values ...interface{}) { +func (self *Printer) Print(message string, values ...any) { formatted := self.format(message, values...) self.out.Write([]byte(formatted)) } @@ -25,7 +25,7 @@ func (self *Printer) Insert(text string) { self.out.Write([]byte(text)) } -func (self *Printer) format(message string, values ...interface{}) string { +func (self *Printer) format(message string, values ...any) string { var formatted string if len(values) == 0 { formatted = self.prefix + message diff --git a/convey/reporting/reports.go b/convey/reporting/reports.go index f30789f6..7a650197 100644 --- a/convey/reporting/reports.go +++ b/convey/reporting/reports.go @@ -92,7 +92,7 @@ type AssertionResult struct { Expected string Actual string Failure string - Error interface{} + Error any StackTrace string Skipped bool } @@ -117,7 +117,7 @@ func parseFailure(failure string, report *AssertionResult) { report.Failure = failure } } -func NewErrorReport(err interface{}) *AssertionResult { +func NewErrorReport(err any) *AssertionResult { report := new(AssertionResult) report.File, report.Line = caller() report.StackTrace = fullStackTrace() diff --git a/convey/reporting_hooks_test.go b/convey/reporting_hooks_test.go index 69125c3c..a9ea6c5d 100644 --- a/convey/reporting_hooks_test.go +++ b/convey/reporting_hooks_test.go @@ -248,7 +248,7 @@ func TestEmbeddedContextHelperReported(t *testing.T) { expectEqual(t, "Begin|A|Embedded|Success|Exit|Exit|End", myReporter.wholeStory()) } -func expectEqual(t *testing.T, expected interface{}, actual interface{}) { +func expectEqual(t *testing.T, expected any, actual any) { if expected != actual { _, file, line, _ := runtime.Caller(1) t.Errorf("Expected '%v' to be '%v' but it wasn't. See '%s' at line %d.", @@ -312,6 +312,6 @@ func (self *fakeReporter) wholeStory() string { type fakeGoTest struct{} func (self *fakeGoTest) Fail() {} -func (self *fakeGoTest) Fatalf(format string, args ...interface{}) {} +func (self *fakeGoTest) Fatalf(format string, args ...any) {} var test t = new(fakeGoTest) diff --git a/convey/story_conventions_test.go b/convey/story_conventions_test.go index 7bdd3986..acb00a06 100644 --- a/convey/story_conventions_test.go +++ b/convey/story_conventions_test.go @@ -5,7 +5,7 @@ import ( "testing" ) -func expectPanic(t *testing.T, f string) interface{} { +func expectPanic(t *testing.T, f string) any { r := recover() if r != nil { if cp, ok := r.(*conveyErr); ok { diff --git a/go.mod b/go.mod index 3c3b799e..6d2e0379 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,15 @@ module github.com/smartystreets/goconvey -go 1.16 +go 1.18 require ( - github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 // indirect github.com/jtolds/gls v4.20.0+incompatible - github.com/smartystreets/assertions v1.2.0 - golang.org/x/tools v0.0.0-20190328211700-ab21143f2384 + github.com/smartystreets/assertions v1.13.1 + golang.org/x/tools v0.7.0 +) + +require ( + github.com/gopherjs/gopherjs v1.17.2 // indirect + golang.org/x/mod v0.9.0 // indirect + golang.org/x/sys v0.6.0 // indirect ) diff --git a/go.sum b/go.sum index b226275f..e77d0632 100644 --- a/go.sum +++ b/go.sum @@ -1,12 +1,13 @@ -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g= +github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= -github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs= -github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/tools v0.0.0-20190328211700-ab21143f2384 h1:TFlARGu6Czu1z7q93HTxcP1P+/ZFC/IKythI5RzrnRg= -golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +github.com/smartystreets/assertions v1.13.1 h1:Ef7KhSmjZcK6AVf9YbJdvPYG9avaF0ZxudX+ThRdWfU= +github.com/smartystreets/assertions v1.13.1/go.mod h1:cXr/IwVfSo/RbCSPhoAPv73p3hlSdrBH/b3SdnW/LMY= +golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs= +golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= +golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4= +golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s= diff --git a/web/server/parser/package_parser_test.go b/web/server/parser/package_parser_test.go index 0fe04c77..25130bdc 100644 --- a/web/server/parser/package_parser_test.go +++ b/web/server/parser/package_parser_test.go @@ -150,7 +150,7 @@ func TestParsePackage_Golang17Subtests_ReturnsPackageResult(t *testing.T) { assertEqual(t, expectedGolang17Subtests, *actual) } -func assertEqual(t *testing.T, expected, actual interface{}) { +func assertEqual(t *testing.T, expected, actual any) { a, _ := json.Marshal(expected) b, _ := json.Marshal(actual) if string(a) != string(b) {