diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..59f0abe --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: go +sudo: false +go: + - tip +before_install: + - go get github.com/mattn/goveralls +script: + - ./gen-coverage.sh coverage.out + - $HOME/gopath/bin/goveralls -coverprofile=coverage.out -service=travis-ci diff --git a/README.md b/README.md index 0ca9e57..79a0af5 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,11 @@ Instructions Install the package with: - go get gopkg.in/check.v1 - + go get github.com/elopio/check + Import it with: - import "gopkg.in/check.v1" + import "github.com/elopio/check" and use _check_ as the package name inside the code. diff --git a/benchmark_test.go b/benchmark_test.go index 4dd827c..7fa8fea 100644 --- a/benchmark_test.go +++ b/benchmark_test.go @@ -4,7 +4,8 @@ package check_test import ( "time" - . "gopkg.in/check.v1" + + . "github.com/elopio/check" ) var benchmarkS = Suite(&BenchmarkS{}) diff --git a/bootstrap_test.go b/bootstrap_test.go index e55f327..4c7bb4e 100644 --- a/bootstrap_test.go +++ b/bootstrap_test.go @@ -14,8 +14,9 @@ package check_test import ( "fmt" - "gopkg.in/check.v1" "strings" + + "github.com/elopio/check" ) type BootstrapS struct{} diff --git a/check.go b/check.go index 82c26fa..cbef564 100644 --- a/check.go +++ b/check.go @@ -84,7 +84,6 @@ type C struct { testName string _status funcStatus logb *logger - logw io.Writer done chan *C reason string mustFail bool @@ -109,25 +108,30 @@ func (c *C) stopNow() { // logger is a concurrency safe byte.Buffer type logger struct { sync.Mutex - writer bytes.Buffer + buffer bytes.Buffer + output io.Writer + verbosity uint8 } func (l *logger) Write(buf []byte) (int, error) { l.Lock() defer l.Unlock() - return l.writer.Write(buf) + if l.verbosity > 1 { + l.output.Write(buf) + } + return l.buffer.Write(buf) } func (l *logger) WriteTo(w io.Writer) (int64, error) { l.Lock() defer l.Unlock() - return l.writer.WriteTo(w) + return l.buffer.WriteTo(w) } func (l *logger) String() string { l.Lock() defer l.Unlock() - return l.writer.String() + return l.buffer.String() } // ----------------------------------------------------------------------- @@ -198,9 +202,6 @@ func (c *C) logNewLine() { func (c *C) writeLog(buf []byte) { c.logb.Write(buf) - if c.logw != nil { - c.logw.Write(buf) - } } func hasStringOrError(x interface{}) (ok bool) { @@ -518,10 +519,12 @@ type suiteRunner struct { tracker *resultTracker tempDir *tempDir keepDir bool - output *outputWriter + logOutput io.Writer + reporter testReporter reportedProblemLast bool benchTime time.Duration benchMem bool + verbosity uint8 } type RunConf struct { @@ -551,16 +554,25 @@ 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), + logOutput: conf.Output, + reporter: newOutputWriter(conf.Output, verbosity), tracker: newResultTracker(), benchTime: conf.BenchmarkTime, benchMem: conf.BenchmarkMem, tempDir: &tempDir{}, keepDir: conf.KeepWorkDir, tests: make([]*methodType, 0, suiteNumMethods), + verbosity: verbosity, } if runner.benchTime == 0 { runner.benchTime = 1 * time.Second @@ -640,19 +652,17 @@ func (runner *suiteRunner) run() *Result { // Create a call object with the given suite method, and fork a // 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 { - logw = runner.output - } if logb == nil { - logb = new(logger) + logb = &logger{ + output: runner.logOutput, + verbosity: runner.verbosity, + } } c := &C{ method: method, kind: kind, testName: testName, logb: logb, - logw: logw, tempDir: runner.tempDir, done: make(chan *C, 1), timer: timer{benchTime: runner.benchTime}, @@ -843,7 +853,7 @@ func (runner *suiteRunner) checkFixtureArgs() bool { } func (runner *suiteRunner) reportCallStarted(c *C) { - runner.output.WriteCallStarted("START", c) + runner.reporter.StartTest(c) } func (runner *suiteRunner) reportCallDone(c *C) { @@ -851,23 +861,23 @@ func (runner *suiteRunner) reportCallDone(c *C) { switch c.status() { case succeededSt: if c.mustFail { - runner.output.WriteCallSuccess("FAIL EXPECTED", c) + runner.reporter.AddExpectedFailure(c) } else { - runner.output.WriteCallSuccess("PASS", c) + runner.reporter.AddSuccess(c) } case skippedSt: - runner.output.WriteCallSuccess("SKIP", c) + runner.reporter.AddSkip(c) case failedSt: - runner.output.WriteCallProblem("FAIL", c) + runner.reporter.AddFailure(c) case panickedSt: - runner.output.WriteCallProblem("PANIC", c) + runner.reporter.AddError(c) case fixturePanickedSt: // That's a testKd call reporting that its fixture // has panicked. The fixture call which caused the // panic itself was tracked above. We'll report to // aid debugging. - runner.output.WriteCallProblem("PANIC", c) + runner.reporter.AddError(c) case missedSt: - runner.output.WriteCallSuccess("MISS", c) + runner.reporter.AddMissed(c) } } diff --git a/check_test.go b/check_test.go index 871b325..7b5eac8 100644 --- a/check_test.go +++ b/check_test.go @@ -12,7 +12,7 @@ import ( "testing" "time" - "gopkg.in/check.v1" + . "github.com/elopio/check" ) // We count the number of suites run at least to get a vague hint that the @@ -23,7 +23,7 @@ const suitesRunExpected = 8 var suitesRun int = 0 func Test(t *testing.T) { - check.TestingT(t) + TestingT(t) if suitesRun != suitesRunExpected && flag.Lookup("check.f").Value.String() == "" { critical(fmt.Sprintf("Expected %d suites to run rather than %d", suitesRunExpected, suitesRun)) @@ -65,8 +65,8 @@ func (s *String) Write(p []byte) (n int, err error) { // Trivial wrapper to test errors happening on a different file // than the test itself. -func checkEqualWrapper(c *check.C, obtained, expected interface{}) (result bool, line int) { - return c.Check(obtained, check.Equals, expected), getMyLine() +func checkEqualWrapper(c *C, obtained, expected interface{}) (result bool, line int) { + return c.Check(obtained, Equals, expected), getMyLine() } // ----------------------------------------------------------------------- @@ -76,7 +76,7 @@ type FailHelper struct { testLine int } -func (s *FailHelper) TestLogAndFail(c *check.C) { +func (s *FailHelper) TestLogAndFail(c *C) { s.testLine = getMyLine() - 1 c.Log("Expected failure!") c.Fail() @@ -87,7 +87,7 @@ func (s *FailHelper) TestLogAndFail(c *check.C) { type SuccessHelper struct{} -func (s *SuccessHelper) TestLogAndSucceed(c *check.C) { +func (s *SuccessHelper) TestLogAndSucceed(c *C) { c.Log("Expected success!") } @@ -104,7 +104,7 @@ type FixtureHelper struct { bytes int64 } -func (s *FixtureHelper) trace(name string, c *check.C) { +func (s *FixtureHelper) trace(name string, c *C) { s.calls = append(s.calls, name) if name == s.panicOn { panic(name) @@ -117,38 +117,38 @@ func (s *FixtureHelper) trace(name string, c *check.C) { } } -func (s *FixtureHelper) SetUpSuite(c *check.C) { +func (s *FixtureHelper) SetUpSuite(c *C) { s.trace("SetUpSuite", c) } -func (s *FixtureHelper) TearDownSuite(c *check.C) { +func (s *FixtureHelper) TearDownSuite(c *C) { s.trace("TearDownSuite", c) } -func (s *FixtureHelper) SetUpTest(c *check.C) { +func (s *FixtureHelper) SetUpTest(c *C) { s.trace("SetUpTest", c) } -func (s *FixtureHelper) TearDownTest(c *check.C) { +func (s *FixtureHelper) TearDownTest(c *C) { s.trace("TearDownTest", c) } -func (s *FixtureHelper) Test1(c *check.C) { +func (s *FixtureHelper) Test1(c *C) { s.trace("Test1", c) } -func (s *FixtureHelper) Test2(c *check.C) { +func (s *FixtureHelper) Test2(c *C) { s.trace("Test2", c) } -func (s *FixtureHelper) Benchmark1(c *check.C) { +func (s *FixtureHelper) Benchmark1(c *C) { s.trace("Benchmark1", c) for i := 0; i < c.N; i++ { time.Sleep(s.sleep) } } -func (s *FixtureHelper) Benchmark2(c *check.C) { +func (s *FixtureHelper) Benchmark2(c *C) { s.trace("Benchmark2", c) c.SetBytes(1024) for i := 0; i < c.N; i++ { @@ -156,7 +156,7 @@ func (s *FixtureHelper) Benchmark2(c *check.C) { } } -func (s *FixtureHelper) Benchmark3(c *check.C) { +func (s *FixtureHelper) Benchmark3(c *C) { var x []int64 s.trace("Benchmark3", c) for i := 0; i < c.N; i++ { @@ -181,7 +181,7 @@ type expectedState struct { // Verify the state of the test. Note that since this also verifies if // the test is supposed to be in a failed state, no other checks should // be done in addition to what is being tested. -func checkState(c *check.C, result interface{}, expected *expectedState) { +func checkState(c *C, result interface{}, expected *expectedState) { failed := c.Failed() c.Succeed() log := c.GetTestLog() diff --git a/checkers_test.go b/checkers_test.go index 5c69747..120b2dd 100644 --- a/checkers_test.go +++ b/checkers_test.go @@ -2,9 +2,10 @@ package check_test import ( "errors" - "gopkg.in/check.v1" "reflect" "runtime" + + "github.com/elopio/check" ) type CheckersS struct{} diff --git a/export_test.go b/export_test.go index abb89a2..96127b0 100644 --- a/export_test.go +++ b/export_test.go @@ -2,6 +2,10 @@ package check import "io" +type TestReporter interface { + testReporter +} + func PrintLine(filename string, line int) (string, error) { return printLine(filename, line) } @@ -10,8 +14,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) { diff --git a/fixture_test.go b/fixture_test.go index 2bff9e1..134e543 100644 --- a/fixture_test.go +++ b/fixture_test.go @@ -2,9 +2,7 @@ package check_test -import ( - . "gopkg.in/check.v1" -) +import . "github.com/elopio/check" // ----------------------------------------------------------------------- // Fixture test suite. @@ -14,7 +12,7 @@ type FixtureS struct{} var fixtureS = Suite(&FixtureS{}) func (s *FixtureS) TestCountSuite(c *C) { - suitesRun += 1 + suitesRun++ } // ----------------------------------------------------------------------- diff --git a/foundation_test.go b/foundation_test.go index 8ecf791..bc019bc 100644 --- a/foundation_test.go +++ b/foundation_test.go @@ -8,11 +8,12 @@ package check_test import ( "fmt" - "gopkg.in/check.v1" "log" "os" "regexp" "strings" + + "github.com/elopio/check" ) // ----------------------------------------------------------------------- @@ -175,7 +176,7 @@ func (s *FoundationS) TestCallerLoggingInDifferentFile(c *check.C) { "foundation_test.go:%d:\n"+ " result, line := checkEqualWrapper\\(c, 10, 20\\)\n"+ "check_test.go:%d:\n"+ - " return c.Check\\(obtained, check.Equals, expected\\), getMyLine\\(\\)\n"+ + " return c.Check\\(obtained, Equals, expected\\), getMyLine\\(\\)\n"+ "\\.\\.\\. obtained int = 10\n"+ "\\.\\.\\. expected int = 20\n\n", testLine, line) diff --git a/gen-coverage.sh b/gen-coverage.sh new file mode 100755 index 0000000..75147aa --- /dev/null +++ b/gen-coverage.sh @@ -0,0 +1,17 @@ +#!/bin/sh +out_file=$1 + +append_coverage() { + local profile="$1" + if [ -f $profile ]; then + cat $profile | grep -v "mode: count" >> "$out_file" + rm $profile + fi +} + +echo "mode: count" > "$out_file" + +for pkg in $(go list ./...); do + go test -covermode=count -coverprofile=profile.out "$pkg" + append_coverage profile.out +done diff --git a/helpers_test.go b/helpers_test.go index 4baa656..52247ef 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -4,11 +4,12 @@ package check_test import ( - "gopkg.in/check.v1" "os" "reflect" "runtime" "sync" + + "github.com/elopio/check" ) var helpersS = check.Suite(&HelpersS{}) diff --git a/printer_test.go b/printer_test.go index 538b2d5..b02fa51 100644 --- a/printer_test.go +++ b/printer_test.go @@ -1,7 +1,7 @@ package check_test import ( - . "gopkg.in/check.v1" + . "github.com/elopio/check" ) var _ = Suite(&PrinterS{}) diff --git a/reporter.go b/reporter.go index fb04f76..3a42ba3 100644 --- a/reporter.go +++ b/reporter.go @@ -6,6 +6,18 @@ import ( "sync" ) +type testReporter interface { + StartTest(*C) + StopTest(*C) + AddFailure(*C) + AddError(*C) + AddUnexpectedSuccess(*C) + AddSuccess(*C) + AddExpectedFailure(*C) + AddSkip(*C) + AddMissed(*C) +} + // ----------------------------------------------------------------------- // Output writer manages atomic output writing according to settings. @@ -13,33 +25,36 @@ type outputWriter struct { m sync.Mutex writer io.Writer wroteCallProblemLast bool - Stream bool - Verbose bool -} - -func newOutputWriter(writer io.Writer, stream, verbose bool) *outputWriter { - return &outputWriter{writer: writer, Stream: stream, Verbose: verbose} + verbosity uint8 } -func (ow *outputWriter) Write(content []byte) (n int, err error) { - ow.m.Lock() - n, err = ow.writer.Write(content) - ow.m.Unlock() - return +func newOutputWriter(writer io.Writer, verbosity uint8) *outputWriter { + return &outputWriter{writer: writer, verbosity: verbosity} } -func (ow *outputWriter) WriteCallStarted(label string, c *C) { - if ow.Stream { - header := renderCallHeader(label, c, "", "\n") +func (ow *outputWriter) StartTest(c *C) { + if ow.verbosity > 1 { + header := renderCallHeader("START", c, "", "\n") ow.m.Lock() ow.writer.Write([]byte(header)) ow.m.Unlock() } } -func (ow *outputWriter) WriteCallProblem(label string, c *C) { +func (ow *outputWriter) StopTest(c *C) { +} + +func (ow *outputWriter) AddFailure(c *C) { + ow.writeProblem("FAIL", c) +} + +func (ow *outputWriter) AddError(c *C) { + ow.writeProblem("PANIC", c) +} + +func (ow *outputWriter) writeProblem(label string, c *C) { var prefix string - if !ow.Stream { + if ow.verbosity < 2 { prefix = "\n-----------------------------------" + "-----------------------------------\n" } @@ -47,14 +62,33 @@ func (ow *outputWriter) WriteCallProblem(label string, c *C) { 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) { +func (ow *outputWriter) AddUnexpectedSuccess(c *C) { +} + +func (ow *outputWriter) AddSuccess(c *C) { + ow.writeSuccess("PASS", c) +} + +func (ow *outputWriter) AddExpectedFailure(c *C) { + ow.writeSuccess("FAIL EXPECTED", c) +} + +func (ow *outputWriter) AddSkip(c *C) { + ow.writeSuccess("SKIP", c) +} + +func (ow *outputWriter) AddMissed(c *C) { + ow.writeSuccess("MISS", c) +} + +func (ow *outputWriter) writeSuccess(label string, c *C) { + if ow.verbosity > 1 || (ow.verbosity == 1 && c.kind == testKd) { // TODO Use a buffer here. var suffix string if c.reason != "" { @@ -64,13 +98,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 diff --git a/reporter_test.go b/reporter_test.go index 0b7ed76..5a8c9a2 100644 --- a/reporter_test.go +++ b/reporter_test.go @@ -5,7 +5,7 @@ import ( "path/filepath" "runtime" - . "gopkg.in/check.v1" + . "github.com/elopio/check" ) var _ = Suite(&reporterS{}) @@ -20,140 +20,154 @@ func (s *reporterS) SetUpSuite(c *C) { s.testFile = filepath.Base(fileName) } -func (s *reporterS) TestWrite(c *C) { - testString := "test string" +func (s *reporterS) TestStartTestWithHighVerbosity(c *C) { + var verbosity uint8 = 2 output := String{} - dummyStream := true - dummyVerbose := true - o := NewOutputWriter(&output, dummyStream, dummyVerbose) + o := NewOutputWriter(&output, verbosity) - o.Write([]byte(testString)) - c.Assert(output.value, Equals, testString) -} - -func (s *reporterS) TestWriteCallStartedWithStreamFlag(c *C) { - testLabel := "test started label" - stream := true - output := String{} - - dummyVerbose := true - o := NewOutputWriter(&output, stream, dummyVerbose) - - o.WriteCallStarted(testLabel, c) - expected := fmt.Sprintf("%s: %s:\\d+: %s\n", testLabel, s.testFile, c.TestName()) + o.StartTest(c) + expected := fmt.Sprintf("START: %s:\\d+: %s\n", s.testFile, c.TestName()) c.Assert(output.value, Matches, expected) } -func (s *reporterS) TestWriteCallStartedWithoutStreamFlag(c *C) { - stream := false +func (s *reporterS) TestStartTestLowVerbosity(c *C) { + var verbosity uint8 = 1 output := String{} - dummyLabel := "dummy" - dummyVerbose := true - o := NewOutputWriter(&output, stream, dummyVerbose) + o := NewOutputWriter(&output, verbosity) - o.WriteCallStarted(dummyLabel, c) + o.StartTest(c) c.Assert(output.value, Equals, "") } -func (s *reporterS) TestWriteCallProblemWithStreamFlag(c *C) { - testLabel := "test problem label" - stream := true - output := String{} +var problemTests = []string{"FAIL", "PANIC"} - dummyVerbose := true - o := NewOutputWriter(&output, stream, dummyVerbose) +func addProblem(label string, r TestReporter, c *C) { + if label == "FAIL" { + r.AddFailure(c) + } else if label == "PANIC" { + r.AddError(c) + } else { + panic("Unknown problem: " + label) + } +} - o.WriteCallProblem(testLabel, c) - expected := fmt.Sprintf("%s: %s:\\d+: %s\n\n", testLabel, s.testFile, c.TestName()) - c.Assert(output.value, Matches, expected) +func (s *reporterS) TestAddProblemWitHighVerbosity(c *C) { + for _, testLabel := range problemTests { + var verbosity uint8 = 2 + output := String{} + + o := NewOutputWriter(&output, verbosity) + + addProblem(testLabel, o, c) + expected := fmt.Sprintf("%s: %s:\\d+: %s\n\n", testLabel, s.testFile, c.TestName()) + c.Check(output.value, Matches, expected) + } } -func (s *reporterS) TestWriteCallProblemWithoutStreamFlag(c *C) { - testLabel := "test problem label" - stream := false - output := String{} +func (s *reporterS) TestAddProblemWithLowVerbosity(c *C) { + for _, testLabel := range problemTests { + var verbosity uint8 = 1 + output := String{} + + o := NewOutputWriter(&output, verbosity) + + addProblem(testLabel, o, c) + expected := fmt.Sprintf(""+ + "\n"+ + "----------------------------------------------------------------------\n"+ + "%s: %s:\\d+: %s\n\n", testLabel, s.testFile, c.TestName()) + c.Check(output.value, Matches, expected) + } +} - dummyVerbose := true - o := NewOutputWriter(&output, stream, dummyVerbose) +func (s *reporterS) TestAddProblemWithLowVerbosityWithLog(c *C) { + for _, testLabel := range problemTests { + testLog := "test log" + var verbosity uint8 = 1 + output := String{} - o.WriteCallProblem(testLabel, c) - expected := fmt.Sprintf(""+ - "\n"+ - "----------------------------------------------------------------------\n"+ - "%s: %s:\\d+: %s\n\n", testLabel, s.testFile, c.TestName()) - c.Assert(output.value, Matches, expected) -} + o := NewOutputWriter(&output, verbosity) -func (s *reporterS) TestWriteCallProblemWithoutStreamFlagWithLog(c *C) { - testLabel := "test problem label" - testLog := "test log" - stream := false - output := String{} + c.Log(testLog) + addProblem(testLabel, o, c) - dummyVerbose := true - o := NewOutputWriter(&output, stream, dummyVerbose) + expected := fmt.Sprintf(""+ + "\n"+ + "----------------------------------------------------------------------\n"+ + "%s: %s:\\d+: %s\n\n%s\n", testLabel, s.testFile, c.TestName(), testLog) + c.Check(output.value, Matches, expected) + } +} - c.Log(testLog) - o.WriteCallProblem(testLabel, c) - expected := fmt.Sprintf(""+ - "\n"+ - "----------------------------------------------------------------------\n"+ - "%s: %s:\\d+: %s\n\n%s\n", testLabel, s.testFile, c.TestName(), testLog) - c.Assert(output.value, Matches, expected) +var successTests = []string{"PASS", "SKIP", "FAIL EXPECTED", "MISS"} + +func addSuccess(label string, r TestReporter, c *C) { + if label == "PASS" { + r.AddSuccess(c) + } else if label == "SKIP" { + r.AddSkip(c) + } else if label == "FAIL EXPECTED" { + r.AddExpectedFailure(c) + } else if label == "MISS" { + r.AddMissed(c) + } else { + panic("Unknown success: " + label) + } } -func (s *reporterS) TestWriteCallSuccessWithStreamFlag(c *C) { - testLabel := "test success label" - stream := true - output := String{} +func (s *reporterS) TestAddSuccessWithHighVerbosity(c *C) { + for _, testLabel := range successTests { + 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()) - c.Assert(output.value, Matches, expected) + addSuccess(testLabel, o, c) + expected := fmt.Sprintf("%s: %s:\\d+: %s\t\\d\\.\\d+s\n\n", testLabel, s.testFile, c.TestName()) + c.Check(output.value, Matches, expected) + } } -func (s *reporterS) TestWriteCallSuccessWithStreamFlagAndReason(c *C) { - testLabel := "test success label" - testReason := "test skip reason" - stream := true - output := String{} +func (s *reporterS) TestAddSuccessWithHighVerbosityAndReason(c *C) { + for _, testLabel := range successTests { + testReason := "test skip reason" + var verbosity uint8 = 2 + output := String{} - dummyVerbose := true - o := NewOutputWriter(&output, stream, dummyVerbose) - c.FakeSkip(testReason) + o := NewOutputWriter(&output, verbosity) + c.FakeSkip(testReason) - o.WriteCallSuccess(testLabel, c) - expected := fmt.Sprintf("%s: %s:\\d+: %s \\(%s\\)\t\\d\\.\\d+s\n\n", - testLabel, s.testFile, c.TestName(), testReason) - c.Assert(output.value, Matches, expected) + addSuccess(testLabel, o, c) + expected := fmt.Sprintf("%s: %s:\\d+: %s \\(%s\\)\t\\d\\.\\d+s\n\n", + testLabel, s.testFile, c.TestName(), testReason) + c.Check(output.value, Matches, expected) + } } -func (s *reporterS) TestWriteCallSuccessWithoutStreamFlagWithVerboseFlag(c *C) { - testLabel := "test success label" - stream := false - verbose := true - output := String{} +func (s *reporterS) TestAddSuccessWithLowVerbosity(c *C) { + for _, testLabel := range successTests { + 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()) - c.Assert(output.value, Matches, expected) + addSuccess(testLabel, o, c) + + expected := fmt.Sprintf("%s: %s:\\d+: %s\t\\d\\.\\d+s\n", testLabel, s.testFile, c.TestName()) + c.Check(output.value, Matches, expected) + } } -func (s *reporterS) TestWriteCallSuccessWithoutStreamFlagWithoutVerboseFlag(c *C) { - testLabel := "test success label" - stream := false - verbose := false - output := String{} +func (s *reporterS) TestAddSuccessWithoutVerbosity(c *C) { + for _, testLabel := range successTests { + var verbosity uint8 = 0 + output := String{} - o := NewOutputWriter(&output, stream, verbose) + o := NewOutputWriter(&output, verbosity) - o.WriteCallSuccess(testLabel, c) - c.Assert(output.value, Equals, "") + addSuccess(testLabel, o, c) + c.Check(output.value, Equals, "") + } } diff --git a/run_test.go b/run_test.go index f41fffc..2252698 100644 --- a/run_test.go +++ b/run_test.go @@ -4,9 +4,10 @@ package check_test import ( "errors" - . "gopkg.in/check.v1" "os" "sync" + + . "github.com/elopio/check" ) var runnerS = Suite(&RunS{}) @@ -400,7 +401,7 @@ func (s *RunS) TestStreamModeWithMiss(c *C) { // ----------------------------------------------------------------------- // Verify that that the keep work dir request indeed does so. -type WorkDirSuite struct {} +type WorkDirSuite struct{} func (s *WorkDirSuite) Test(c *C) { c.MkDir() @@ -411,7 +412,7 @@ func (s *RunS) TestKeepWorkDir(c *C) { runConf := RunConf{Output: &output, Verbose: true, KeepWorkDir: true} result := Run(&WorkDirSuite{}, &runConf) - c.Assert(result.String(), Matches, ".*\nWORK=" + result.WorkDir) + c.Assert(result.String(), Matches, ".*\nWORK="+result.WorkDir) stat, err := os.Stat(result.WorkDir) c.Assert(err, IsNil)