Skip to content

Commit 809a710

Browse files
deiningehsandavari
andauthored
change interface{} to any (#1502)
Co-authored-by: ehsandavari <[email protected]>
1 parent f65e80b commit 809a710

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+286
-286
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ Ginkgo also uses this progress reporting infrastructure under the hood when hand
630630
### Features
631631
- `BeforeSuite`, `AfterSuite`, `SynchronizedBeforeSuite`, `SynchronizedAfterSuite`, and `ReportAfterSuite` now support (the relevant subset of) decorators. These can be passed in _after_ the callback functions that are usually passed into these nodes.
632632

633-
As a result the **signature of these methods has changed** and now includes a trailing `args ...interface{}`. For most users simply using the DSL, this change is transparent. However if you were assigning one of these functions to a custom variable (or passing it around) then your code may need to change to reflect the new signature.
633+
As a result the **signature of these methods has changed** and now includes a trailing `args ...any`. For most users simply using the DSL, this change is transparent. However if you were assigning one of these functions to a custom variable (or passing it around) then your code may need to change to reflect the new signature.
634634

635635
### Maintenance
636636
- Modernize the invocation of Ginkgo in github actions [0ffde58]

core_dsl.go

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ func exitIfErrors(errors []error) {
8383
type GinkgoWriterInterface interface {
8484
io.Writer
8585

86-
Print(a ...interface{})
87-
Printf(format string, a ...interface{})
88-
Println(a ...interface{})
86+
Print(a ...any)
87+
Printf(format string, a ...any)
88+
Println(a ...any)
8989

9090
TeeTo(writer io.Writer)
9191
ClearTeeWriters()
@@ -243,7 +243,7 @@ for more on how specs are parallelized in Ginkgo.
243243
244244
You can also pass suite-level Label() decorators to RunSpecs. The passed-in labels will apply to all specs in the suite.
245245
*/
246-
func RunSpecs(t GinkgoTestingT, description string, args ...interface{}) bool {
246+
func RunSpecs(t GinkgoTestingT, description string, args ...any) bool {
247247
if suiteDidRun {
248248
exitIfErr(types.GinkgoErrors.RerunningSuite())
249249
}
@@ -316,7 +316,7 @@ func RunSpecs(t GinkgoTestingT, description string, args ...interface{}) bool {
316316
return passed
317317
}
318318

319-
func extractSuiteConfiguration(args []interface{}) Labels {
319+
func extractSuiteConfiguration(args []any) Labels {
320320
suiteLabels := Labels{}
321321
configErrors := []error{}
322322
for _, arg := range args {
@@ -491,22 +491,22 @@ to Describe the behavior of an object or function and, within that Describe, out
491491
You can learn more at https://onsi.github.io/ginkgo/#organizing-specs-with-container-nodes
492492
In addition, container nodes can be decorated with a variety of decorators. You can learn more here: https://onsi.github.io/ginkgo/#decorator-reference
493493
*/
494-
func Describe(text string, args ...interface{}) bool {
494+
func Describe(text string, args ...any) bool {
495495
return pushNode(internal.NewNode(deprecationTracker, types.NodeTypeContainer, text, args...))
496496
}
497497

498498
/*
499499
FDescribe focuses specs within the Describe block.
500500
*/
501-
func FDescribe(text string, args ...interface{}) bool {
501+
func FDescribe(text string, args ...any) bool {
502502
args = append(args, internal.Focus)
503503
return pushNode(internal.NewNode(deprecationTracker, types.NodeTypeContainer, text, args...))
504504
}
505505

506506
/*
507507
PDescribe marks specs within the Describe block as pending.
508508
*/
509-
func PDescribe(text string, args ...interface{}) bool {
509+
func PDescribe(text string, args ...any) bool {
510510
args = append(args, internal.Pending)
511511
return pushNode(internal.NewNode(deprecationTracker, types.NodeTypeContainer, text, args...))
512512
}
@@ -522,18 +522,18 @@ var XDescribe = PDescribe
522522
var Context, FContext, PContext, XContext = Describe, FDescribe, PDescribe, XDescribe
523523

524524
/* When is an alias for Describe - it generates the exact same kind of Container node */
525-
func When(text string, args ...interface{}) bool {
525+
func When(text string, args ...any) bool {
526526
return pushNode(internal.NewNode(deprecationTracker, types.NodeTypeContainer, "when "+text, args...))
527527
}
528528

529529
/* When is an alias for Describe - it generates the exact same kind of Container node */
530-
func FWhen(text string, args ...interface{}) bool {
530+
func FWhen(text string, args ...any) bool {
531531
args = append(args, internal.Focus)
532532
return pushNode(internal.NewNode(deprecationTracker, types.NodeTypeContainer, "when "+text, args...))
533533
}
534534

535535
/* When is an alias for Describe - it generates the exact same kind of Container node */
536-
func PWhen(text string, args ...interface{}) bool {
536+
func PWhen(text string, args ...any) bool {
537537
args = append(args, internal.Pending)
538538
return pushNode(internal.NewNode(deprecationTracker, types.NodeTypeContainer, "when "+text, args...))
539539
}
@@ -550,22 +550,22 @@ You can pass It nodes bare functions (func() {}) or functions that receive a Spe
550550
You can learn more at https://onsi.github.io/ginkgo/#spec-subjects-it
551551
In addition, subject nodes can be decorated with a variety of decorators. You can learn more here: https://onsi.github.io/ginkgo/#decorator-reference
552552
*/
553-
func It(text string, args ...interface{}) bool {
553+
func It(text string, args ...any) bool {
554554
return pushNode(internal.NewNode(deprecationTracker, types.NodeTypeIt, text, args...))
555555
}
556556

557557
/*
558558
FIt allows you to focus an individual It.
559559
*/
560-
func FIt(text string, args ...interface{}) bool {
560+
func FIt(text string, args ...any) bool {
561561
args = append(args, internal.Focus)
562562
return pushNode(internal.NewNode(deprecationTracker, types.NodeTypeIt, text, args...))
563563
}
564564

565565
/*
566566
PIt allows you to mark an individual It as pending.
567567
*/
568-
func PIt(text string, args ...interface{}) bool {
568+
func PIt(text string, args ...any) bool {
569569
args = append(args, internal.Pending)
570570
return pushNode(internal.NewNode(deprecationTracker, types.NodeTypeIt, text, args...))
571571
}
@@ -611,8 +611,8 @@ BeforeSuite can take a func() body, or an interruptible func(SpecContext)/func(c
611611
You cannot nest any other Ginkgo nodes within a BeforeSuite node's closure.
612612
You can learn more here: https://onsi.github.io/ginkgo/#suite-setup-and-cleanup-beforesuite-and-aftersuite
613613
*/
614-
func BeforeSuite(body interface{}, args ...interface{}) bool {
615-
combinedArgs := []interface{}{body}
614+
func BeforeSuite(body any, args ...any) bool {
615+
combinedArgs := []any{body}
616616
combinedArgs = append(combinedArgs, args...)
617617
return pushNode(internal.NewNode(deprecationTracker, types.NodeTypeBeforeSuite, "", combinedArgs...))
618618
}
@@ -630,8 +630,8 @@ AfterSuite can take a func() body, or an interruptible func(SpecContext)/func(co
630630
You cannot nest any other Ginkgo nodes within an AfterSuite node's closure.
631631
You can learn more here: https://onsi.github.io/ginkgo/#suite-setup-and-cleanup-beforesuite-and-aftersuite
632632
*/
633-
func AfterSuite(body interface{}, args ...interface{}) bool {
634-
combinedArgs := []interface{}{body}
633+
func AfterSuite(body any, args ...any) bool {
634+
combinedArgs := []any{body}
635635
combinedArgs = append(combinedArgs, args...)
636636
return pushNode(internal.NewNode(deprecationTracker, types.NodeTypeAfterSuite, "", combinedArgs...))
637637
}
@@ -667,8 +667,8 @@ If either function receives a context.Context/SpecContext it is considered inter
667667
You cannot nest any other Ginkgo nodes within an SynchronizedBeforeSuite node's closure.
668668
You can learn more, and see some examples, here: https://onsi.github.io/ginkgo/#parallel-suite-setup-and-cleanup-synchronizedbeforesuite-and-synchronizedaftersuite
669669
*/
670-
func SynchronizedBeforeSuite(process1Body interface{}, allProcessBody interface{}, args ...interface{}) bool {
671-
combinedArgs := []interface{}{process1Body, allProcessBody}
670+
func SynchronizedBeforeSuite(process1Body any, allProcessBody any, args ...any) bool {
671+
combinedArgs := []any{process1Body, allProcessBody}
672672
combinedArgs = append(combinedArgs, args...)
673673

674674
return pushNode(internal.NewNode(deprecationTracker, types.NodeTypeSynchronizedBeforeSuite, "", combinedArgs...))
@@ -687,8 +687,8 @@ Note that you can also use DeferCleanup() in SynchronizedBeforeSuite to accompli
687687
You cannot nest any other Ginkgo nodes within an SynchronizedAfterSuite node's closure.
688688
You can learn more, and see some examples, here: https://onsi.github.io/ginkgo/#parallel-suite-setup-and-cleanup-synchronizedbeforesuite-and-synchronizedaftersuite
689689
*/
690-
func SynchronizedAfterSuite(allProcessBody interface{}, process1Body interface{}, args ...interface{}) bool {
691-
combinedArgs := []interface{}{allProcessBody, process1Body}
690+
func SynchronizedAfterSuite(allProcessBody any, process1Body any, args ...any) bool {
691+
combinedArgs := []any{allProcessBody, process1Body}
692692
combinedArgs = append(combinedArgs, args...)
693693

694694
return pushNode(internal.NewNode(deprecationTracker, types.NodeTypeSynchronizedAfterSuite, "", combinedArgs...))
@@ -703,7 +703,7 @@ BeforeEach can take a func() body, or an interruptible func(SpecContext)/func(co
703703
You cannot nest any other Ginkgo nodes within a BeforeEach node's closure.
704704
You can learn more here: https://onsi.github.io/ginkgo/#extracting-common-setup-beforeeach
705705
*/
706-
func BeforeEach(args ...interface{}) bool {
706+
func BeforeEach(args ...any) bool {
707707
return pushNode(internal.NewNode(deprecationTracker, types.NodeTypeBeforeEach, "", args...))
708708
}
709709

@@ -716,7 +716,7 @@ JustBeforeEach can take a func() body, or an interruptible func(SpecContext)/fun
716716
You cannot nest any other Ginkgo nodes within a JustBeforeEach node's closure.
717717
You can learn more and see some examples here: https://onsi.github.io/ginkgo/#separating-creation-and-configuration-justbeforeeach
718718
*/
719-
func JustBeforeEach(args ...interface{}) bool {
719+
func JustBeforeEach(args ...any) bool {
720720
return pushNode(internal.NewNode(deprecationTracker, types.NodeTypeJustBeforeEach, "", args...))
721721
}
722722

@@ -731,7 +731,7 @@ AfterEach can take a func() body, or an interruptible func(SpecContext)/func(con
731731
You cannot nest any other Ginkgo nodes within an AfterEach node's closure.
732732
You can learn more here: https://onsi.github.io/ginkgo/#spec-cleanup-aftereach-and-defercleanup
733733
*/
734-
func AfterEach(args ...interface{}) bool {
734+
func AfterEach(args ...any) bool {
735735
return pushNode(internal.NewNode(deprecationTracker, types.NodeTypeAfterEach, "", args...))
736736
}
737737

@@ -743,7 +743,7 @@ JustAfterEach can take a func() body, or an interruptible func(SpecContext)/func
743743
You cannot nest any other Ginkgo nodes within a JustAfterEach node's closure.
744744
You can learn more and see some examples here: https://onsi.github.io/ginkgo/#separating-diagnostics-collection-and-teardown-justaftereach
745745
*/
746-
func JustAfterEach(args ...interface{}) bool {
746+
func JustAfterEach(args ...any) bool {
747747
return pushNode(internal.NewNode(deprecationTracker, types.NodeTypeJustAfterEach, "", args...))
748748
}
749749

@@ -758,7 +758,7 @@ You cannot nest any other Ginkgo nodes within a BeforeAll node's closure.
758758
You can learn more about Ordered Containers at: https://onsi.github.io/ginkgo/#ordered-containers
759759
And you can learn more about BeforeAll at: https://onsi.github.io/ginkgo/#setup-in-ordered-containers-beforeall-and-afterall
760760
*/
761-
func BeforeAll(args ...interface{}) bool {
761+
func BeforeAll(args ...any) bool {
762762
return pushNode(internal.NewNode(deprecationTracker, types.NodeTypeBeforeAll, "", args...))
763763
}
764764

@@ -775,7 +775,7 @@ You cannot nest any other Ginkgo nodes within an AfterAll node's closure.
775775
You can learn more about Ordered Containers at: https://onsi.github.io/ginkgo/#ordered-containers
776776
And you can learn more about AfterAll at: https://onsi.github.io/ginkgo/#setup-in-ordered-containers-beforeall-and-afterall
777777
*/
778-
func AfterAll(args ...interface{}) bool {
778+
func AfterAll(args ...any) bool {
779779
return pushNode(internal.NewNode(deprecationTracker, types.NodeTypeAfterAll, "", args...))
780780
}
781781

@@ -818,7 +818,7 @@ When DeferCleanup is called in BeforeSuite, SynchronizedBeforeSuite, AfterSuite,
818818
Note that DeferCleanup does not represent a node but rather dynamically generates the appropriate type of cleanup node based on the context in which it is called. As such you must call DeferCleanup within a Setup or Subject node, and not within a Container node.
819819
You can learn more about DeferCleanup here: https://onsi.github.io/ginkgo/#cleaning-up-our-cleanup-code-defercleanup
820820
*/
821-
func DeferCleanup(args ...interface{}) {
821+
func DeferCleanup(args ...any) {
822822
fail := func(message string, cl types.CodeLocation) {
823823
global.Failer.Fail(message, cl)
824824
}

deprecated_dsl.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ Use Gomega's gmeasure package instead.
118118
You can learn more here: https://onsi.github.io/ginkgo/#benchmarking-code
119119
*/
120120
type Benchmarker interface {
121-
Time(name string, body func(), info ...interface{}) (elapsedTime time.Duration)
122-
RecordValue(name string, value float64, info ...interface{})
123-
RecordValueWithPrecision(name string, value float64, units string, precision int, info ...interface{})
121+
Time(name string, body func(), info ...any) (elapsedTime time.Duration)
122+
RecordValue(name string, value float64, info ...any)
123+
RecordValueWithPrecision(name string, value float64, units string, precision int, info ...any)
124124
}
125125

126126
/*
@@ -129,7 +129,7 @@ Deprecated: Measure() has been removed from Ginkgo 2.0
129129
Use Gomega's gmeasure package instead.
130130
You can learn more here: https://onsi.github.io/ginkgo/#benchmarking-code
131131
*/
132-
func Measure(_ ...interface{}) bool {
132+
func Measure(_ ...any) bool {
133133
deprecationTracker.TrackDeprecation(types.Deprecations.Measure(), types.NewCodeLocation(1))
134134
return true
135135
}

docs/MIGRATING_TO_V2.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ Specs can now be decorated with a series of new spec decorators. These decorato
5959
To support decorators, the signature for Ginkgo's container, setup, and It nodes have been changed to:
6060

6161
```go
62-
func Describe(text string, args ...interface{})
63-
func It(text string, args ...interface{})
64-
func BeforeEach(args ...interface{})
62+
func Describe(text string, args ...any)
63+
func It(text string, args ...any)
64+
func BeforeEach(args ...any)
6565
```
6666
Note that this change is backwards compatible with v1.X.
6767

@@ -234,7 +234,7 @@ Ginkgo's CLI flags have been rewritten to provide clearer, better-organized docu
234234
The `GinkgoWriter` is used to write output that is only made visible if a test fails, or if the user runs in verbose mode with `ginkgo -v`.
235235

236236
In Ginkgo 2.0 `GinkgoWriter` now has:
237-
- Three new convenience methods `GinkgoWriter.Print(a ...interface{})`, `GinkgoWriter.Println(a ...interface{})`, `GinkgoWriter.Printf(format string, a ...interface{})` These are equivalent to calling the associated `fmt.Fprint*` functions and passing in `GinkgoWriter`.
237+
- Three new convenience methods `GinkgoWriter.Print(a ...any)`, `GinkgoWriter.Println(a ...any)`, `GinkgoWriter.Printf(format string, a ...any)` These are equivalent to calling the associated `fmt.Fprint*` functions and passing in `GinkgoWriter`.
238238
- The ability to tee to additional writers. `GinkgoWriter.TeeTo(writer)` will send any future data written to `GinkgoWriter` to the passed in `writer`. You can attach multiple `io.Writer`s for `GinkgoWriter` to tee to. You can remove all attached writers with `GinkgoWriter.ClearTeeWriters()`.
239239

240240
Note that _all_ data written to `GinkgoWriter` is immediately forwarded to attached tee writers regardless of where a test passes or fails.
@@ -293,14 +293,14 @@ Ginkgo V2 supports attaching arbitrary data to individual spec reports. These a
293293
You attach data to a spec report via
294294

295295
```go
296-
AddReportEntry(name string, args ...interface{})
296+
AddReportEntry(name string, args ...any)
297297
```
298298

299299
`AddReportEntry` can be called from any runnable node (e.g. `It`, `BeforeEach`, `BeforeSuite`) - but not from the body of a container node (e.g. `Describe`, `Context`).
300300

301301
`AddReportEntry` generates `ReportEntry` and attaches it to the current running spec. `ReportEntry` includes the passed in `name` as well as the time and source location at which `AddReportEntry` was called. Users can also attach a single object of arbitrary type to the `ReportEntry` by passing it into `AddReportEntry` - this object is wrapped and stored under `ReportEntry.Value` and is always included in the suite's JSON report.
302302

303-
You can access the report entries attached to a spec by getting the `CurrentSpecReport()` or registering a `ReportAfterEach()` - the returned report will include the attached `ReportEntries`. You can fetch the value associated with the `ReportEntry` by calling `entry.GetRawValue()`. When called in-process this returns the object that was passed to `AddReportEntry`. When called after hydrating a report from JSON `entry.GetRawValue()` will include a parsed JSON `interface{}` - if you want to hydrate the JSON yourself into an object of known type you can `json.Unmarshal([]byte(entry.Value.AsJSON), &object)`.
303+
You can access the report entries attached to a spec by getting the `CurrentSpecReport()` or registering a `ReportAfterEach()` - the returned report will include the attached `ReportEntries`. You can fetch the value associated with the `ReportEntry` by calling `entry.GetRawValue()`. When called in-process this returns the object that was passed to `AddReportEntry`. When called after hydrating a report from JSON `entry.GetRawValue()` will include a parsed JSON `any` - if you want to hydrate the JSON yourself into an object of known type you can `json.Unmarshal([]byte(entry.Value.AsJSON), &object)`.
304304

305305
#### Supported Args
306306
`AddReportEntry` supports the `Offset` and `CodeLocation` decorators. These will control the source code location associated with the generated `ReportEntry`. You can also pass in a `time.Time` to override the `ReportEntry`'s timestamp. It also supports passing in a `ReportEntryVisibility` enum to control the report's visibility (see below).

0 commit comments

Comments
 (0)