...

Source file src/github.com/onsi/ginkgo/v2/integration/filter_test.go

Documentation: github.com/onsi/ginkgo/v2/integration

     1  package integration_test
     2  
     3  import (
     4  	. "github.com/onsi/ginkgo/v2"
     5  	. "github.com/onsi/gomega"
     6  	"github.com/onsi/gomega/gbytes"
     7  	"github.com/onsi/gomega/gexec"
     8  
     9  	. "github.com/onsi/ginkgo/v2/internal/test_helpers"
    10  )
    11  
    12  var _ = Describe("Filter", func() {
    13  	BeforeEach(func() {
    14  		fm.MountFixture("filter")
    15  	})
    16  
    17  	It("honors the focus, skip, focus-file and skip-file flags", func() {
    18  		session := startGinkgo(fm.PathTo("filter"),
    19  			"--focus=dog", "--focus=fish",
    20  			"--skip=cat",
    21  			"--focus-file=sprocket", "--focus-file=widget:1-24", "--focus-file=_b:24-42",
    22  			"--skip-file=_c",
    23  			"--json-report=report.json",
    24  			"--label-filter=TopLevelLabel && !SLOW",
    25  		)
    26  		Eventually(session).Should(gexec.Exit(0))
    27  		specs := Reports(fm.LoadJSONReports("filter", "report.json")[0].SpecReports)
    28  
    29  		passedSpecs := []string{
    30  			"SprocketA dog fish",
    31  			"SprocketB dog", "SprocketB dog fish",
    32  			"WidgetA dog", "WidgetA dog fish",
    33  			"WidgetB dog fish",
    34  			// lines in _b > 24 are in --focus-file
    35  			"More WidgetB dog", "More WidgetB dog fish",
    36  		}
    37  
    38  		skippedSpecs := []string{
    39  			// nugget files are not in focus-file
    40  			"NuggetA cat", "NuggetA dog", "NuggetA cat fish", "NuggetA dog fish",
    41  			"NuggetB cat", "NuggetB dog", "NuggetB cat fish", "NuggetB dog fish",
    42  			// cat is not in -focus
    43  			"SprocketA cat", "SprocketB cat", "WidgetA cat", "WidgetB cat", "More WidgetB cat",
    44  			// fish is in -focus but cat is in -skip
    45  			"SprocketA cat fish", "SprocketB cat fish", "WidgetA cat fish", "WidgetB cat fish", "More WidgetB cat fish",
    46  			// Tests labelled 'slow'
    47  			"WidgetB dog",
    48  			"SprocketB fish",
    49  			// _c is in -skip-file
    50  			"SprocketC cat", "SprocketC dog", "SprocketC cat fish", "SprocketC dog fish",
    51  			// lines in widget > 24 are not in --focus-file
    52  			"More WidgetA cat", "More WidgetA dog", "More WidgetA cat fish", "More WidgetA dog fish",
    53  		}
    54  		pendingSpecs := []string{
    55  			"SprocketA pending dog",
    56  		}
    57  
    58  		Ω(specs).Should(HaveLen(len(passedSpecs) + len(skippedSpecs) + len(pendingSpecs)))
    59  
    60  		for _, text := range passedSpecs {
    61  			Ω(specs.FindByFullText(text)).Should(HavePassed(), text)
    62  		}
    63  		for _, text := range skippedSpecs {
    64  			Ω(specs.FindByFullText(text)).Should(HaveBeenSkipped(), text)
    65  		}
    66  		for _, text := range pendingSpecs {
    67  			Ω(specs.FindByFullText(text)).Should(BePending(), text)
    68  		}
    69  	})
    70  
    71  	It("ignores empty filter flags", func() {
    72  		session := startGinkgo(fm.PathTo("filter"),
    73  			"--focus=", "--skip=",
    74  			"--json-report=report.json",
    75  		)
    76  		Eventually(session).Should(gexec.Exit(0))
    77  		specs := Reports(fm.LoadJSONReports("filter", "report.json")[0].SpecReports)
    78  		for _, spec := range specs {
    79  			Ω(spec).Should(SatisfyAny(HavePassed(), BePending()))
    80  		}
    81  	})
    82  
    83  	It("errors if the file-filter format is wrong", func() {
    84  		session := startGinkgo(fm.PathTo("filter"), "--focus-file=foo:bar", "--skip-file=")
    85  		Eventually(session).Should(gexec.Exit(1))
    86  		Ω(session).Should(gbytes.Say("Invalid File Filter"))
    87  		Ω(session).Should(gbytes.Say("Invalid File Filter"))
    88  	})
    89  
    90  	Describe("Listing labels", func() {
    91  		BeforeEach(func() {
    92  			fm.MountFixture("labels")
    93  		})
    94  
    95  		It("can list labels", func() {
    96  			session := startGinkgo(fm.TmpDir, "labels", "-r")
    97  			Eventually(session).Should(gexec.Exit(0))
    98  			Ω(session).Should(gbytes.Say(`filter: \["TopLevelLabel", "slow"\]`))
    99  			Ω(session).Should(gbytes.Say(`labels: \["beluga", "bird", "cat", "chicken", "cow", "dog", "giraffe", "koala", "monkey", "otter", "owl", "panda"\]`))
   100  			Ω(session).Should(gbytes.Say(`nolabels: No labels found`))
   101  			Ω(session).Should(gbytes.Say(`onepkg: \["beluga", "bird", "cat", "chicken", "cow", "dog", "giraffe", "koala", "monkey", "otter", "owl", "panda"\]`))
   102  		})
   103  	})
   104  })
   105  

View as plain text