-
-
Notifications
You must be signed in to change notification settings - Fork 650
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce new DSL packages to enable users to pick-and-choose which p…
…ortions of the DSL to dot-import.
- Loading branch information
Showing
10 changed files
with
364 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
Ginkgo isusually dot-imported via: | ||
import . "github.com/onsi/ginkgo/v2" | ||
however some parts of the DSL may conflict with existing symbols in the user's code. | ||
To mitigate this without losing the brevity of dot-importing Ginkgo the various packages in the | ||
dsl directory provide pieces of the Ginkgo DSL that can be dot-imported separately. | ||
This "core" package pulls in the core Ginkgo DSL - most test suites will only need to import this package. | ||
*/ | ||
package core | ||
|
||
import ( | ||
"github.com/onsi/ginkgo/v2" | ||
) | ||
|
||
const GINKGO_VERSION = ginkgo.GINKGO_VERSION | ||
|
||
type GinkgoWriterInterface = ginkgo.GinkgoWriterInterface | ||
type GinkgoTestingT = ginkgo.GinkgoTestingT | ||
type GinkgoTInterface = ginkgo.GinkgoTInterface | ||
|
||
var GinkgoWriter = ginkgo.GinkgoWriter | ||
var GinkgoConfiguration = ginkgo.GinkgoConfiguration | ||
var GinkgoRandomSeed = ginkgo.GinkgoRandomSeed | ||
var GinkgoParallelProcess = ginkgo.GinkgoParallelProcess | ||
var PauseOutputInterception = ginkgo.PauseOutputInterception | ||
var ResumeOutputInterception = ginkgo.ResumeOutputInterception | ||
var RunSpecs = ginkgo.RunSpecs | ||
var Skip = ginkgo.Skip | ||
var Fail = ginkgo.Fail | ||
var AbortSuite = ginkgo.AbortSuite | ||
var GinkgoRecover = ginkgo.GinkgoRecover | ||
var Describe = ginkgo.Describe | ||
var FDescribe = ginkgo.FDescribe | ||
var PDescribe = ginkgo.PDescribe | ||
var XDescribe = PDescribe | ||
var Context, FContext, PContext, XContext = Describe, FDescribe, PDescribe, XDescribe | ||
var When, FWhen, PWhen, XWhen = Describe, FDescribe, PDescribe, XDescribe | ||
var It = ginkgo.It | ||
var FIt = ginkgo.FIt | ||
var PIt = ginkgo.PIt | ||
var XIt = PIt | ||
var Specify, FSpecify, PSpecify, XSpecify = It, FIt, PIt, XIt | ||
var By = ginkgo.By | ||
var BeforeSuite = ginkgo.BeforeSuite | ||
var AfterSuite = ginkgo.AfterSuite | ||
var SynchronizedBeforeSuite = ginkgo.SynchronizedBeforeSuite | ||
var SynchronizedAfterSuite = ginkgo.SynchronizedAfterSuite | ||
var BeforeEach = ginkgo.BeforeEach | ||
var JustBeforeEach = ginkgo.JustBeforeEach | ||
var AfterEach = ginkgo.AfterEach | ||
var JustAfterEach = ginkgo.JustAfterEach | ||
var BeforeAll = ginkgo.BeforeAll | ||
var AfterAll = ginkgo.AfterAll | ||
var DeferCleanup = ginkgo.DeferCleanup | ||
var GinkgoT = ginkgo.GinkgoT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
Ginkgo isusually dot-imported via: | ||
import . "github.com/onsi/ginkgo/v2" | ||
however some parts of the DSL may conflict with existing symbols in the user's code. | ||
To mitigate this without losing the brevity of dot-importing Ginkgo the various packages in the | ||
dsl directory provide pieces of the Ginkgo DSL that can be dot-imported separately. | ||
This "decorators" package pulls in the various decorators defined in the Ginkgo DSL. | ||
*/ | ||
package decorators | ||
|
||
import ( | ||
"github.com/onsi/ginkgo/v2" | ||
) | ||
|
||
type Offset = ginkgo.Offset | ||
type FlakeAttempts = ginkgo.FlakeAttempts | ||
type Labels = ginkgo.Labels | ||
|
||
const Focus = ginkgo.Focus | ||
const Pending = ginkgo.Pending | ||
const Serial = ginkgo.Serial | ||
const Ordered = ginkgo.Ordered | ||
const OncePerOrdered = ginkgo.OncePerOrdered | ||
|
||
var Label = ginkgo.Label |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package dsl_test | ||
|
||
import ( | ||
"go/ast" | ||
"go/parser" | ||
"go/token" | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestDSL(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "DSL Suite") | ||
} | ||
|
||
func ExtractSymbols(f *ast.File) []string { | ||
symbols := []string{} | ||
for _, decl := range f.Decls { | ||
names := []string{} | ||
switch v := decl.(type) { | ||
case *ast.FuncDecl: | ||
names = append(names, v.Name.Name) | ||
case *ast.GenDecl: | ||
switch v.Tok { | ||
case token.TYPE: | ||
s := v.Specs[0].(*ast.TypeSpec) | ||
names = append(names, s.Name.Name) | ||
case token.CONST, token.VAR: | ||
s := v.Specs[0].(*ast.ValueSpec) | ||
for _, n := range s.Names { | ||
names = append(names, n.Name) | ||
} | ||
} | ||
} | ||
for _, name := range names { | ||
if ast.IsExported(name) { | ||
symbols = append(symbols, name) | ||
} | ||
} | ||
} | ||
return symbols | ||
} | ||
|
||
var _ = It("ensures complete coverage of the core dsl", func() { | ||
fset := token.NewFileSet() | ||
pkgs, err := parser.ParseDir(fset, "../", nil, 0) | ||
Ω(err).ShouldNot(HaveOccurred()) | ||
expectedSymbols := []string{} | ||
for fn, file := range pkgs["ginkgo"].Files { | ||
if fn == "../deprecated_dsl.go" { | ||
continue | ||
} | ||
expectedSymbols = append(expectedSymbols, ExtractSymbols(file)...) | ||
} | ||
|
||
actualSymbols := []string{} | ||
for _, pkg := range []string{"core", "reporting", "decorators", "table"} { | ||
pkgs, err := parser.ParseDir(fset, "./"+pkg, nil, 0) | ||
Ω(err).ShouldNot(HaveOccurred()) | ||
for _, file := range pkgs[pkg].Files { | ||
actualSymbols = append(actualSymbols, ExtractSymbols(file)...) | ||
} | ||
} | ||
|
||
Ω(actualSymbols).Should(ConsistOf(expectedSymbols)) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
Ginkgo isusually dot-imported via: | ||
import . "github.com/onsi/ginkgo/v2" | ||
however some parts of the DSL may conflict with existing symbols in the user's code. | ||
To mitigate this without losing the brevity of dot-importing Ginkgo the various packages in the | ||
dsl directory provide pieces of the Ginkgo DSL that can be dot-imported separately. | ||
This "reporting" package pulls in the reporting-related pieces of the Ginkgo DSL. | ||
*/ | ||
package reporting | ||
|
||
import ( | ||
"github.com/onsi/ginkgo/v2" | ||
) | ||
|
||
type Report = ginkgo.Report | ||
type SpecReport = ginkgo.SpecReport | ||
type ReportEntryVisibility = ginkgo.ReportEntryVisibility | ||
|
||
const ReportEntryVisibilityAlways, ReportEntryVisibilityFailureOrVerbose, ReportEntryVisibilityNever = ginkgo.ReportEntryVisibilityAlways, ginkgo.ReportEntryVisibilityFailureOrVerbose, ginkgo.ReportEntryVisibilityNever | ||
|
||
var CurrentSpecReport = ginkgo.CurrentSpecReport | ||
var AddReportEntry = ginkgo.AddReportEntry | ||
|
||
var ReportBeforeEach = ginkgo.ReportBeforeEach | ||
var ReportAfterEach = ginkgo.ReportAfterEach | ||
var ReportAfterSuite = ginkgo.ReportAfterSuite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
Ginkgo isusually dot-imported via: | ||
import . "github.com/onsi/ginkgo/v2" | ||
however some parts of the DSL may conflict with existing symbols in the user's code. | ||
To mitigate this without losing the brevity of dot-importing Ginkgo the various packages in the | ||
dsl directory provide pieces of the Ginkgo DSL that can be dot-imported separately. | ||
This "table" package pulls in the Ginkgo's table-testing DSL | ||
*/ | ||
package table | ||
|
||
import ( | ||
"github.com/onsi/ginkgo/v2" | ||
) | ||
|
||
type EntryDescription = ginkgo.EntryDescription | ||
|
||
var DescribeTable = ginkgo.DescribeTable | ||
var FDescribeTable = ginkgo.FDescribeTable | ||
var PDescribeTable = ginkgo.PDescribeTable | ||
var XDescribeTable = ginkgo.XDescribeTable | ||
|
||
type TableEntry = ginkgo.TableEntry | ||
|
||
var Entry = ginkgo.Entry | ||
var FEntry = ginkgo.FEntry | ||
var PEntry = ginkgo.PEntry | ||
var XEntry = ginkgo.XEntry |
Oops, something went wrong.