Skip to content

Commit

Permalink
fix: fixes the test skip when the --focus flag argument contains meta…
Browse files Browse the repository at this point in the history
…characters.
  • Loading branch information
Joselito Viveiros Nogueira Filho committed Mar 20, 2021
1 parent 9162b86 commit 68969fc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
3 changes: 2 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package config

import (
"flag"
"regexp"
"time"

"fmt"
Expand Down Expand Up @@ -139,7 +140,7 @@ func BuildFlagArgs(prefix string, ginkgo GinkgoConfigType, reporter DefaultRepor
}

for _, s := range ginkgo.FocusStrings {
result = append(result, fmt.Sprintf("--%sfocus=%s", prefix, s))
result = append(result, fmt.Sprintf("--%sfocus=%s", prefix, regexp.QuoteMeta(s)))
}

for _, s := range ginkgo.SkipStrings {
Expand Down
6 changes: 6 additions & 0 deletions integration/_fixtures/flags_tests/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ var _ = Describe("Testing various flags", func() {
})
})

Describe("--focus flag argument contains metacharacters", func() {
It("should MyMethod() $called", func() {
println("MyMethod")
})
})

It("should detect races", func(done Done) {
var a string
go func() {
Expand Down
24 changes: 20 additions & 4 deletions integration/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var _ = Describe("Flags Specs", func() {
output := string(session.Out.Contents())

Ω(output).Should(ContainSubstring("Ran 3 samples:"), "has a measurement")
Ω(output).Should(ContainSubstring("11 Passed"))
Ω(output).Should(ContainSubstring("12 Passed"))
Ω(output).Should(ContainSubstring("0 Failed"))
Ω(output).Should(ContainSubstring("1 Pending"))
Ω(output).Should(ContainSubstring("3 Skipped"))
Expand Down Expand Up @@ -88,7 +88,23 @@ var _ = Describe("Flags Specs", func() {
Ω(output).Should(ContainSubstring("3 Passed"))
Ω(output).Should(ContainSubstring("0 Failed"))
Ω(output).Should(ContainSubstring("0 Pending"))
Ω(output).Should(ContainSubstring("12 Skipped"))
Ω(output).Should(ContainSubstring("13 Skipped"))
})

It("should override the programmatic focus when the --focus flag argument contains metacharacters", func() {
session := startGinkgo(pathToTest, "--noColor", "--focus=should MyMethod() $called")
Eventually(session).Should(gexec.Exit(0))
output := string(session.Out.Contents())

Ω(output).Should(ContainSubstring("MyMethod"))
Ω(output).Should(ContainSubstring("1 Passed"))
Ω(output).Should(ContainSubstring("0 Failed"))
Ω(output).Should(ContainSubstring("0 Pending"))
Ω(output).Should(ContainSubstring("15 Skipped"))
})

It("should ... when method() ...", func() {
Expect(1).To(Equal(1))
})

It("should override the programmatic focus when told to skip", func() {
Expand All @@ -99,7 +115,7 @@ var _ = Describe("Flags Specs", func() {
Ω(output).ShouldNot(ContainSubstring("marshmallow"))
Ω(output).Should(ContainSubstring("chocolate"))
Ω(output).Should(ContainSubstring("smores"))
Ω(output).Should(ContainSubstring("11 Passed"))
Ω(output).Should(ContainSubstring("12 Passed"))
Ω(output).Should(ContainSubstring("0 Failed"))
Ω(output).Should(ContainSubstring("1 Pending"))
Ω(output).Should(ContainSubstring("3 Skipped"))
Expand All @@ -113,7 +129,7 @@ var _ = Describe("Flags Specs", func() {
Ω(output).ShouldNot(ContainSubstring("marshmallow"))
Ω(output).Should(ContainSubstring("chocolate"))
Ω(output).Should(ContainSubstring("smores"))
Ω(output).Should(ContainSubstring("11 Passed"))
Ω(output).Should(ContainSubstring("12 Passed"))
Ω(output).Should(ContainSubstring("0 Failed"))
Ω(output).Should(ContainSubstring("1 Pending"))
Ω(output).Should(ContainSubstring("3 Skipped"))
Expand Down

0 comments on commit 68969fc

Please sign in to comment.