func setupFakeReporter() (*fakeReporter, *fakeGoTest) { myReporter := fakeReporter{} myReporter.calls = []string{} reporter = &myReporter runner = execution.NewRunner() runner.UpgradeReporter(reporter) return &myReporter, &fakeGoTest{} }
func TestMissingTopLevelGoTestReferenceCausesPanic(t *testing.T) { runner = execution.NewRunner() output := map[string]bool{} defer expectEqual(t, false, output["good"]) defer requireGoTestReference(t) Convey("Hi", func() { output["bad"] = true // this shouldn't happen }) }
func TestMissingTopLevelGoTestReferenceAfterGoodExample(t *testing.T) { runner = execution.NewRunner() output := map[string]bool{} defer func() { expectEqual(t, true, output["good"]) expectEqual(t, false, output["bad"]) }() defer requireGoTestReference(t) Convey("Good example", t, func() { output["good"] = true }) Convey("Bad example", func() { output["bad"] = true // shouldn't happen }) }
func TestExtraReferencePanics(t *testing.T) { runner = execution.NewRunner() output := map[string]bool{} defer func() { err := recover() if err == nil { t.Error("We should have recovered a panic here (because of an extra *testing.T reference)!") } else if !strings.HasPrefix(fmt.Sprintf("%v", err), execution.ExtraGoTest) { t.Error("Should have panicked with the 'extra go test' error!") } if output["bad"] { t.Error("We should NOT have run the bad example!") } }() Convey("Good example", t, func() { Convey("Bad example - passing in *testing.T a second time!", t, func() { output["bad"] = true // shouldn't happen }) }) }
func (self *suiteContext) Run(entry *execution.Registration) { key := resolveTestPackageAndFunctionName() if self.currentRunner() != nil { panic(execution.ExtraGoTest) } reporter := buildReporter() runner := execution.NewRunner() runner.UpgradeReporter(reporter) self.lock.Lock() self.runners[key] = runner self.reporters[key] = reporter self.lock.Unlock() runner.Begin(entry) runner.Run() self.lock.Lock() delete(self.runners, key) delete(self.reporters, key) self.lock.Unlock() }
func (self *suiteContext) Run(entry *execution.Registration) { if self.current() != nil { panic(execution.ExtraGoTest) } reporter := buildReporter() runner := execution.NewRunner() runner.UpgradeReporter(reporter) testName, location, _ := suiteAnchor() self.lock.Lock() self.locations[location] = testName self.runners[testName] = runner self.lock.Unlock() runner.Begin(entry) runner.Run() self.lock.Lock() delete(self.locations, location) delete(self.runners, testName) self.lock.Unlock() }
func prepare() string { runner = execution.NewRunner() reporting.QuietMode() return "" }
func configureRunner() { reporter = buildReporter() runner = execution.NewRunner() runner.UpgradeReporter(reporter) }