diff --git a/ginkgo/outline/_testdata/alias_test.go b/ginkgo/outline/_testdata/alias_test.go index bf9a29075..ee72ccc5e 100644 --- a/ginkgo/outline/_testdata/alias_test.go +++ b/ginkgo/outline/_testdata/alias_test.go @@ -2,6 +2,7 @@ package example_test import ( fooginkgo "github.com/onsi/ginkgo" + footable "github.com/onsi/ginkgo/extensions/table" ) var _ = fooginkgo.Describe("NodotFixture", func() { @@ -33,17 +34,17 @@ var _ = fooginkgo.Describe("NodotFixture", func() { }) - fooginkgo.Measure("normal", func(b Benchmarker) { + fooginkgo.Measure("normal", func(b fooginkgo.Benchmarker) { }, 2) - fooginkgo.DescribeTable("normal", + footable.DescribeTable("normal", func() {}, - fooginkgo.Entry("normal"), + footable.Entry("normal"), ) - fooginkgo.DescribeTable("normal", + footable.DescribeTable("normal", func() {}, - fooginkgo.Entry("normal"), + footable.Entry("normal"), ) }) diff --git a/ginkgo/outline/_testdata/alias_test.go.csv b/ginkgo/outline/_testdata/alias_test.go.csv index 267f905a1..cfa386c71 100644 --- a/ginkgo/outline/_testdata/alias_test.go.csv +++ b/ginkgo/outline/_testdata/alias_test.go.csv @@ -1,13 +1,17 @@ Name,Text,Start,End,Spec,Focused,Pending -Describe,NodotFixture,79,728,false,false,false -Describe,normal,124,257,false,false,false -It,normal,164,253,true,false,false -By,normal,199,221,false,false,false -By,normal,225,247,false,false,false -Context,normal,260,340,false,false,false -It,normal,299,336,true,false,false -When,normal,343,420,false,false,false -It,normal,379,416,true,false,false -It,normal,423,459,true,false,false -Specify,normal,462,503,true,false,false -Measure,normal,506,563,true,false,false +Describe,NodotFixture,131,786,false,false,false +Describe,normal,176,309,false,false,false +It,normal,216,305,true,false,false +By,normal,251,273,false,false,false +By,normal,277,299,false,false,false +Context,normal,312,392,false,false,false +It,normal,351,388,true,false,false +When,normal,395,472,false,false,false +It,normal,431,468,true,false,false +It,normal,475,511,true,false,false +Specify,normal,514,555,true,false,false +Measure,normal,558,625,true,false,false +DescribeTable,normal,628,704,false,false,false +Entry,normal,676,700,true,false,false +DescribeTable,normal,707,783,false,false,false +Entry,normal,755,779,true,false,false diff --git a/ginkgo/outline/_testdata/alias_test.go.json b/ginkgo/outline/_testdata/alias_test.go.json index 885de0a80..44248147b 100644 --- a/ginkgo/outline/_testdata/alias_test.go.json +++ b/ginkgo/outline/_testdata/alias_test.go.json @@ -1 +1 @@ -[{"name":"Describe","text":"NodotFixture","start":79,"end":728,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"Describe","text":"normal","start":124,"end":257,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"It","text":"normal","start":164,"end":253,"spec":true,"focused":false,"pending":false,"nodes":[{"name":"By","text":"normal","start":199,"end":221,"spec":false,"focused":false,"pending":false},{"name":"By","text":"normal","start":225,"end":247,"spec":false,"focused":false,"pending":false}]}]},{"name":"Context","text":"normal","start":260,"end":340,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"It","text":"normal","start":299,"end":336,"spec":true,"focused":false,"pending":false}]},{"name":"When","text":"normal","start":343,"end":420,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"It","text":"normal","start":379,"end":416,"spec":true,"focused":false,"pending":false}]},{"name":"It","text":"normal","start":423,"end":459,"spec":true,"focused":false,"pending":false},{"name":"Specify","text":"normal","start":462,"end":503,"spec":true,"focused":false,"pending":false},{"name":"Measure","text":"normal","start":506,"end":563,"spec":true,"focused":false,"pending":false}]}] +[{"name":"Describe","text":"NodotFixture","start":131,"end":786,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"Describe","text":"normal","start":176,"end":309,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"It","text":"normal","start":216,"end":305,"spec":true,"focused":false,"pending":false,"nodes":[{"name":"By","text":"normal","start":251,"end":273,"spec":false,"focused":false,"pending":false},{"name":"By","text":"normal","start":277,"end":299,"spec":false,"focused":false,"pending":false}]}]},{"name":"Context","text":"normal","start":312,"end":392,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"It","text":"normal","start":351,"end":388,"spec":true,"focused":false,"pending":false}]},{"name":"When","text":"normal","start":395,"end":472,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"It","text":"normal","start":431,"end":468,"spec":true,"focused":false,"pending":false}]},{"name":"It","text":"normal","start":475,"end":511,"spec":true,"focused":false,"pending":false},{"name":"Specify","text":"normal","start":514,"end":555,"spec":true,"focused":false,"pending":false},{"name":"Measure","text":"normal","start":558,"end":625,"spec":true,"focused":false,"pending":false},{"name":"DescribeTable","text":"normal","start":628,"end":704,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"Entry","text":"normal","start":676,"end":700,"spec":true,"focused":false,"pending":false}]},{"name":"DescribeTable","text":"normal","start":707,"end":783,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"Entry","text":"normal","start":755,"end":779,"spec":true,"focused":false,"pending":false}]}]}] diff --git a/ginkgo/outline/_testdata/focused_test.go.csv b/ginkgo/outline/_testdata/focused_test.go.csv index d49522daf..417765dfb 100644 --- a/ginkgo/outline/_testdata/focused_test.go.csv +++ b/ginkgo/outline/_testdata/focused_test.go.csv @@ -11,3 +11,7 @@ It,focused,342,370,true,true,false FIt,focused,377,405,true,true,false FSpecify,focused,408,441,true,true,false FMeasure,focused,444,493,true,true,false +FDescribeTable,focused,496,557,false,true,false +Entry,focused,537,553,true,true,false +DescribeTable,focused,560,621,false,false,false +FEntry,focused,600,617,true,true,false diff --git a/ginkgo/outline/_testdata/focused_test.go.json b/ginkgo/outline/_testdata/focused_test.go.json index 2c042225d..101e6d799 100644 --- a/ginkgo/outline/_testdata/focused_test.go.json +++ b/ginkgo/outline/_testdata/focused_test.go.json @@ -1 +1 @@ -[{"name":"Describe","text":"unfocused","start":116,"end":624,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"FDescribe","text":"focused","start":148,"end":245,"spec":false,"focused":true,"pending":false,"nodes":[{"name":"It","text":"focused","start":180,"end":241,"spec":true,"focused":true,"pending":false,"nodes":[{"name":"By","text":"focused","start":206,"end":219,"spec":false,"focused":true,"pending":false},{"name":"By","text":"focused","start":223,"end":236,"spec":false,"focused":true,"pending":false}]}]},{"name":"FContext","text":"focused","start":248,"end":311,"spec":false,"focused":true,"pending":false,"nodes":[{"name":"It","text":"focused","start":279,"end":307,"spec":true,"focused":true,"pending":false}]},{"name":"FWhen","text":"focused","start":314,"end":374,"spec":false,"focused":true,"pending":false,"nodes":[{"name":"It","text":"focused","start":342,"end":370,"spec":true,"focused":true,"pending":false}]},{"name":"FIt","text":"focused","start":377,"end":405,"spec":true,"focused":true,"pending":false},{"name":"FSpecify","text":"focused","start":408,"end":441,"spec":true,"focused":true,"pending":false},{"name":"FMeasure","text":"focused","start":444,"end":493,"spec":true,"focused":true,"pending":false}]}] +[{"name":"Describe","text":"unfocused","start":116,"end":624,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"FDescribe","text":"focused","start":148,"end":245,"spec":false,"focused":true,"pending":false,"nodes":[{"name":"It","text":"focused","start":180,"end":241,"spec":true,"focused":true,"pending":false,"nodes":[{"name":"By","text":"focused","start":206,"end":219,"spec":false,"focused":true,"pending":false},{"name":"By","text":"focused","start":223,"end":236,"spec":false,"focused":true,"pending":false}]}]},{"name":"FContext","text":"focused","start":248,"end":311,"spec":false,"focused":true,"pending":false,"nodes":[{"name":"It","text":"focused","start":279,"end":307,"spec":true,"focused":true,"pending":false}]},{"name":"FWhen","text":"focused","start":314,"end":374,"spec":false,"focused":true,"pending":false,"nodes":[{"name":"It","text":"focused","start":342,"end":370,"spec":true,"focused":true,"pending":false}]},{"name":"FIt","text":"focused","start":377,"end":405,"spec":true,"focused":true,"pending":false},{"name":"FSpecify","text":"focused","start":408,"end":441,"spec":true,"focused":true,"pending":false},{"name":"FMeasure","text":"focused","start":444,"end":493,"spec":true,"focused":true,"pending":false},{"name":"FDescribeTable","text":"focused","start":496,"end":557,"spec":false,"focused":true,"pending":false,"nodes":[{"name":"Entry","text":"focused","start":537,"end":553,"spec":true,"focused":true,"pending":false}]},{"name":"DescribeTable","text":"focused","start":560,"end":621,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"FEntry","text":"focused","start":600,"end":617,"spec":true,"focused":true,"pending":false}]}]}] diff --git a/ginkgo/outline/_testdata/nodot_test.go b/ginkgo/outline/_testdata/nodot_test.go index 13525db75..1198c7908 100644 --- a/ginkgo/outline/_testdata/nodot_test.go +++ b/ginkgo/outline/_testdata/nodot_test.go @@ -2,6 +2,7 @@ package example_test import ( "github.com/onsi/ginkgo" + "github.com/onsi/ginkgo/extensions/table" ) var _ = ginkgo.Describe("NodotFixture", func() { @@ -32,17 +33,17 @@ var _ = ginkgo.Describe("NodotFixture", func() { }) - ginkgo.Measure("normal", func(b Benchmarker) { + ginkgo.Measure("normal", func(b ginkgo.Benchmarker) { }, 2) - ginkgo.DescribeTable("normal", + table.DescribeTable("normal", func() {}, - ginkgo.Entry("normal"), + table.Entry("normal"), ) - ginkgo.DescribeTable("normal", + table.DescribeTable("normal", func() {}, - ginkgo.Entry("normal"), + table.Entry("normal"), ) }) diff --git a/ginkgo/outline/_testdata/nodot_test.go.csv b/ginkgo/outline/_testdata/nodot_test.go.csv index eecd3b9d5..37454bc6f 100644 --- a/ginkgo/outline/_testdata/nodot_test.go.csv +++ b/ginkgo/outline/_testdata/nodot_test.go.csv @@ -1,13 +1,17 @@ Name,Text,Start,End,Spec,Focused,Pending -Describe,NodotFixture,69,669,false,false,false -Describe,normal,111,231,false,false,false -It,normal,148,227,true,false,false -By,normal,180,199,false,false,false -By,normal,203,222,false,false,false -Context,normal,234,308,false,false,false -It,normal,270,304,true,false,false -When,normal,311,382,false,false,false -It,normal,344,378,true,false,false -It,normal,385,418,true,false,false -Specify,normal,421,459,true,false,false -Measure,normal,462,516,true,false,false +Describe,NodotFixture,112,715,false,false,false +Describe,normal,154,274,false,false,false +It,normal,191,270,true,false,false +By,normal,223,242,false,false,false +By,normal,246,265,false,false,false +Context,normal,277,351,false,false,false +It,normal,313,347,true,false,false +When,normal,354,425,false,false,false +It,normal,387,421,true,false,false +It,normal,428,461,true,false,false +Specify,normal,464,502,true,false,false +Measure,normal,505,566,true,false,false +DescribeTable,normal,569,639,false,false,false +Entry,normal,614,635,true,false,false +DescribeTable,normal,642,712,false,false,false +Entry,normal,687,708,true,false,false diff --git a/ginkgo/outline/_testdata/nodot_test.go.json b/ginkgo/outline/_testdata/nodot_test.go.json index d476b820c..8ddf7e421 100644 --- a/ginkgo/outline/_testdata/nodot_test.go.json +++ b/ginkgo/outline/_testdata/nodot_test.go.json @@ -1 +1 @@ -[{"name":"Describe","text":"NodotFixture","start":69,"end":669,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"Describe","text":"normal","start":111,"end":231,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"It","text":"normal","start":148,"end":227,"spec":true,"focused":false,"pending":false,"nodes":[{"name":"By","text":"normal","start":180,"end":199,"spec":false,"focused":false,"pending":false},{"name":"By","text":"normal","start":203,"end":222,"spec":false,"focused":false,"pending":false}]}]},{"name":"Context","text":"normal","start":234,"end":308,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"It","text":"normal","start":270,"end":304,"spec":true,"focused":false,"pending":false}]},{"name":"When","text":"normal","start":311,"end":382,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"It","text":"normal","start":344,"end":378,"spec":true,"focused":false,"pending":false}]},{"name":"It","text":"normal","start":385,"end":418,"spec":true,"focused":false,"pending":false},{"name":"Specify","text":"normal","start":421,"end":459,"spec":true,"focused":false,"pending":false},{"name":"Measure","text":"normal","start":462,"end":516,"spec":true,"focused":false,"pending":false}]}] +[{"name":"Describe","text":"NodotFixture","start":112,"end":715,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"Describe","text":"normal","start":154,"end":274,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"It","text":"normal","start":191,"end":270,"spec":true,"focused":false,"pending":false,"nodes":[{"name":"By","text":"normal","start":223,"end":242,"spec":false,"focused":false,"pending":false},{"name":"By","text":"normal","start":246,"end":265,"spec":false,"focused":false,"pending":false}]}]},{"name":"Context","text":"normal","start":277,"end":351,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"It","text":"normal","start":313,"end":347,"spec":true,"focused":false,"pending":false}]},{"name":"When","text":"normal","start":354,"end":425,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"It","text":"normal","start":387,"end":421,"spec":true,"focused":false,"pending":false}]},{"name":"It","text":"normal","start":428,"end":461,"spec":true,"focused":false,"pending":false},{"name":"Specify","text":"normal","start":464,"end":502,"spec":true,"focused":false,"pending":false},{"name":"Measure","text":"normal","start":505,"end":566,"spec":true,"focused":false,"pending":false},{"name":"DescribeTable","text":"normal","start":569,"end":639,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"Entry","text":"normal","start":614,"end":635,"spec":true,"focused":false,"pending":false}]},{"name":"DescribeTable","text":"normal","start":642,"end":712,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"Entry","text":"normal","start":687,"end":708,"spec":true,"focused":false,"pending":false}]}]}] diff --git a/ginkgo/outline/_testdata/normal_test.go.csv b/ginkgo/outline/_testdata/normal_test.go.csv index 569f336cf..0b4db4d81 100644 --- a/ginkgo/outline/_testdata/normal_test.go.csv +++ b/ginkgo/outline/_testdata/normal_test.go.csv @@ -11,3 +11,7 @@ It,normal,336,363,true,false,false It,normal,370,396,true,false,false Specify,normal,399,430,true,false,false Measure,normal,433,480,true,false,false +DescribeTable,normal,483,541,false,false,false +Entry,normal,522,537,true,false,false +DescribeTable,normal,544,602,false,false,false +Entry,normal,583,598,true,false,false diff --git a/ginkgo/outline/_testdata/normal_test.go.json b/ginkgo/outline/_testdata/normal_test.go.json index 43b97a2b9..89710cd2b 100644 --- a/ginkgo/outline/_testdata/normal_test.go.json +++ b/ginkgo/outline/_testdata/normal_test.go.json @@ -1 +1 @@ -[{"name":"Describe","text":"NormalFixture","start":116,"end":605,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"Describe","text":"normal","start":152,"end":244,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"It","text":"normal","start":182,"end":240,"spec":true,"focused":false,"pending":false,"nodes":[{"name":"By","text":"step 1","start":207,"end":219,"spec":false,"focused":false,"pending":false},{"name":"By","text":"step 2","start":223,"end":235,"spec":false,"focused":false,"pending":false}]}]},{"name":"Context","text":"normal","start":247,"end":307,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"It","text":"normal","start":276,"end":303,"spec":true,"focused":false,"pending":false}]},{"name":"When","text":"normal","start":310,"end":367,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"It","text":"normal","start":336,"end":363,"spec":true,"focused":false,"pending":false}]},{"name":"It","text":"normal","start":370,"end":396,"spec":true,"focused":false,"pending":false},{"name":"Specify","text":"normal","start":399,"end":430,"spec":true,"focused":false,"pending":false},{"name":"Measure","text":"normal","start":433,"end":480,"spec":true,"focused":false,"pending":false}]}] +[{"name":"Describe","text":"NormalFixture","start":116,"end":605,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"Describe","text":"normal","start":152,"end":244,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"It","text":"normal","start":182,"end":240,"spec":true,"focused":false,"pending":false,"nodes":[{"name":"By","text":"step 1","start":207,"end":219,"spec":false,"focused":false,"pending":false},{"name":"By","text":"step 2","start":223,"end":235,"spec":false,"focused":false,"pending":false}]}]},{"name":"Context","text":"normal","start":247,"end":307,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"It","text":"normal","start":276,"end":303,"spec":true,"focused":false,"pending":false}]},{"name":"When","text":"normal","start":310,"end":367,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"It","text":"normal","start":336,"end":363,"spec":true,"focused":false,"pending":false}]},{"name":"It","text":"normal","start":370,"end":396,"spec":true,"focused":false,"pending":false},{"name":"Specify","text":"normal","start":399,"end":430,"spec":true,"focused":false,"pending":false},{"name":"Measure","text":"normal","start":433,"end":480,"spec":true,"focused":false,"pending":false},{"name":"DescribeTable","text":"normal","start":483,"end":541,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"Entry","text":"normal","start":522,"end":537,"spec":true,"focused":false,"pending":false}]},{"name":"DescribeTable","text":"normal","start":544,"end":602,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"Entry","text":"normal","start":583,"end":598,"spec":true,"focused":false,"pending":false}]}]}] diff --git a/ginkgo/outline/_testdata/pending_test.go.csv b/ginkgo/outline/_testdata/pending_test.go.csv index 831c8d9da..d3eae7229 100644 --- a/ginkgo/outline/_testdata/pending_test.go.csv +++ b/ginkgo/outline/_testdata/pending_test.go.csv @@ -11,3 +11,7 @@ It,pending,347,375,true,false,true PIt,pending,382,410,true,false,true PSpecify,pending,413,446,true,false,true PMeasure,pending,449,498,true,false,true +PDescribeTable,pending,501,562,false,false,true +Entry,pending,542,558,true,false,true +DescribeTable,pending,565,626,false,false,false +PEntry,pending,605,622,true,false,true diff --git a/ginkgo/outline/_testdata/pending_test.go.json b/ginkgo/outline/_testdata/pending_test.go.json index 0014d4a2c..dec6d7309 100644 --- a/ginkgo/outline/_testdata/pending_test.go.json +++ b/ginkgo/outline/_testdata/pending_test.go.json @@ -1 +1 @@ -[{"name":"Describe","text":"PendingFixture","start":116,"end":629,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"PDescribe","text":"pending","start":153,"end":250,"spec":false,"focused":false,"pending":true,"nodes":[{"name":"It","text":"pending","start":185,"end":246,"spec":true,"focused":false,"pending":true,"nodes":[{"name":"By","text":"pending","start":211,"end":224,"spec":false,"focused":false,"pending":true},{"name":"By","text":"pending","start":228,"end":241,"spec":false,"focused":false,"pending":true}]}]},{"name":"PContext","text":"pending","start":253,"end":316,"spec":false,"focused":false,"pending":true,"nodes":[{"name":"It","text":"pending","start":284,"end":312,"spec":true,"focused":false,"pending":true}]},{"name":"PWhen","text":"pending","start":319,"end":379,"spec":false,"focused":false,"pending":true,"nodes":[{"name":"It","text":"pending","start":347,"end":375,"spec":true,"focused":false,"pending":true}]},{"name":"PIt","text":"pending","start":382,"end":410,"spec":true,"focused":false,"pending":true},{"name":"PSpecify","text":"pending","start":413,"end":446,"spec":true,"focused":false,"pending":true},{"name":"PMeasure","text":"pending","start":449,"end":498,"spec":true,"focused":false,"pending":true}]}] +[{"name":"Describe","text":"PendingFixture","start":116,"end":629,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"PDescribe","text":"pending","start":153,"end":250,"spec":false,"focused":false,"pending":true,"nodes":[{"name":"It","text":"pending","start":185,"end":246,"spec":true,"focused":false,"pending":true,"nodes":[{"name":"By","text":"pending","start":211,"end":224,"spec":false,"focused":false,"pending":true},{"name":"By","text":"pending","start":228,"end":241,"spec":false,"focused":false,"pending":true}]}]},{"name":"PContext","text":"pending","start":253,"end":316,"spec":false,"focused":false,"pending":true,"nodes":[{"name":"It","text":"pending","start":284,"end":312,"spec":true,"focused":false,"pending":true}]},{"name":"PWhen","text":"pending","start":319,"end":379,"spec":false,"focused":false,"pending":true,"nodes":[{"name":"It","text":"pending","start":347,"end":375,"spec":true,"focused":false,"pending":true}]},{"name":"PIt","text":"pending","start":382,"end":410,"spec":true,"focused":false,"pending":true},{"name":"PSpecify","text":"pending","start":413,"end":446,"spec":true,"focused":false,"pending":true},{"name":"PMeasure","text":"pending","start":449,"end":498,"spec":true,"focused":false,"pending":true},{"name":"PDescribeTable","text":"pending","start":501,"end":562,"spec":false,"focused":false,"pending":true,"nodes":[{"name":"Entry","text":"pending","start":542,"end":558,"spec":true,"focused":false,"pending":true}]},{"name":"DescribeTable","text":"pending","start":565,"end":626,"spec":false,"focused":false,"pending":false,"nodes":[{"name":"PEntry","text":"pending","start":605,"end":622,"spec":true,"focused":false,"pending":true}]}]}] diff --git a/ginkgo/outline/ginkgo.go b/ginkgo/outline/ginkgo.go index 2256a2cca..8fddcca24 100644 --- a/ginkgo/outline/ginkgo.go +++ b/ginkgo/outline/ginkgo.go @@ -101,38 +101,32 @@ func (n *ginkgoNode) BackpropagateUnfocus() { } -func ginkgoIdentNameFromCallExpr(ce *ast.CallExpr, ginkgoImportName string) (string, bool) { +func packageAndIdentNamesFromCallExpr(ce *ast.CallExpr) (string, string, bool) { switch ex := ce.Fun.(type) { case *ast.Ident: - if ginkgoImportName != "." { - return "", false - } - return ex.Name, true + return "", ex.Name, true case *ast.SelectorExpr: pkgID, ok := ex.X.(*ast.Ident) if !ok { - return "", false + return "", "", false } // A package identifier is top-level, so Obj must be nil if pkgID.Obj != nil { - return "", false - } - if ginkgoImportName != pkgID.Name { - return "", false + return "", "", false } if ex.Sel == nil { - return "", false + return "", "", false } - return ex.Sel.Name, true + return pkgID.Name, ex.Sel.Name, true default: - return "", false + return "", "", false } } // ginkgoNodeFromCallExpr derives an outline entry from a go AST subtree // corresponding to a Ginkgo container or spec. -func ginkgoNodeFromCallExpr(ce *ast.CallExpr, ginkgoImportName string) (*ginkgoNode, bool) { - identName, ok := ginkgoIdentNameFromCallExpr(ce, ginkgoImportName) +func ginkgoNodeFromCallExpr(ce *ast.CallExpr, ginkgoPackageName, tablePackageName *string) (*ginkgoNode, bool) { + packageName, identName, ok := packageAndIdentNamesFromCallExpr(ce) if !ok { return nil, false } @@ -141,37 +135,71 @@ func ginkgoNodeFromCallExpr(ce *ast.CallExpr, ginkgoImportName string) (*ginkgoN n.Name = identName n.Start = ce.Pos() n.End = ce.End() - switch identName { case "It", "Measure", "Specify": n.Spec = true n.Text = textOrAltFromCallExpr(ce, undefinedTextAlt) + return &n, ginkgoPackageName != nil && *ginkgoPackageName == packageName + case "Entry": + n.Spec = true + n.Text = textOrAltFromCallExpr(ce, undefinedTextAlt) + return &n, tablePackageName != nil && *tablePackageName == packageName case "FIt", "FMeasure", "FSpecify": n.Spec = true n.Focused = true n.Text = textOrAltFromCallExpr(ce, undefinedTextAlt) + return &n, ginkgoPackageName != nil && *ginkgoPackageName == packageName + case "FEntry": + n.Spec = true + n.Focused = true + n.Text = textOrAltFromCallExpr(ce, undefinedTextAlt) + return &n, tablePackageName != nil && *tablePackageName == packageName case "PIt", "PMeasure", "PSpecify", "XIt", "XMeasure", "XSpecify": n.Spec = true n.Pending = true n.Text = textOrAltFromCallExpr(ce, undefinedTextAlt) + return &n, ginkgoPackageName != nil && *ginkgoPackageName == packageName + case "PEntry", "XEntry": + n.Spec = true + n.Pending = true + n.Text = textOrAltFromCallExpr(ce, undefinedTextAlt) + return &n, tablePackageName != nil && *tablePackageName == packageName case "Context", "Describe", "When": n.Text = textOrAltFromCallExpr(ce, undefinedTextAlt) + return &n, ginkgoPackageName != nil && *ginkgoPackageName == packageName + case "DescribeTable": + n.Text = textOrAltFromCallExpr(ce, undefinedTextAlt) + return &n, tablePackageName != nil && *tablePackageName == packageName case "FContext", "FDescribe", "FWhen": n.Focused = true n.Text = textOrAltFromCallExpr(ce, undefinedTextAlt) + return &n, ginkgoPackageName != nil && *ginkgoPackageName == packageName + case "FDescribeTable": + n.Focused = true + n.Text = textOrAltFromCallExpr(ce, undefinedTextAlt) + return &n, tablePackageName != nil && *tablePackageName == packageName case "PContext", "PDescribe", "PWhen", "XContext", "XDescribe", "XWhen": n.Pending = true n.Text = textOrAltFromCallExpr(ce, undefinedTextAlt) + return &n, ginkgoPackageName != nil && *ginkgoPackageName == packageName + case "PDescribeTable", "XDescribeTable": + n.Pending = true + n.Text = textOrAltFromCallExpr(ce, undefinedTextAlt) + return &n, tablePackageName != nil && *tablePackageName == packageName case "By": n.Text = textOrAltFromCallExpr(ce, undefinedTextAlt) + return &n, ginkgoPackageName != nil && *ginkgoPackageName == packageName case "AfterEach", "BeforeEach": + return &n, ginkgoPackageName != nil && *ginkgoPackageName == packageName case "JustAfterEach", "JustBeforeEach": + return &n, ginkgoPackageName != nil && *ginkgoPackageName == packageName case "AfterSuite", "BeforeSuite": + return &n, ginkgoPackageName != nil && *ginkgoPackageName == packageName case "SynchronizedAfterSuite", "SynchronizedBeforeSuite": + return &n, ginkgoPackageName != nil && *ginkgoPackageName == packageName default: return nil, false } - return &n, true } // textOrAltFromCallExpr tries to derive the "text" of a Ginkgo spec or diff --git a/ginkgo/outline/import.go b/ginkgo/outline/import.go index 9b869cf46..4328ab391 100644 --- a/ginkgo/outline/import.go +++ b/ginkgo/outline/import.go @@ -14,16 +14,17 @@ import ( "strings" ) -// importNameForPackage returns the import name for the package. If the package -// is not imported, it returns false. Examples: -// How package is imported -> Import Name +// packageNameForImport returns the package name for the package. If the package +// is not imported, it returns nil. "Package name" refers to `pkgname` in the +// call expression `pkgname.ExportedIdentifier`. Examples: +// (import path not found) -> nil // "import example.com/pkg/foo" -> "foo" // "import fooalias example.com/pkg/foo" -> "fooalias" -// "import . example.com/pkg/foo" -> "." -func importNameForPackage(f *ast.File, path string) (string, bool) { +// "import . example.com/pkg/foo" -> "" +func packageNameForImport(f *ast.File, path string) *string { spec := importSpec(f, path) if spec == nil { - return "", false + return nil } name := spec.Name.String() if name == "" { @@ -36,7 +37,10 @@ func importNameForPackage(f *ast.File, path string) (string, bool) { name = path[lastSlash+1:] } } - return name, true + if name == "." { + name = "" + } + return &name } // importSpec returns the import spec if f imports path, diff --git a/ginkgo/outline/outline.go b/ginkgo/outline/outline.go index 200afd39e..177c13f11 100644 --- a/ginkgo/outline/outline.go +++ b/ginkgo/outline/outline.go @@ -12,19 +12,21 @@ import ( const ( // ginkgoImportPath is the well-known ginkgo import path ginkgoImportPath = "github.com/onsi/ginkgo" + + // tableImportPath is the well-known table extension import path + tableImportPath = "github.com/onsi/ginkgo/extensions/table" ) // FromASTFile returns an outline for a Ginkgo test source file func FromASTFile(src *ast.File) (*outline, error) { - ginkgoImportName, ok := importNameForPackage(src, ginkgoImportPath) - if !ok { - return nil, fmt.Errorf("file does not import %s", ginkgoImportPath) - } - root := ginkgoNode{ - Nodes: []*ginkgoNode{}, + ginkgoPackageName := packageNameForImport(src, ginkgoImportPath) + tablePackageName := packageNameForImport(src, tableImportPath) + if ginkgoPackageName == nil && tablePackageName == nil { + return nil, fmt.Errorf("file does not import %q or %q", ginkgoImportPath, tableImportPath) } - stack := []*ginkgoNode{&root} + root := ginkgoNode{} + stack := []*ginkgoNode{&root} ispr := inspector.New([]*ast.File{src}) ispr.Nodes([]ast.Node{(*ast.CallExpr)(nil)}, func(node ast.Node, push bool) bool { if push { @@ -35,15 +37,13 @@ func FromASTFile(src *ast.File) (*outline, error) { // ast.CallExpr, this should never happen panic(fmt.Errorf("node starting at %d, ending at %d is not an *ast.CallExpr", node.Pos(), node.End())) } - gn, ok := ginkgoNodeFromCallExpr(ce, ginkgoImportName) + gn, ok := ginkgoNodeFromCallExpr(ce, ginkgoPackageName, tablePackageName) if !ok { // Node is not a Ginkgo spec or container, continue return true } - parent := stack[len(stack)-1] parent.Nodes = append(parent.Nodes, gn) - stack = append(stack, gn) return true } @@ -56,6 +56,9 @@ func FromASTFile(src *ast.File) (*outline, error) { stack = stack[0 : len(stack)-1] return true }) + if len(root.Nodes) == 0 { + return &outline{[]*ginkgoNode{}}, nil + } // Derive the final focused property for all nodes. This must be done // _before_ propagating the inherited focused property. @@ -63,11 +66,11 @@ func FromASTFile(src *ast.File) (*outline, error) { // Now, propagate inherited properties, including focused and pending. root.PropagateInheritedProperties() - return &outline{root}, nil + return &outline{root.Nodes}, nil } type outline struct { - ginkgoNode + Nodes []*ginkgoNode `json:"nodes"` } func (o *outline) MarshalJSON() ([]byte, error) {