Skip to content

Commit

Permalink
Join the Stream and Verbose flags into verbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
come-maiz committed Jan 27, 2016
1 parent 08d0748 commit 2b6969e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 47 deletions.
17 changes: 12 additions & 5 deletions check.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ type suiteRunner struct {
reportedProblemLast bool
benchTime time.Duration
benchMem bool
stream bool
verbosity uint8
}

type RunConf struct {
Expand Down Expand Up @@ -552,17 +552,24 @@ func newSuiteRunner(suite interface{}, runConf *RunConf) *suiteRunner {
suiteType := reflect.TypeOf(suite)
suiteNumMethods := suiteType.NumMethod()
suiteValue := reflect.ValueOf(suite)

var verbosity uint8
if conf.Verbose {
verbosity = 1
}
if conf.Stream {
verbosity = 2
}

runner := &suiteRunner{
suite: suite,
output: newOutputWriter(conf.Output, conf.Stream, conf.Verbose),
output: newOutputWriter(conf.Output, verbosity),
tracker: newResultTracker(),
benchTime: conf.BenchmarkTime,
benchMem: conf.BenchmarkMem,
tempDir: &tempDir{},
keepDir: conf.KeepWorkDir,
tests: make([]*methodType, 0, suiteNumMethods),
stream: conf.Stream,
verbosity: verbosity,
}
if runner.benchTime == 0 {
runner.benchTime = 1 * time.Second
Expand Down Expand Up @@ -643,7 +650,7 @@ func (runner *suiteRunner) run() *Result {
// goroutine with the provided dispatcher for running it.
func (runner *suiteRunner) forkCall(method *methodType, kind funcKind, testName string, logb *logger, dispatcher func(c *C)) *C {
var logw io.Writer
if runner.stream {
if runner.verbosity > 1 {
logw = runner.output
}
if logb == nil {
Expand Down
4 changes: 2 additions & 2 deletions export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ func Indent(s, with string) string {
return indent(s, with)
}

func NewOutputWriter(writer io.Writer, stream, verbose bool) *outputWriter {
return newOutputWriter(writer, stream, verbose)
func NewOutputWriter(writer io.Writer, verbosity uint8) *outputWriter {
return newOutputWriter(writer, verbosity)
}

func (c *C) FakeSkip(reason string) {
Expand Down
19 changes: 9 additions & 10 deletions reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ type outputWriter struct {
m sync.Mutex
writer io.Writer
wroteCallProblemLast bool
stream bool
verbose bool
verbosity uint8
}

func newOutputWriter(writer io.Writer, stream, verbose bool) *outputWriter {
return &outputWriter{writer: writer, stream: stream, verbose: verbose}
func newOutputWriter(writer io.Writer, verbosity uint8) *outputWriter {
return &outputWriter{writer: writer, verbosity: verbosity}
}

func (ow *outputWriter) Write(content []byte) (n int, err error) {
Expand All @@ -29,7 +28,7 @@ func (ow *outputWriter) Write(content []byte) (n int, err error) {
}

func (ow *outputWriter) WriteCallStarted(label string, c *C) {
if ow.stream {
if ow.verbosity > 1 {
header := renderCallHeader(label, c, "", "\n")
ow.m.Lock()
ow.writer.Write([]byte(header))
Expand All @@ -39,22 +38,22 @@ func (ow *outputWriter) WriteCallStarted(label string, c *C) {

func (ow *outputWriter) WriteCallProblem(label string, c *C) {
var prefix string
if !ow.stream {
if ow.verbosity < 2 {
prefix = "\n-----------------------------------" +
"-----------------------------------\n"
}
header := renderCallHeader(label, c, prefix, "\n\n")
ow.m.Lock()
ow.wroteCallProblemLast = true
ow.writer.Write([]byte(header))
if !ow.stream {
if ow.verbosity < 2 {
c.logb.WriteTo(ow.writer)
}
ow.m.Unlock()
}

func (ow *outputWriter) WriteCallSuccess(label string, c *C) {
if ow.stream || (ow.verbose && c.kind == testKd) {
if ow.verbosity > 1 || (ow.verbosity == 1 && c.kind == testKd) {
// TODO Use a buffer here.
var suffix string
if c.reason != "" {
Expand All @@ -64,13 +63,13 @@ func (ow *outputWriter) WriteCallSuccess(label string, c *C) {
suffix += "\t" + c.timerString()
}
suffix += "\n"
if ow.stream {
if ow.verbosity > 1 {
suffix += "\n"
}
header := renderCallHeader(label, c, "", suffix)
ow.m.Lock()
// Resist temptation of using line as prefix above due to race.
if !ow.stream && ow.wroteCallProblemLast {
if ow.verbosity < 2 && ow.wroteCallProblemLast {
header = "\n-----------------------------------" +
"-----------------------------------\n" +
header
Expand Down
50 changes: 20 additions & 30 deletions reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,46 +24,42 @@ func (s *reporterS) TestWrite(c *C) {
testString := "test string"
output := String{}

dummyStream := true
dummyVerbose := true
o := NewOutputWriter(&output, dummyStream, dummyVerbose)
var dummyVerbosity uint8
o := NewOutputWriter(&output, dummyVerbosity)

o.Write([]byte(testString))
c.Assert(output.value, Equals, testString)
}

func (s *reporterS) TestWriteCallStartedWithStreamFlag(c *C) {
testLabel := "test started label"
stream := true
var verbosity uint8 = 2
output := String{}

dummyVerbose := true
o := NewOutputWriter(&output, stream, dummyVerbose)
o := NewOutputWriter(&output, verbosity)

o.WriteCallStarted(testLabel, c)
expected := fmt.Sprintf("%s: %s:\\d+: %s\n", testLabel, s.testFile, c.TestName())
c.Assert(output.value, Matches, expected)
}

func (s *reporterS) TestWriteCallStartedWithoutStreamFlag(c *C) {
stream := false
var verbosity uint8 = 1
output := String{}

dummyLabel := "dummy"
dummyVerbose := true
o := NewOutputWriter(&output, stream, dummyVerbose)
o := NewOutputWriter(&output, verbosity)

o.WriteCallStarted(dummyLabel, c)
c.Assert(output.value, Equals, "")
}

func (s *reporterS) TestWriteCallProblemWithStreamFlag(c *C) {
testLabel := "test problem label"
stream := true
var verbosity uint8 = 2
output := String{}

dummyVerbose := true
o := NewOutputWriter(&output, stream, dummyVerbose)
o := NewOutputWriter(&output, verbosity)

o.WriteCallProblem(testLabel, c)
expected := fmt.Sprintf("%s: %s:\\d+: %s\n\n", testLabel, s.testFile, c.TestName())
Expand All @@ -72,11 +68,10 @@ func (s *reporterS) TestWriteCallProblemWithStreamFlag(c *C) {

func (s *reporterS) TestWriteCallProblemWithoutStreamFlag(c *C) {
testLabel := "test problem label"
stream := false
var verbosity uint8 = 1
output := String{}

dummyVerbose := true
o := NewOutputWriter(&output, stream, dummyVerbose)
o := NewOutputWriter(&output, verbosity)

o.WriteCallProblem(testLabel, c)
expected := fmt.Sprintf(""+
Expand All @@ -89,11 +84,10 @@ func (s *reporterS) TestWriteCallProblemWithoutStreamFlag(c *C) {
func (s *reporterS) TestWriteCallProblemWithoutStreamFlagWithLog(c *C) {
testLabel := "test problem label"
testLog := "test log"
stream := false
var verbosity uint8 = 1
output := String{}

dummyVerbose := true
o := NewOutputWriter(&output, stream, dummyVerbose)
o := NewOutputWriter(&output, verbosity)

c.Log(testLog)
o.WriteCallProblem(testLabel, c)
Expand All @@ -106,11 +100,10 @@ func (s *reporterS) TestWriteCallProblemWithoutStreamFlagWithLog(c *C) {

func (s *reporterS) TestWriteCallSuccessWithStreamFlag(c *C) {
testLabel := "test success label"
stream := true
var verbosity uint8 = 2
output := String{}

dummyVerbose := true
o := NewOutputWriter(&output, stream, dummyVerbose)
o := NewOutputWriter(&output, verbosity)

o.WriteCallSuccess(testLabel, c)
expected := fmt.Sprintf("%s: %s:\\d+: %s\t\\d\\.\\d+s\n\n", testLabel, s.testFile, c.TestName())
Expand All @@ -120,11 +113,10 @@ func (s *reporterS) TestWriteCallSuccessWithStreamFlag(c *C) {
func (s *reporterS) TestWriteCallSuccessWithStreamFlagAndReason(c *C) {
testLabel := "test success label"
testReason := "test skip reason"
stream := true
var verbosity uint8 = 2
output := String{}

dummyVerbose := true
o := NewOutputWriter(&output, stream, dummyVerbose)
o := NewOutputWriter(&output, verbosity)
c.FakeSkip(testReason)

o.WriteCallSuccess(testLabel, c)
Expand All @@ -135,11 +127,10 @@ func (s *reporterS) TestWriteCallSuccessWithStreamFlagAndReason(c *C) {

func (s *reporterS) TestWriteCallSuccessWithoutStreamFlagWithVerboseFlag(c *C) {
testLabel := "test success label"
stream := false
verbose := true
var verbosity uint8 = 1
output := String{}

o := NewOutputWriter(&output, stream, verbose)
o := NewOutputWriter(&output, verbosity)

o.WriteCallSuccess(testLabel, c)
expected := fmt.Sprintf("%s: %s:\\d+: %s\t\\d\\.\\d+s\n", testLabel, s.testFile, c.TestName())
Expand All @@ -148,11 +139,10 @@ func (s *reporterS) TestWriteCallSuccessWithoutStreamFlagWithVerboseFlag(c *C) {

func (s *reporterS) TestWriteCallSuccessWithoutStreamFlagWithoutVerboseFlag(c *C) {
testLabel := "test success label"
stream := false
verbose := false
var verbosity uint8 = 0
output := String{}

o := NewOutputWriter(&output, stream, verbose)
o := NewOutputWriter(&output, verbosity)

o.WriteCallSuccess(testLabel, c)
c.Assert(output.value, Equals, "")
Expand Down

0 comments on commit 2b6969e

Please sign in to comment.