Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (s *BenchmarkS) TestCountSuite(c *C) {
func (s *BenchmarkS) TestBasicTestTiming(c *C) {
helper := FixtureHelper{sleepOn: "Test1", sleep: 1000000 * time.Nanosecond}
output := String{}
runConf := RunConf{Output: &output, Verbose: true}
runConf := RunConf{Output: &output, Verbosity: 1}
Run(&helper, &runConf)

expected := "PASS: check_test\\.go:[0-9]+: FixtureHelper\\.Test1\t0\\.001s\n" +
Expand All @@ -29,7 +29,7 @@ func (s *BenchmarkS) TestBasicTestTiming(c *C) {
func (s *BenchmarkS) TestStreamTestTiming(c *C) {
helper := FixtureHelper{sleepOn: "SetUpSuite", sleep: 1000000 * time.Nanosecond}
output := String{}
runConf := RunConf{Output: &output, Stream: true}
runConf := RunConf{Output: &output, Verbosity: 2}
Run(&helper, &runConf)

expected := "(?s).*\nPASS: check_test\\.go:[0-9]+: FixtureHelper\\.SetUpSuite\t *0\\.001s\n.*"
Expand Down
15 changes: 8 additions & 7 deletions check.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,12 +522,12 @@ type suiteRunner struct {
reportedProblemLast bool
benchTime time.Duration
benchMem bool
verbosity uint8
}

type RunConf struct {
Output io.Writer
Stream bool
Verbose bool
Verbosity uint8
Filter string
Benchmark bool
BenchmarkTime time.Duration // Defaults to 1 second
Expand All @@ -544,23 +544,24 @@ func newSuiteRunner(suite interface{}, runConf *RunConf) *suiteRunner {
if conf.Output == nil {
conf.Output = os.Stdout
}
if conf.Benchmark {
conf.Verbose = true
if conf.Benchmark && conf.Verbosity < 1 {
conf.Verbosity = 1
}

suiteType := reflect.TypeOf(suite)
suiteNumMethods := suiteType.NumMethod()
suiteValue := reflect.ValueOf(suite)

runner := &suiteRunner{
suite: suite,
output: newOutputWriter(conf.Output, conf.Stream, conf.Verbose),
output: newOutputWriter(conf.Output, conf.Verbosity),
tracker: newResultTracker(),
benchTime: conf.BenchmarkTime,
benchMem: conf.BenchmarkMem,
tempDir: &tempDir{},
keepDir: conf.KeepWorkDir,
tests: make([]*methodType, 0, suiteNumMethods),
verbosity: conf.Verbosity,
}
if runner.benchTime == 0 {
runner.benchTime = 1 * time.Second
Expand Down Expand Up @@ -641,7 +642,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.output.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
4 changes: 2 additions & 2 deletions foundation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func (s *FoundationS) TestExpectFailureSucceed(c *check.C) {
func (s *FoundationS) TestExpectFailureSucceedVerbose(c *check.C) {
helper := ExpectFailureSucceedHelper{}
output := String{}
result := check.Run(&helper, &check.RunConf{Output: &output, Verbose: true})
result := check.Run(&helper, &check.RunConf{Output: &output, Verbosity: 1})

expected := "" +
"FAIL EXPECTED: foundation_test\\.go:[0-9]+:" +
Expand Down Expand Up @@ -277,7 +277,7 @@ func (s *FoundationS) TestSkip(c *check.C) {
func (s *FoundationS) TestSkipVerbose(c *check.C) {
helper := SkipTestHelper{}
output := String{}
check.Run(&helper, &check.RunConf{Output: &output, Verbose: true})
check.Run(&helper, &check.RunConf{Output: &output, Verbosity: 1})

expected := "SKIP: foundation_test\\.go:[0-9]+: SkipTestHelper\\.TestFail" +
" \\(Wrong platform or whatever\\)"
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
8 changes: 6 additions & 2 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,17 @@ func TestingT(testingT *testing.T) {
}
conf := &RunConf{
Filter: *oldFilterFlag + *newFilterFlag,
Verbose: *oldVerboseFlag || *newVerboseFlag,
Stream: *oldStreamFlag || *newStreamFlag,
Benchmark: *oldBenchFlag || *newBenchFlag,
BenchmarkTime: benchTime,
BenchmarkMem: *newBenchMem,
KeepWorkDir: *oldWorkFlag || *newWorkFlag,
}
if *oldVerboseFlag || *newVerboseFlag {
conf.Verbosity = 1
}
if *oldStreamFlag || *newStreamFlag {
conf.Verbosity = 2
}
if *oldListFlag || *newListFlag {
w := bufio.NewWriter(os.Stdout)
for _, name := range ListAll(conf) {
Expand Down
10 changes: 5 additions & 5 deletions run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func (s *RunS) TestList(c *C) {
func (s *RunS) TestVerboseMode(c *C) {
helper := FixtureHelper{}
output := String{}
runConf := RunConf{Output: &output, Verbose: true}
runConf := RunConf{Output: &output, Verbosity: 1}
Run(&helper, &runConf)

expected := "PASS: check_test\\.go:[0-9]+: FixtureHelper\\.Test1\t *[.0-9]+s\n" +
Expand All @@ -316,7 +316,7 @@ func (s *RunS) TestVerboseMode(c *C) {
func (s *RunS) TestVerboseModeWithFailBeforePass(c *C) {
helper := FixtureHelper{panicOn: "Test1"}
output := String{}
runConf := RunConf{Output: &output, Verbose: true}
runConf := RunConf{Output: &output, Verbosity: 1}
Run(&helper, &runConf)

expected := "(?s).*PANIC.*\n-+\n" + // Should have an extra line.
Expand Down Expand Up @@ -359,7 +359,7 @@ func (s *StreamHelper) Test2(c *C) {
func (s *RunS) TestStreamMode(c *C) {
helper := &StreamHelper{}
output := String{}
runConf := RunConf{Output: &output, Stream: true}
runConf := RunConf{Output: &output, Verbosity: 2}
Run(helper, &runConf)

expected := "START: run_test\\.go:[0-9]+: StreamHelper\\.SetUpSuite\n0\n" +
Expand All @@ -386,7 +386,7 @@ func (s *StreamMissHelper) Test1(c *C) {
func (s *RunS) TestStreamModeWithMiss(c *C) {
helper := &StreamMissHelper{}
output := String{}
runConf := RunConf{Output: &output, Stream: true}
runConf := RunConf{Output: &output, Verbosity: 2}
Run(helper, &runConf)

expected := "START: run_test\\.go:[0-9]+: StreamMissHelper\\.SetUpSuite\n0\n" +
Expand All @@ -408,7 +408,7 @@ func (s *WorkDirSuite) Test(c *C) {

func (s *RunS) TestKeepWorkDir(c *C) {
output := String{}
runConf := RunConf{Output: &output, Verbose: true, KeepWorkDir: true}
runConf := RunConf{Output: &output, Verbosity: 1, KeepWorkDir: true}
result := Run(&WorkDirSuite{}, &runConf)

c.Assert(result.String(), Matches, ".*\nWORK=" + result.WorkDir)
Expand Down