- *C now has an Output method matching the log.Logger interface.
- rand => math/rand
diff --git a/foundation_test.go b/foundation_test.go
index cd0ce9f..b69eb5e 100644
--- a/foundation_test.go
+++ b/foundation_test.go
@@ -11,6 +11,8 @@
"strings"
"regexp"
"fmt"
+ "log"
+ "os"
)
// -----------------------------------------------------------------------
@@ -288,6 +290,28 @@
}
// -----------------------------------------------------------------------
+// Check minimum *log.Logger interface provided by *gocheck.C.
+
+type minLogger interface {
+ Output(calldepth int, s string) error
+}
+
+func (s *BootstrapS) TestMinLogger(c *gocheck.C) {
+ var logger minLogger
+ logger = log.New(os.Stderr, "", 0)
+ logger = c
+ logger.Output(0, "Hello there")
+ expected := "\\[LOG\\] [.0-9]+ Hello there\n"
+ output := c.GetTestLog()
+ matched, err := regexp.MatchString(expected, output)
+ if err != nil {
+ c.Error("Bad expression: ", expected)
+ } else if !matched {
+ c.Error("Output() didn't log properly:\n", output)
+ }
+}
+
+// -----------------------------------------------------------------------
// Ensure that suites with embedded types are working fine, including the
// the workaround for issue 906.
diff --git a/gocheck.go b/gocheck.go
index 9dcc2d4..acd9ec6 100644
--- a/gocheck.go
+++ b/gocheck.go
@@ -5,9 +5,9 @@
"errors"
"fmt"
"io"
+ "math/rand"
"os"
"path"
- "rand"
"reflect"
"regexp"
"runtime"
diff --git a/helpers.go b/helpers.go
index 8be5143..7dd96ef 100644
--- a/helpers.go
+++ b/helpers.go
@@ -3,6 +3,7 @@
import (
"fmt"
"strings"
+ "time"
)
// -----------------------------------------------------------------------
@@ -88,6 +89,15 @@
c.logf(format, args...)
}
+// Output enables *C to be used as a logger in functions that require only
+// the minimum interface of *log.Logger.
+func (c *C) Output(calldepth int, s string) error {
+ ns := time.Nanoseconds()
+ t := float64(ns%100e9) / 1e9
+ c.Logf("[LOG] %.05f %s", t, s)
+ return nil
+}
+
// Log an error into the test error output, and mark the test as failed.
// The provided arguments will be assembled together into a string using
// fmt.Sprint().