Browse files

moved types into the separate types package -- now the namespace is n…

…ot flooded with non-test-specific objects
  • Loading branch information...
1 parent 8cf3084 commit 69942bf79f4d8d08e4ed3fffbbddc63c240805fa Onsi Fakhouri committed Oct 18, 2013
Showing with 143 additions and 142 deletions.
  1. +6 −10 benchmarker.go
  2. +24 −23 default_reporter.go
  3. +0 −25 enums_and_types.go
  4. +34 −34 example.go
  5. +7 −6 example_collection.go
  6. +19 −19 example_test.go
  7. +14 −2 ginkgo.go
  8. +9 −8 ginkgo_suite_test.go
  9. +1 −1 measure_node.go
  10. +29 −14 reporter_interface.go → types/example_types.go
View
16 benchmarker.go
@@ -1,22 +1,18 @@
package ginkgo
import (
+ "github.com/onsi/ginkgo/types"
"math"
"time"
)
-type Benchmarker interface {
- Time(name string, body func(), info ...interface{}) (elapsedTime time.Duration)
- RecordValue(name string, value float64, info ...interface{})
-}
-
type benchmarker struct {
- measurements map[string]*ExampleMeasurement
+ measurements map[string]*types.ExampleMeasurement
}
func newBenchmarker() *benchmarker {
return &benchmarker{
- measurements: make(map[string]*ExampleMeasurement, 0),
+ measurements: make(map[string]*types.ExampleMeasurement, 0),
}
}
@@ -36,15 +32,15 @@ func (b *benchmarker) RecordValue(name string, value float64, info ...interface{
measurement.Results = append(measurement.Results, value)
}
-func (b *benchmarker) getMeasurement(name string, smallestLabel string, largestLabel string, averageLabel string, units string, info ...interface{}) *ExampleMeasurement {
+func (b *benchmarker) getMeasurement(name string, smallestLabel string, largestLabel string, averageLabel string, units string, info ...interface{}) *types.ExampleMeasurement {
measurement, ok := b.measurements[name]
if !ok {
var computedInfo interface{}
computedInfo = nil
if len(info) > 0 {
computedInfo = info[0]
}
- measurement = &ExampleMeasurement{
+ measurement = &types.ExampleMeasurement{
Name: name,
Info: computedInfo,
SmallestLabel: smallestLabel,
@@ -59,7 +55,7 @@ func (b *benchmarker) getMeasurement(name string, smallestLabel string, largestL
return measurement
}
-func (b *benchmarker) measurementsReport() map[string]*ExampleMeasurement {
+func (b *benchmarker) measurementsReport() map[string]*types.ExampleMeasurement {
for _, measurement := range b.measurements {
measurement.Smallest = math.MaxFloat64
measurement.Largest = -math.MaxFloat64
View
47 default_reporter.go
@@ -2,6 +2,7 @@ package ginkgo
import (
"github.com/onsi/ginkgo/config"
+ "github.com/onsi/ginkgo/types"
"fmt"
"strings"
@@ -73,7 +74,7 @@ func (reporter *defaultReporter) println(indentation int, format string, args ..
fmt.Println(reporter.indent(indentation, format, args...))
}
-func (reporter *defaultReporter) SpecSuiteWillBegin(config config.GinkgoConfigType, summary *SuiteSummary) {
+func (reporter *defaultReporter) SpecSuiteWillBegin(config config.GinkgoConfigType, summary *types.SuiteSummary) {
reporter.printNewLine()
reporter.printBanner(fmt.Sprintf("Running Suite: %s", summary.SuiteDescription), "=")
@@ -101,9 +102,9 @@ func (reporter *defaultReporter) SpecSuiteWillBegin(config config.GinkgoConfigTy
reporter.printNewLine()
}
-func (reporter *defaultReporter) ExampleWillRun(exampleSummary *ExampleSummary) {
+func (reporter *defaultReporter) ExampleWillRun(exampleSummary *types.ExampleSummary) {
if reporter.config.Verbose {
- if exampleSummary.State != ExampleStatePending && exampleSummary.State != ExampleStateSkipped {
+ if exampleSummary.State != types.ExampleStatePending && exampleSummary.State != types.ExampleStateSkipped {
colors := []string{defaultStyle, grayColor}
for i, text := range exampleSummary.ComponentTexts[1 : len(exampleSummary.ComponentTexts)-1] {
reporter.print(0, reporter.colorize(colors[i%2], text)+" ")
@@ -117,26 +118,26 @@ func (reporter *defaultReporter) ExampleWillRun(exampleSummary *ExampleSummary)
}
}
-func (reporter *defaultReporter) ExampleDidComplete(exampleSummary *ExampleSummary) {
- if exampleSummary.State == ExampleStatePassed {
+func (reporter *defaultReporter) ExampleDidComplete(exampleSummary *types.ExampleSummary) {
+ if exampleSummary.State == types.ExampleStatePassed {
reporter.printStatus(greenColor, "", exampleSummary)
- } else if exampleSummary.State == ExampleStatePending {
+ } else if exampleSummary.State == types.ExampleStatePending {
reporter.printStatus(yellowColor, "P", exampleSummary)
- } else if exampleSummary.State == ExampleStateSkipped {
+ } else if exampleSummary.State == types.ExampleStateSkipped {
reporter.printStatus(cyanColor, "S", exampleSummary)
- } else if exampleSummary.State == ExampleStateTimedOut {
+ } else if exampleSummary.State == types.ExampleStateTimedOut {
reporter.printFailure("•... Timeout", exampleSummary)
- } else if exampleSummary.State == ExampleStatePanicked {
+ } else if exampleSummary.State == types.ExampleStatePanicked {
reporter.printFailure("•! Panic", exampleSummary)
- } else if exampleSummary.State == ExampleStateFailed {
+ } else if exampleSummary.State == types.ExampleStateFailed {
reporter.printFailure("• Failure", exampleSummary)
}
if reporter.config.Verbose && !reporter.lastExampleWasABlock {
reporter.printNewLine()
}
}
-func (reporter *defaultReporter) SpecSuiteDidEnd(summary *SuiteSummary) {
+func (reporter *defaultReporter) SpecSuiteDidEnd(summary *types.SuiteSummary) {
reporter.printNewLine()
color := greenColor
if !summary.SuiteSucceeded {
@@ -162,7 +163,7 @@ func (reporter *defaultReporter) SpecSuiteDidEnd(summary *SuiteSummary) {
reporter.printNewLine()
}
-func (reporter *defaultReporter) printBlockWithMessage(header string, message string, exampleSummary *ExampleSummary) {
+func (reporter *defaultReporter) printBlockWithMessage(header string, message string, exampleSummary *types.ExampleSummary) {
if !reporter.lastExampleWasABlock {
if !reporter.config.Verbose {
reporter.printNewLine()
@@ -194,10 +195,10 @@ func (reporter *defaultReporter) printBlockWithMessage(header string, message st
reporter.lastExampleWasABlock = true
}
-func (reporter *defaultReporter) printStatus(color string, message string, exampleSummary *ExampleSummary) {
- if exampleSummary.State == ExampleStatePending && reporter.config.NoisyPendings {
+func (reporter *defaultReporter) printStatus(color string, message string, exampleSummary *types.ExampleSummary) {
+ if exampleSummary.State == types.ExampleStatePending && reporter.config.NoisyPendings {
reporter.printBlockWithMessage(reporter.colorize(color, "%s [PENDING]", message), "", exampleSummary)
- } else if exampleSummary.State == ExampleStatePassed && exampleSummary.IsMeasurement {
+ } else if exampleSummary.State == types.ExampleStatePassed && exampleSummary.IsMeasurement {
reporter.printBlockWithMessage(reporter.colorize(color, "%s [MEASUREMENT]", message), reporter.measurementReport(exampleSummary), exampleSummary)
} else if exampleSummary.RunTime.Seconds() >= reporter.config.SlowSpecThreshold {
reporter.printBlockWithMessage(reporter.colorize(color, "%s [SLOW TEST:%.3f seconds]", message, exampleSummary.RunTime.Seconds()), "", exampleSummary)
@@ -207,7 +208,7 @@ func (reporter *defaultReporter) printStatus(color string, message string, examp
}
}
-func (reporter *defaultReporter) measurementReport(exampleSummary *ExampleSummary) (message string) {
+func (reporter *defaultReporter) measurementReport(exampleSummary *types.ExampleSummary) (message string) {
if len(exampleSummary.Measurements) == 0 {
return "Found no measurements"
}
@@ -244,7 +245,7 @@ func (reporter *defaultReporter) measurementReport(exampleSummary *ExampleSummar
return
}
-func (reporter *defaultReporter) printFailure(message string, exampleSummary *ExampleSummary) {
+func (reporter *defaultReporter) printFailure(message string, exampleSummary *types.ExampleSummary) {
if !reporter.lastExampleWasABlock {
if !reporter.config.Verbose {
reporter.printNewLine()
@@ -263,15 +264,15 @@ func (reporter *defaultReporter) printFailure(message string, exampleSummary *Ex
if i == exampleSummary.Failure.ComponentIndex {
blockType := ""
switch exampleSummary.Failure.ComponentType {
- case ExampleComponentTypeBeforeEach:
+ case types.ExampleComponentTypeBeforeEach:
blockType = "BeforeEach"
- case ExampleComponentTypeJustBeforeEach:
+ case types.ExampleComponentTypeJustBeforeEach:
blockType = "JustBeforeEach"
- case ExampleComponentTypeAfterEach:
+ case types.ExampleComponentTypeAfterEach:
blockType = "AfterEach"
- case ExampleComponentTypeIt:
+ case types.ExampleComponentTypeIt:
blockType = "It"
- case ExampleComponentTypeMeasure:
+ case types.ExampleComponentTypeMeasure:
blockType = "Measurement"
}
reporter.println(i+offset, reporter.colorize(redColor+boldStyle, "%s [%s]", exampleSummary.ComponentTexts[i], blockType))
@@ -285,7 +286,7 @@ func (reporter *defaultReporter) printFailure(message string, exampleSummary *Ex
indentation := exampleSummary.Failure.ComponentIndex + offset
reporter.printNewLine()
- if exampleSummary.State == ExampleStatePanicked {
+ if exampleSummary.State == types.ExampleStatePanicked {
reporter.println(indentation, reporter.colorize(redColor+boldStyle, exampleSummary.Failure.Message))
reporter.println(indentation, reporter.colorize(redColor, "%v", exampleSummary.Failure.ForwardedPanic))
reporter.println(indentation, exampleSummary.Failure.Location.String())
View
25 enums_and_types.go
@@ -42,28 +42,3 @@ const (
nodeTypeIt
nodeTypeMeasure
)
-
-type ExampleState uint
-
-const (
- ExampleStateInvalid ExampleState = iota
-
- ExampleStatePending
- ExampleStateSkipped
- ExampleStatePassed
- ExampleStateFailed
- ExampleStatePanicked
- ExampleStateTimedOut
-)
-
-type ExampleComponentType uint
-
-const (
- ExampleComponentTypeInvalid ExampleComponentType = iota
-
- ExampleComponentTypeBeforeEach
- ExampleComponentTypeJustBeforeEach
- ExampleComponentTypeAfterEach
- ExampleComponentTypeIt
- ExampleComponentTypeMeasure
-)
View
68 example.go
@@ -11,9 +11,9 @@ type example struct {
containers []*containerNode
- state ExampleState
+ state types.ExampleState
runTime time.Duration
- failure ExampleFailure
+ failure types.ExampleFailure
didInterceptFailure bool
interceptedFailure failureData
}
@@ -25,7 +25,7 @@ func newExample(subject exampleSubject) *example {
}
if subject.getFlag() == flagTypePending {
- ex.state = ExampleStatePending
+ ex.state = types.ExampleStatePending
}
return ex
@@ -36,7 +36,7 @@ func (ex *example) addContainerNode(container *containerNode) {
if container.flag == flagTypeFocused {
ex.focused = true
} else if container.flag == flagTypePending {
- ex.state = ExampleStatePending
+ ex.state = types.ExampleStatePending
}
}
@@ -48,14 +48,14 @@ func (ex *example) fail(failure failureData) {
}
func (ex *example) skip() {
- ex.state = ExampleStateSkipped
+ ex.state = types.ExampleStateSkipped
}
-func (ex *example) subjectComponentType() ExampleComponentType {
+func (ex *example) subjectComponentType() types.ExampleComponentType {
if ex.subject.nodeType() == nodeTypeMeasure {
- return ExampleComponentTypeMeasure
+ return types.ExampleComponentTypeMeasure
} else {
- return ExampleComponentTypeIt
+ return types.ExampleComponentTypeIt
}
}
@@ -68,15 +68,15 @@ func (ex *example) desiredNumberOfSamples() int {
}
func (ex *example) failed() bool {
- return ex.state == ExampleStateFailed || ex.state == ExampleStatePanicked || ex.state == ExampleStateTimedOut
+ return ex.state == types.ExampleStateFailed || ex.state == types.ExampleStatePanicked || ex.state == types.ExampleStateTimedOut
}
func (ex *example) skippedOrPending() bool {
- return ex.state == ExampleStateSkipped || ex.state == ExampleStatePending
+ return ex.state == types.ExampleStateSkipped || ex.state == types.ExampleStatePending
}
func (ex *example) pending() bool {
- return ex.state == ExampleStatePending
+ return ex.state == types.ExampleStatePending
}
func (ex *example) run() {
@@ -88,15 +88,15 @@ func (ex *example) run() {
for sample := 0; sample < ex.desiredNumberOfSamples(); sample++ {
ex.state, ex.failure = ex.runSample(sample)
- if ex.state != ExampleStatePassed {
+ if ex.state != types.ExampleStatePassed {
return
}
}
}
-func (ex *example) runSample(sample int) (exampleState ExampleState, exampleFailure ExampleFailure) {
- exampleState = ExampleStatePassed
- exampleFailure = ExampleFailure{}
+func (ex *example) runSample(sample int) (exampleState types.ExampleState, exampleFailure types.ExampleFailure) {
+ exampleState = types.ExampleStatePassed
+ exampleFailure = types.ExampleFailure{}
innerMostContainerIndexToUnwind := 0
defer func() {
@@ -105,8 +105,8 @@ func (ex *example) runSample(sample int) (exampleState ExampleState, exampleFail
container := ex.containers[i]
for _, afterEach := range container.afterEachNodes {
outcome, failure := afterEach.run()
- afterEachState, afterEachFailure := ex.processOutcomeAndFailure(i, ExampleComponentTypeAfterEach, afterEach.codeLocation, outcome, failure)
- if afterEachState != ExampleStatePassed && exampleState == ExampleStatePassed {
+ afterEachState, afterEachFailure := ex.processOutcomeAndFailure(i, types.ExampleComponentTypeAfterEach, afterEach.codeLocation, outcome, failure)
+ if afterEachState != types.ExampleStatePassed && exampleState == types.ExampleStatePassed {
exampleState = afterEachState
exampleFailure = afterEachFailure
}
@@ -119,8 +119,8 @@ func (ex *example) runSample(sample int) (exampleState ExampleState, exampleFail
innerMostContainerIndexToUnwind = i
for _, beforeEach := range container.beforeEachNodes {
outcome, failure := beforeEach.run()
- exampleState, exampleFailure = ex.processOutcomeAndFailure(i, ExampleComponentTypeBeforeEach, beforeEach.codeLocation, outcome, failure)
- if exampleState != ExampleStatePassed {
+ exampleState, exampleFailure = ex.processOutcomeAndFailure(i, types.ExampleComponentTypeBeforeEach, beforeEach.codeLocation, outcome, failure)
+ if exampleState != types.ExampleStatePassed {
return
}
}
@@ -129,8 +129,8 @@ func (ex *example) runSample(sample int) (exampleState ExampleState, exampleFail
for i, container := range ex.containers {
for _, justBeforeEach := range container.justBeforeEachNodes {
outcome, failure := justBeforeEach.run()
- exampleState, exampleFailure = ex.processOutcomeAndFailure(i, ExampleComponentTypeJustBeforeEach, justBeforeEach.codeLocation, outcome, failure)
- if exampleState != ExampleStatePassed {
+ exampleState, exampleFailure = ex.processOutcomeAndFailure(i, types.ExampleComponentTypeJustBeforeEach, justBeforeEach.codeLocation, outcome, failure)
+ if exampleState != types.ExampleStatePassed {
return
}
}
@@ -139,29 +139,29 @@ func (ex *example) runSample(sample int) (exampleState ExampleState, exampleFail
outcome, failure := ex.subject.run()
exampleState, exampleFailure = ex.processOutcomeAndFailure(len(ex.containers), ex.subjectComponentType(), ex.subject.getCodeLocation(), outcome, failure)
- if exampleState != ExampleStatePassed {
+ if exampleState != types.ExampleStatePassed {
return
}
return
}
-func (ex *example) processOutcomeAndFailure(containerIndex int, componentType ExampleComponentType, codeLocation types.CodeLocation, outcome runOutcome, failure failureData) (exampleState ExampleState, exampleFailure ExampleFailure) {
- exampleFailure = ExampleFailure{}
- exampleState = ExampleStatePassed
+func (ex *example) processOutcomeAndFailure(containerIndex int, componentType types.ExampleComponentType, codeLocation types.CodeLocation, outcome runOutcome, failure failureData) (exampleState types.ExampleState, exampleFailure types.ExampleFailure) {
+ exampleFailure = types.ExampleFailure{}
+ exampleState = types.ExampleStatePassed
if ex.didInterceptFailure {
- exampleState = ExampleStateFailed
+ exampleState = types.ExampleStateFailed
failure = ex.interceptedFailure
} else if outcome == runOutcomePanicked {
- exampleState = ExampleStatePanicked
+ exampleState = types.ExampleStatePanicked
} else if outcome == runOutcomeTimedOut {
- exampleState = ExampleStateTimedOut
+ exampleState = types.ExampleStateTimedOut
} else {
return
}
- exampleFailure = ExampleFailure{
+ exampleFailure = types.ExampleFailure{
Message: failure.message,
Location: failure.codeLocation,
ForwardedPanic: failure.forwardedPanic,
@@ -173,7 +173,7 @@ func (ex *example) processOutcomeAndFailure(containerIndex int, componentType Ex
return
}
-func (ex *example) summary() *ExampleSummary {
+func (ex *example) summary() *types.ExampleSummary {
componentTexts := make([]string, len(ex.containers)+1)
componentCodeLocations := make([]types.CodeLocation, len(ex.containers)+1)
@@ -185,8 +185,8 @@ func (ex *example) summary() *ExampleSummary {
componentTexts[len(ex.containers)] = ex.subject.getText()
componentCodeLocations[len(ex.containers)] = ex.subject.getCodeLocation()
- return &ExampleSummary{
- IsMeasurement: ex.subjectComponentType() == ExampleComponentTypeMeasure,
+ return &types.ExampleSummary{
+ IsMeasurement: ex.subjectComponentType() == types.ExampleComponentTypeMeasure,
NumberOfSamples: ex.desiredNumberOfSamples(),
ComponentTexts: componentTexts,
ComponentCodeLocations: componentCodeLocations,
@@ -197,8 +197,8 @@ func (ex *example) summary() *ExampleSummary {
}
}
-func (ex *example) measurementsReport() (measurements map[string]*ExampleMeasurement) {
- if ex.subjectComponentType() != ExampleComponentTypeMeasure {
+func (ex *example) measurementsReport() (measurements map[string]*types.ExampleMeasurement) {
+ if ex.subjectComponentType() != types.ExampleComponentTypeMeasure {
return
}
if ex.failed() {
View
13 example_collection.go
@@ -2,6 +2,7 @@ package ginkgo
import (
"github.com/onsi/ginkgo/config"
+ "github.com/onsi/ginkgo/types"
"math/rand"
"regexp"
@@ -108,7 +109,7 @@ func (collection *exampleCollection) trimForParallelization(parallelTotal int, p
func (collection *exampleCollection) skipMeasurements() {
for _, example := range collection.examples {
- if example.subjectComponentType() == ExampleComponentTypeMeasure {
+ if example.subjectComponentType() == types.ExampleComponentTypeMeasure {
example.skip()
}
}
@@ -200,21 +201,21 @@ func (collection *exampleCollection) countExamplesSatisfying(filter func(ex *exa
return count
}
-func (collection *exampleCollection) summary() *SuiteSummary {
+func (collection *exampleCollection) summary() *types.SuiteSummary {
numberOfExamplesThatWillBeRun := collection.countExamplesSatisfying(func(ex *example) bool {
return !ex.skippedOrPending()
})
numberOfPendingExamples := collection.countExamplesSatisfying(func(ex *example) bool {
- return ex.state == ExampleStatePending
+ return ex.state == types.ExampleStatePending
})
numberOfSkippedExamples := collection.countExamplesSatisfying(func(ex *example) bool {
- return ex.state == ExampleStateSkipped
+ return ex.state == types.ExampleStateSkipped
})
numberOfPassedExamples := collection.countExamplesSatisfying(func(ex *example) bool {
- return ex.state == ExampleStatePassed
+ return ex.state == types.ExampleStatePassed
})
numberOfFailedExamples := collection.countExamplesSatisfying(func(ex *example) bool {
@@ -229,7 +230,7 @@ func (collection *exampleCollection) summary() *SuiteSummary {
success = false
}
- return &SuiteSummary{
+ return &types.SuiteSummary{
SuiteDescription: collection.description,
SuiteSucceeded: success,
View
38 example_test.go
@@ -78,7 +78,7 @@ func init() {
})
It("should be in the pending state", func() {
- Ω(ex.state).Should(Equal(ExampleStatePending))
+ Ω(ex.state).Should(Equal(types.ExampleStatePending))
})
})
@@ -88,7 +88,7 @@ func init() {
})
It("should be in the pending state", func() {
- Ω(ex.state).Should(Equal(ExampleStatePending))
+ Ω(ex.state).Should(Equal(types.ExampleStatePending))
})
})
@@ -100,7 +100,7 @@ func init() {
It("should be focused and have the pending state", func() {
Ω(ex.focused).Should(BeTrue())
- Ω(ex.state).Should(Equal(ExampleStatePending))
+ Ω(ex.state).Should(Equal(types.ExampleStatePending))
})
})
})
@@ -109,7 +109,7 @@ func init() {
It("should mark the example as skipped", func() {
ex := newExample(it)
ex.skip()
- Ω(ex.state).Should(Equal(ExampleStateSkipped))
+ Ω(ex.state).Should(Equal(types.ExampleStateSkipped))
})
})
@@ -190,7 +190,7 @@ func init() {
})
It("should report that it has an it node", func() {
- Ω(ex.subjectComponentType()).Should(Equal(ExampleComponentTypeIt))
+ Ω(ex.subjectComponentType()).Should(Equal(types.ExampleComponentTypeIt))
})
It("runs the before/justBefore/after nodes in each of the containers, and the it node, in the correct order", func() {
@@ -229,14 +229,14 @@ func init() {
It("has a summary reporting no failure", func() {
ex.run()
summary := ex.summary()
- Ω(summary.State).Should(Equal(ExampleStatePassed))
+ Ω(summary.State).Should(Equal(types.ExampleStatePassed))
Ω(summary.RunTime.Seconds()).Should(BeNumerically(">", 0.01))
Ω(summary.IsMeasurement).Should(BeFalse())
})
})
componentTypes := []string{"BeforeEach", "JustBeforeEach", "AfterEach"}
- expectedComponentTypes := []ExampleComponentType{ExampleComponentTypeBeforeEach, ExampleComponentTypeJustBeforeEach, ExampleComponentTypeAfterEach}
+ expectedComponentTypes := []types.ExampleComponentType{types.ExampleComponentTypeBeforeEach, types.ExampleComponentTypeJustBeforeEach, types.ExampleComponentTypeAfterEach}
pushFuncs := []func(container *containerNode, node *runnableNode){(*containerNode).pushBeforeEachNode, (*containerNode).pushJustBeforeEachNode, (*containerNode).pushAfterEachNode}
for i := range componentTypes {
@@ -267,7 +267,7 @@ func init() {
ex.run()
summary := ex.summary()
- Ω(summary.State).Should(Equal(ExampleStateFailed))
+ Ω(summary.State).Should(Equal(types.ExampleStateFailed))
Ω(summary.Failure.Message).Should(Equal(failure.message))
Ω(summary.Failure.Location).Should(Equal(failure.codeLocation))
Ω(summary.Failure.ForwardedPanic).Should(BeNil())
@@ -295,7 +295,7 @@ func init() {
ex.run()
summary := ex.summary()
- Ω(summary.State).Should(Equal(ExampleStatePanicked))
+ Ω(summary.State).Should(Equal(types.ExampleStatePanicked))
Ω(summary.Failure.Message).Should(Equal("Test Panicked"))
Ω(summary.Failure.Location.FileName).Should(Equal(panicCodeLocation.FileName))
Ω(summary.Failure.Location.LineNumber).Should(Equal(panicCodeLocation.LineNumber+1), "Expect panic code location to be correct")
@@ -322,7 +322,7 @@ func init() {
ex.run()
summary := ex.summary()
- Ω(summary.State).Should(Equal(ExampleStateTimedOut))
+ Ω(summary.State).Should(Equal(types.ExampleStateTimedOut))
Ω(summary.Failure.Message).Should(Equal("Timed out"))
Ω(summary.Failure.Location).Should(Equal(componentCodeLocation))
Ω(summary.Failure.ForwardedPanic).Should(BeNil())
@@ -361,12 +361,12 @@ func init() {
ex.run()
summary := ex.summary()
- Ω(summary.State).Should(Equal(ExampleStateFailed))
+ Ω(summary.State).Should(Equal(types.ExampleStateFailed))
Ω(summary.Failure.Message).Should(Equal(failure.message))
Ω(summary.Failure.Location).Should(Equal(failure.codeLocation))
Ω(summary.Failure.ForwardedPanic).Should(BeNil())
Ω(summary.Failure.ComponentIndex).Should(Equal(2), "Should be the it node that failed")
- Ω(summary.Failure.ComponentType).Should(Equal(ExampleComponentTypeIt))
+ Ω(summary.Failure.ComponentType).Should(Equal(types.ExampleComponentTypeIt))
Ω(summary.Failure.ComponentCodeLocation).Should(Equal(componentCodeLocation))
Ω(ex.failed()).Should(BeTrue())
@@ -387,13 +387,13 @@ func init() {
ex.run()
summary := ex.summary()
- Ω(summary.State).Should(Equal(ExampleStatePanicked))
+ Ω(summary.State).Should(Equal(types.ExampleStatePanicked))
Ω(summary.Failure.Message).Should(Equal("Test Panicked"))
Ω(summary.Failure.Location.FileName).Should(Equal(panicCodeLocation.FileName))
Ω(summary.Failure.Location.LineNumber).Should(Equal(panicCodeLocation.LineNumber+1), "Expect panic code location to be correct")
Ω(summary.Failure.ForwardedPanic).Should(Equal("kaboom!"))
Ω(summary.Failure.ComponentIndex).Should(Equal(2), "Should be the it node that failed")
- Ω(summary.Failure.ComponentType).Should(Equal(ExampleComponentTypeIt))
+ Ω(summary.Failure.ComponentType).Should(Equal(types.ExampleComponentTypeIt))
Ω(summary.Failure.ComponentCodeLocation).Should(Equal(componentCodeLocation))
Ω(ex.failed()).Should(BeTrue())
@@ -412,12 +412,12 @@ func init() {
ex.run()
summary := ex.summary()
- Ω(summary.State).Should(Equal(ExampleStateTimedOut))
+ Ω(summary.State).Should(Equal(types.ExampleStateTimedOut))
Ω(summary.Failure.Message).Should(Equal("Timed out"))
Ω(summary.Failure.Location).Should(Equal(componentCodeLocation))
Ω(summary.Failure.ForwardedPanic).Should(BeNil())
Ω(summary.Failure.ComponentIndex).Should(Equal(2), "Should be the it node that failed")
- Ω(summary.Failure.ComponentType).Should(Equal(ExampleComponentTypeIt))
+ Ω(summary.Failure.ComponentType).Should(Equal(types.ExampleComponentTypeIt))
Ω(summary.Failure.ComponentCodeLocation).Should(Equal(componentCodeLocation))
Ω(ex.failed()).Should(BeTrue())
@@ -440,7 +440,7 @@ func init() {
It("should report that it has a measurement", func() {
ex = newExample(newMeasureNode("measure", func(b Benchmarker) {}, flagTypeNone, componentCodeLocation, 1))
- Ω(ex.subjectComponentType()).Should(Equal(ExampleComponentTypeMeasure))
+ Ω(ex.subjectComponentType()).Should(Equal(types.ExampleComponentTypeMeasure))
})
Context("when the measurement does not fail", func() {
@@ -457,7 +457,7 @@ func init() {
Ω(runs).Should(Equal(5))
- Ω(summary.State).Should(Equal(ExampleStatePassed))
+ Ω(summary.State).Should(Equal(types.ExampleStatePassed))
Ω(summary.IsMeasurement).Should(BeTrue())
Ω(summary.NumberOfSamples).Should(Equal(5))
Ω(summary.Measurements).Should(HaveLen(1))
@@ -483,7 +483,7 @@ func init() {
Ω(runs).Should(Equal(3))
- Ω(summary.State).Should(Equal(ExampleStateFailed))
+ Ω(summary.State).Should(Equal(types.ExampleStateFailed))
Ω(summary.IsMeasurement).Should(BeTrue())
Ω(summary.NumberOfSamples).Should(Equal(5))
Ω(summary.Measurements).Should(BeEmpty())
View
16 ginkgo.go
@@ -19,6 +19,20 @@ func init() {
globalSuite = newSuite()
}
+type Reporter interface {
+ SpecSuiteWillBegin(config config.GinkgoConfigType, summary *types.SuiteSummary)
+ ExampleWillRun(exampleSummary *types.ExampleSummary)
+ ExampleDidComplete(exampleSummary *types.ExampleSummary)
+ SpecSuiteDidEnd(summary *types.SuiteSummary)
+}
+
+type Done chan<- interface{}
+
+type Benchmarker interface {
+ Time(name string, body func(), info ...interface{}) (elapsedTime time.Duration)
+ RecordValue(name string, value float64, info ...interface{})
+}
+
func RunSpecs(t *testing.T, description string) {
globalSuite.run(t, description, []Reporter{newDefaultReporter(config.DefaultReporterConfig)}, config.GinkgoConfig)
}
@@ -32,8 +46,6 @@ func RunSpecsWithCustomReporters(t *testing.T, description string, reporters []R
globalSuite.run(t, description, reporters, config.GinkgoConfig)
}
-type Done chan<- interface{}
-
func Fail(message string, callerSkip ...int) {
skip := 0
if len(callerSkip) > 0 {
View
17 ginkgo_suite_test.go
@@ -2,6 +2,7 @@ package ginkgo
import (
"github.com/onsi/ginkgo/config"
+ "github.com/onsi/ginkgo/types"
. "github.com/onsi/gomega"
"math/rand"
@@ -39,25 +40,25 @@ func (fakeT *fakeTestingT) Fail() {
type fakeReporter struct {
config config.GinkgoConfigType
- beginSummary *SuiteSummary
- exampleWillRunSummaries []*ExampleSummary
- exampleSummaries []*ExampleSummary
- endSummary *SuiteSummary
+ beginSummary *types.SuiteSummary
+ exampleWillRunSummaries []*types.ExampleSummary
+ exampleSummaries []*types.ExampleSummary
+ endSummary *types.SuiteSummary
}
-func (fakeR *fakeReporter) SpecSuiteWillBegin(config config.GinkgoConfigType, summary *SuiteSummary) {
+func (fakeR *fakeReporter) SpecSuiteWillBegin(config config.GinkgoConfigType, summary *types.SuiteSummary) {
fakeR.config = config
fakeR.beginSummary = summary
}
-func (fakeR *fakeReporter) ExampleWillRun(exampleSummary *ExampleSummary) {
+func (fakeR *fakeReporter) ExampleWillRun(exampleSummary *types.ExampleSummary) {
fakeR.exampleWillRunSummaries = append(fakeR.exampleWillRunSummaries, exampleSummary)
}
-func (fakeR *fakeReporter) ExampleDidComplete(exampleSummary *ExampleSummary) {
+func (fakeR *fakeReporter) ExampleDidComplete(exampleSummary *types.ExampleSummary) {
fakeR.exampleSummaries = append(fakeR.exampleSummaries, exampleSummary)
}
-func (fakeR *fakeReporter) SpecSuiteDidEnd(summary *SuiteSummary) {
+func (fakeR *fakeReporter) SpecSuiteDidEnd(summary *types.SuiteSummary) {
fakeR.endSummary = summary
}
View
2 measure_node.go
@@ -30,7 +30,7 @@ func (node *measureNode) run() (outcome runOutcome, failure failureData) {
return runOutcomeCompleted, failureData{}
}
-func (node *measureNode) measurementsReport() map[string]*ExampleMeasurement {
+func (node *measureNode) measurementsReport() map[string]*types.ExampleMeasurement {
return node.benchmarker.measurementsReport()
}
View
43 reporter_interface.go → types/example_types.go
@@ -1,19 +1,9 @@
-package ginkgo
+package types
import (
- "github.com/onsi/ginkgo/config"
- "github.com/onsi/ginkgo/types"
-
"time"
)
-type Reporter interface {
- SpecSuiteWillBegin(config config.GinkgoConfigType, summary *SuiteSummary)
- ExampleWillRun(exampleSummary *ExampleSummary)
- ExampleDidComplete(exampleSummary *ExampleSummary)
- SpecSuiteDidEnd(summary *SuiteSummary)
-}
-
type SuiteSummary struct {
SuiteDescription string
SuiteSucceeded bool
@@ -30,7 +20,7 @@ type SuiteSummary struct {
type ExampleSummary struct {
ComponentTexts []string
- ComponentCodeLocations []types.CodeLocation
+ ComponentCodeLocations []CodeLocation
State ExampleState
RunTime time.Duration
@@ -42,12 +32,12 @@ type ExampleSummary struct {
type ExampleFailure struct {
Message string
- Location types.CodeLocation
+ Location CodeLocation
ForwardedPanic interface{}
ComponentIndex int
ComponentType ExampleComponentType
- ComponentCodeLocation types.CodeLocation
+ ComponentCodeLocation CodeLocation
}
type ExampleMeasurement struct {
@@ -66,3 +56,28 @@ type ExampleMeasurement struct {
AverageLabel string
Units string
}
+
+type ExampleState uint
+
+const (
+ ExampleStateInvalid ExampleState = iota
+
+ ExampleStatePending
+ ExampleStateSkipped
+ ExampleStatePassed
+ ExampleStateFailed
+ ExampleStatePanicked
+ ExampleStateTimedOut
+)
+
+type ExampleComponentType uint
+
+const (
+ ExampleComponentTypeInvalid ExampleComponentType = iota
+
+ ExampleComponentTypeBeforeEach
+ ExampleComponentTypeJustBeforeEach
+ ExampleComponentTypeAfterEach
+ ExampleComponentTypeIt
+ ExampleComponentTypeMeasure
+)

0 comments on commit 69942bf

Please sign in to comment.