Skip to content

Commit

Permalink
moved types into the separate types package -- now the namespace is n…
Browse files Browse the repository at this point in the history
…ot flooded with non-test-specific objects
  • Loading branch information
Onsi Fakhouri committed Oct 18, 2013
1 parent 8cf3084 commit 69942bf
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 142 deletions.
16 changes: 6 additions & 10 deletions benchmarker.go
@@ -1,22 +1,18 @@
package ginkgo package ginkgo


import ( import (
"github.com/onsi/ginkgo/types"
"math" "math"
"time" "time"
) )


type Benchmarker interface {
Time(name string, body func(), info ...interface{}) (elapsedTime time.Duration)
RecordValue(name string, value float64, info ...interface{})
}

type benchmarker struct { type benchmarker struct {
measurements map[string]*ExampleMeasurement measurements map[string]*types.ExampleMeasurement
} }


func newBenchmarker() *benchmarker { func newBenchmarker() *benchmarker {
return &benchmarker{ return &benchmarker{
measurements: make(map[string]*ExampleMeasurement, 0), measurements: make(map[string]*types.ExampleMeasurement, 0),
} }
} }


Expand All @@ -36,15 +32,15 @@ func (b *benchmarker) RecordValue(name string, value float64, info ...interface{
measurement.Results = append(measurement.Results, value) 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] measurement, ok := b.measurements[name]
if !ok { if !ok {
var computedInfo interface{} var computedInfo interface{}
computedInfo = nil computedInfo = nil
if len(info) > 0 { if len(info) > 0 {
computedInfo = info[0] computedInfo = info[0]
} }
measurement = &ExampleMeasurement{ measurement = &types.ExampleMeasurement{
Name: name, Name: name,
Info: computedInfo, Info: computedInfo,
SmallestLabel: smallestLabel, SmallestLabel: smallestLabel,
Expand All @@ -59,7 +55,7 @@ func (b *benchmarker) getMeasurement(name string, smallestLabel string, largestL
return measurement return measurement
} }


func (b *benchmarker) measurementsReport() map[string]*ExampleMeasurement { func (b *benchmarker) measurementsReport() map[string]*types.ExampleMeasurement {
for _, measurement := range b.measurements { for _, measurement := range b.measurements {
measurement.Smallest = math.MaxFloat64 measurement.Smallest = math.MaxFloat64
measurement.Largest = -math.MaxFloat64 measurement.Largest = -math.MaxFloat64
Expand Down
47 changes: 24 additions & 23 deletions default_reporter.go
Expand Up @@ -2,6 +2,7 @@ package ginkgo


import ( import (
"github.com/onsi/ginkgo/config" "github.com/onsi/ginkgo/config"
"github.com/onsi/ginkgo/types"


"fmt" "fmt"
"strings" "strings"
Expand Down Expand Up @@ -73,7 +74,7 @@ func (reporter *defaultReporter) println(indentation int, format string, args ..
fmt.Println(reporter.indent(indentation, format, 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.printNewLine()
reporter.printBanner(fmt.Sprintf("Running Suite: %s", summary.SuiteDescription), "=") reporter.printBanner(fmt.Sprintf("Running Suite: %s", summary.SuiteDescription), "=")


Expand Down Expand Up @@ -101,9 +102,9 @@ func (reporter *defaultReporter) SpecSuiteWillBegin(config config.GinkgoConfigTy
reporter.printNewLine() reporter.printNewLine()
} }


func (reporter *defaultReporter) ExampleWillRun(exampleSummary *ExampleSummary) { func (reporter *defaultReporter) ExampleWillRun(exampleSummary *types.ExampleSummary) {
if reporter.config.Verbose { if reporter.config.Verbose {
if exampleSummary.State != ExampleStatePending && exampleSummary.State != ExampleStateSkipped { if exampleSummary.State != types.ExampleStatePending && exampleSummary.State != types.ExampleStateSkipped {
colors := []string{defaultStyle, grayColor} colors := []string{defaultStyle, grayColor}
for i, text := range exampleSummary.ComponentTexts[1 : len(exampleSummary.ComponentTexts)-1] { for i, text := range exampleSummary.ComponentTexts[1 : len(exampleSummary.ComponentTexts)-1] {
reporter.print(0, reporter.colorize(colors[i%2], text)+" ") reporter.print(0, reporter.colorize(colors[i%2], text)+" ")
Expand All @@ -117,26 +118,26 @@ func (reporter *defaultReporter) ExampleWillRun(exampleSummary *ExampleSummary)
} }
} }


func (reporter *defaultReporter) ExampleDidComplete(exampleSummary *ExampleSummary) { func (reporter *defaultReporter) ExampleDidComplete(exampleSummary *types.ExampleSummary) {
if exampleSummary.State == ExampleStatePassed { if exampleSummary.State == types.ExampleStatePassed {
reporter.printStatus(greenColor, "•", exampleSummary) reporter.printStatus(greenColor, "•", exampleSummary)
} else if exampleSummary.State == ExampleStatePending { } else if exampleSummary.State == types.ExampleStatePending {
reporter.printStatus(yellowColor, "P", exampleSummary) reporter.printStatus(yellowColor, "P", exampleSummary)
} else if exampleSummary.State == ExampleStateSkipped { } else if exampleSummary.State == types.ExampleStateSkipped {
reporter.printStatus(cyanColor, "S", exampleSummary) reporter.printStatus(cyanColor, "S", exampleSummary)
} else if exampleSummary.State == ExampleStateTimedOut { } else if exampleSummary.State == types.ExampleStateTimedOut {
reporter.printFailure("•... Timeout", exampleSummary) reporter.printFailure("•... Timeout", exampleSummary)
} else if exampleSummary.State == ExampleStatePanicked { } else if exampleSummary.State == types.ExampleStatePanicked {
reporter.printFailure("•! Panic", exampleSummary) reporter.printFailure("•! Panic", exampleSummary)
} else if exampleSummary.State == ExampleStateFailed { } else if exampleSummary.State == types.ExampleStateFailed {
reporter.printFailure("• Failure", exampleSummary) reporter.printFailure("• Failure", exampleSummary)
} }
if reporter.config.Verbose && !reporter.lastExampleWasABlock { if reporter.config.Verbose && !reporter.lastExampleWasABlock {
reporter.printNewLine() reporter.printNewLine()
} }
} }


func (reporter *defaultReporter) SpecSuiteDidEnd(summary *SuiteSummary) { func (reporter *defaultReporter) SpecSuiteDidEnd(summary *types.SuiteSummary) {
reporter.printNewLine() reporter.printNewLine()
color := greenColor color := greenColor
if !summary.SuiteSucceeded { if !summary.SuiteSucceeded {
Expand All @@ -162,7 +163,7 @@ func (reporter *defaultReporter) SpecSuiteDidEnd(summary *SuiteSummary) {
reporter.printNewLine() 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.lastExampleWasABlock {
if !reporter.config.Verbose { if !reporter.config.Verbose {
reporter.printNewLine() reporter.printNewLine()
Expand Down Expand Up @@ -194,10 +195,10 @@ func (reporter *defaultReporter) printBlockWithMessage(header string, message st
reporter.lastExampleWasABlock = true reporter.lastExampleWasABlock = true
} }


func (reporter *defaultReporter) printStatus(color string, message string, exampleSummary *ExampleSummary) { func (reporter *defaultReporter) printStatus(color string, message string, exampleSummary *types.ExampleSummary) {
if exampleSummary.State == ExampleStatePending && reporter.config.NoisyPendings { if exampleSummary.State == types.ExampleStatePending && reporter.config.NoisyPendings {
reporter.printBlockWithMessage(reporter.colorize(color, "%s [PENDING]", message), "", exampleSummary) 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) reporter.printBlockWithMessage(reporter.colorize(color, "%s [MEASUREMENT]", message), reporter.measurementReport(exampleSummary), exampleSummary)
} else if exampleSummary.RunTime.Seconds() >= reporter.config.SlowSpecThreshold { } else if exampleSummary.RunTime.Seconds() >= reporter.config.SlowSpecThreshold {
reporter.printBlockWithMessage(reporter.colorize(color, "%s [SLOW TEST:%.3f seconds]", message, exampleSummary.RunTime.Seconds()), "", exampleSummary) reporter.printBlockWithMessage(reporter.colorize(color, "%s [SLOW TEST:%.3f seconds]", message, exampleSummary.RunTime.Seconds()), "", exampleSummary)
Expand All @@ -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 { if len(exampleSummary.Measurements) == 0 {
return "Found no measurements" return "Found no measurements"
} }
Expand Down Expand Up @@ -244,7 +245,7 @@ func (reporter *defaultReporter) measurementReport(exampleSummary *ExampleSummar
return return
} }


func (reporter *defaultReporter) printFailure(message string, exampleSummary *ExampleSummary) { func (reporter *defaultReporter) printFailure(message string, exampleSummary *types.ExampleSummary) {
if !reporter.lastExampleWasABlock { if !reporter.lastExampleWasABlock {
if !reporter.config.Verbose { if !reporter.config.Verbose {
reporter.printNewLine() reporter.printNewLine()
Expand All @@ -263,15 +264,15 @@ func (reporter *defaultReporter) printFailure(message string, exampleSummary *Ex
if i == exampleSummary.Failure.ComponentIndex { if i == exampleSummary.Failure.ComponentIndex {
blockType := "" blockType := ""
switch exampleSummary.Failure.ComponentType { switch exampleSummary.Failure.ComponentType {
case ExampleComponentTypeBeforeEach: case types.ExampleComponentTypeBeforeEach:
blockType = "BeforeEach" blockType = "BeforeEach"
case ExampleComponentTypeJustBeforeEach: case types.ExampleComponentTypeJustBeforeEach:
blockType = "JustBeforeEach" blockType = "JustBeforeEach"
case ExampleComponentTypeAfterEach: case types.ExampleComponentTypeAfterEach:
blockType = "AfterEach" blockType = "AfterEach"
case ExampleComponentTypeIt: case types.ExampleComponentTypeIt:
blockType = "It" blockType = "It"
case ExampleComponentTypeMeasure: case types.ExampleComponentTypeMeasure:
blockType = "Measurement" blockType = "Measurement"
} }
reporter.println(i+offset, reporter.colorize(redColor+boldStyle, "%s [%s]", exampleSummary.ComponentTexts[i], blockType)) reporter.println(i+offset, reporter.colorize(redColor+boldStyle, "%s [%s]", exampleSummary.ComponentTexts[i], blockType))
Expand All @@ -285,7 +286,7 @@ func (reporter *defaultReporter) printFailure(message string, exampleSummary *Ex
indentation := exampleSummary.Failure.ComponentIndex + offset indentation := exampleSummary.Failure.ComponentIndex + offset


reporter.printNewLine() 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+boldStyle, exampleSummary.Failure.Message))
reporter.println(indentation, reporter.colorize(redColor, "%v", exampleSummary.Failure.ForwardedPanic)) reporter.println(indentation, reporter.colorize(redColor, "%v", exampleSummary.Failure.ForwardedPanic))
reporter.println(indentation, exampleSummary.Failure.Location.String()) reporter.println(indentation, exampleSummary.Failure.Location.String())
Expand Down
25 changes: 0 additions & 25 deletions enums_and_types.go
Expand Up @@ -42,28 +42,3 @@ const (
nodeTypeIt nodeTypeIt
nodeTypeMeasure 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
)

0 comments on commit 69942bf

Please sign in to comment.