Permalink
Browse files

dont do that thing with the flag thing

Signed-off-by: Michael Fraenkel <fraenkel@us.ibm.com>
  • Loading branch information...
1 parent b6566b8 commit 349f2d5baae688f172db626a521c8317e11550d3 @onsi committed with Michael Fraenkel Feb 27, 2014
Showing with 16 additions and 21 deletions.
  1. +11 −14 ginkgo.go
  2. +3 −5 suite.go
  3. +2 −2 suite_test.go
View
@@ -13,7 +13,6 @@ package ginkgo
import (
"bytes"
- "flag"
"github.com/onsi/ginkgo/config"
"github.com/onsi/ginkgo/remote"
"github.com/onsi/ginkgo/reporters"
@@ -33,16 +32,7 @@ var globalSuite *suite
func init() {
config.Flags("ginkgo", true)
- flag.Parse()
-
- if config.DefaultReporterConfig.Verbose {
- GinkgoWriter = os.Stdout
- globalSuite = newSuite(nil)
- } else {
- buffer := &bytes.Buffer{}
- GinkgoWriter = buffer
- globalSuite = newSuite(buffer)
- }
+ globalSuite = newSuite()
}
//GinkgoWriter implements an io.Writer
@@ -148,20 +138,27 @@ type Benchmarker interface {
// ginkgo bootstrap
func RunSpecs(t GinkgoTestingT, description string) bool {
specReporters := []Reporter{buildDefaultReporter()}
- return globalSuite.run(t, description, specReporters, config.GinkgoConfig)
+ return RunSpecsWithCustomReporters(t, description, specReporters)
}
//To run your tests with Ginkgo's default reporter and your custom reporter(s), replace
//RunSpecs() with this method.
func RunSpecsWithDefaultAndCustomReporters(t GinkgoTestingT, description string, specReporters []Reporter) bool {
specReporters = append([]Reporter{buildDefaultReporter()}, specReporters...)
- return globalSuite.run(t, description, specReporters, config.GinkgoConfig)
+ return RunSpecsWithCustomReporters(t, description, specReporters)
}
//To run your tests with your custom reporter(s) (and *not* Ginkgo's default reporter), replace
//RunSpecs() with this method.
func RunSpecsWithCustomReporters(t GinkgoTestingT, description string, specReporters []Reporter) bool {
- return globalSuite.run(t, description, specReporters, config.GinkgoConfig)
+ if config.DefaultReporterConfig.Verbose {
+ GinkgoWriter = os.Stdout
+ return globalSuite.run(t, description, specReporters, nil, config.GinkgoConfig)
+ } else {
+ buffer := &bytes.Buffer{}
+ GinkgoWriter = buffer
+ return globalSuite.run(t, description, specReporters, buffer, config.GinkgoConfig)
+ }
}
func buildDefaultReporter() Reporter {
View
@@ -19,25 +19,23 @@ type suite struct {
topLevelContainer *containerNode
currentContainer *containerNode
exampleCollection *exampleCollection
- writer ginkgoWriter
}
type ginkgoWriter interface {
Truncate(n int)
WriteTo(w io.Writer) (n int64, err error)
}
-func newSuite(writer ginkgoWriter) *suite {
+func newSuite() *suite {
topLevelContainer := newContainerNode("[Top Level]", flagTypeNone, types.CodeLocation{})
return &suite{
topLevelContainer: topLevelContainer,
currentContainer: topLevelContainer,
- writer: writer,
}
}
-func (suite *suite) run(t GinkgoTestingT, description string, reporters []Reporter, config config.GinkgoConfigType) bool {
+func (suite *suite) run(t GinkgoTestingT, description string, reporters []Reporter, writer ginkgoWriter, config config.GinkgoConfigType) bool {
r := rand.New(rand.NewSource(config.RandomSeed))
suite.topLevelContainer.shuffle(r)
@@ -49,7 +47,7 @@ func (suite *suite) run(t GinkgoTestingT, description string, reporters []Report
panic("ginkgo.parallel.node is one-indexed and must be <= ginkgo.parallel.total")
}
- suite.exampleCollection = newExampleCollection(t, description, suite.topLevelContainer.generateExamples(), reporters, suite.writer, config)
+ suite.exampleCollection = newExampleCollection(t, description, suite.topLevelContainer.generateExamples(), reporters, writer, config)
return suite.exampleCollection.run()
}
View
@@ -20,7 +20,7 @@ func init() {
BeforeEach(func() {
fakeT = &fakeTestingT{}
fakeR = reporters.NewFakeReporter()
- specSuite = newSuite(nil)
+ specSuite = newSuite()
})
Describe("running a suite", func() {
@@ -72,7 +72,7 @@ func init() {
})
JustBeforeEach(func() {
- runResult = specSuite.run(fakeT, "suite description", []Reporter{fakeR}, config.GinkgoConfigType{
+ runResult = specSuite.run(fakeT, "suite description", []Reporter{fakeR}, nil, config.GinkgoConfigType{
RandomSeed: randomSeed,
RandomizeAllSpecs: randomizeAllSpecs,
FocusString: focusString,

0 comments on commit 349f2d5

Please sign in to comment.