Implemented support for -v1 flag to display all passing tests as well.
diff --git a/TODO b/TODO
index e67a898..795e43e 100644
--- a/TODO
+++ b/TODO
@@ -5,15 +5,6 @@
- t.LockResource("database", "config-dir"), acquires exclusive access
to these resources and prevents parallel tests from using them.
- Benchmark support
-- Implement PASS logging in verbose mode:
-
----------------------------------------------------------------------
-PASS: filename:line:TestMethod
-PASS: filename:line:TestMethod
-PASS: filename:line:TestMethod
-PASS: filename:line:TestMethod
----------------------------------------------------------------------
-
- Improved logging of multiline strings:
---------------------------------------------------------------------
diff --git a/gocheck.go b/gocheck.go
index a54fd14..fd08d27 100644
--- a/gocheck.go
+++ b/gocheck.go
@@ -282,6 +282,8 @@
type resultTracker struct {
writer io.Writer
result Result
+ verbose bool
+ _lastWasProblem bool
_waiting int
_missed int
_waitChan chan *C
@@ -289,11 +291,11 @@
_stopChan chan bool
}
-func newResultTracker(writer io.Writer) *resultTracker {
- return &resultTracker{writer: writer,
+func newResultTracker(writer io.Writer, verbose bool) *resultTracker {
+ return &resultTracker{writer: writer, verbose: verbose,
_waitChan: make(chan *C), // Synchronous
_doneChan: make(chan *C, 32), // Asynchronous
- _stopChan: make(chan bool)} // Synchronous
+ _stopChan: make(chan bool)} // Synchronous
}
func (tracker *resultTracker) start() {
@@ -327,6 +329,7 @@
case succeededSt:
if c.kind == testKd {
tracker.result.Succeeded++
+ tracker._reportVerbose("PASS", c)
}
case failedSt:
tracker.result.Failed++
@@ -379,6 +382,7 @@
}
func (tracker *resultTracker) _reportProblem(label string, c *C) {
+ tracker._lastWasProblem = true
pc := c.method.Get()
header := fmt.Sprintf(
"\n-----------------------------------" +
@@ -389,6 +393,21 @@
c.logb.WriteTo(tracker.writer)
}
+func (tracker *resultTracker) _reportVerbose(label string, c *C) {
+ if tracker.verbose {
+ var line string
+ if tracker._lastWasProblem {
+ tracker._lastWasProblem = false
+ line = "\n-----------------------------------" +
+ "-----------------------------------\n"
+ }
+ pc := c.method.Get()
+ header := fmt.Sprintf(
+ "%s%s: %s: %s\n",
+ line, label, niceFuncPath(pc), niceFuncName(pc))
+ io.WriteString(tracker.writer, header)
+ }
+}
// -----------------------------------------------------------------------
@@ -406,12 +425,14 @@
type RunConf struct {
Output io.Writer
Filter string
+ Verbose bool
}
// Create a new suiteRunner able to run all methods in the given suite.
func newSuiteRunner(suite interface{}, runConf *RunConf) *suiteRunner {
var output io.Writer
var filter string
+ var verbose bool
output = os.Stdout
@@ -419,9 +440,8 @@
if runConf.Output != nil {
output = runConf.Output
}
- if runConf.Filter != "" {
- filter = runConf.Filter
- }
+ filter = runConf.Filter
+ verbose = runConf.Verbose
}
suiteType := reflect.Typeof(suite)
@@ -429,7 +449,7 @@
suiteValue := reflect.NewValue(suite)
runner := suiteRunner{suite:suite,
- tracker:newResultTracker(output)}
+ tracker:newResultTracker(output, verbose)}
runner.tests = make([]*reflect.FuncValue, suiteNumMethods)
runner.tempDir = new(tempDir)
testsLen := 0
diff --git a/run.go b/run.go
index 1ac5f06..e4a6e7f 100644
--- a/run.go
+++ b/run.go
@@ -27,11 +27,14 @@
"Regular expression to select " +
"what to run (gocheck)")
+var verboseFlag = flag.Bool("v1", false, "Verbose mode (gocheck)")
+
+
// Run all test suites registered with the Suite() function, printing
// results to stdout, and reporting any failures back to the 'testing'
// module.
func TestingT(testingT *testing.T) {
- result := RunAll(&RunConf{Filter: *filterFlag})
+ result := RunAll(&RunConf{Filter: *filterFlag, Verbose: *verboseFlag})
println(result.String())
if usedDeprecatedChecks {
println("WARNING: The Check/AssertEqual() and Check/AssertMatch() " +
diff --git a/run_test.go b/run_test.go
index eac4d47..beed217 100644
--- a/run_test.go
+++ b/run_test.go
@@ -253,7 +253,6 @@
c.Check(helper.n, Equals, 8)
}
-
func (s *RunS) TestFilterError(c *C) {
helper := FixtureHelper{}
output := String{}
@@ -263,3 +262,30 @@
"ERROR: Bad filter expression: unmatched ']'")
c.Check(helper.n, Equals, 0)
}
+
+// -----------------------------------------------------------------------
+// Verify that verbose mode prints tests which pass as well.
+
+func (s *RunS) TestVerboseMode(c *C) {
+ helper := FixtureHelper{}
+ output := String{}
+ runConf := RunConf{Output: &output, Verbose: true}
+ Run(&helper, &runConf)
+
+ expected := "PASS: gocheck_test\\.go:[0-9]+: FixtureHelper\\.Test1\n" +
+ "PASS: gocheck_test\\.go:[0-9]+: FixtureHelper\\.Test2\n"
+
+ c.Assert(output.value, Matches, expected)
+}
+
+func (s *RunS) TestVerboseModeWithFailBeforePass(c *C) {
+ helper := FixtureHelper{panicOn: "Test1"}
+ output := String{}
+ runConf := RunConf{Output: &output, Verbose: true}
+ Run(&helper, &runConf)
+
+ expected := ".*PANIC.*\n-+\n" + // Should have an extra line.
+ "PASS: gocheck_test\\.go:[0-9]+: FixtureHelper\\.Test2\n"
+
+ c.Assert(output.value, Matches, expected)
+}