chore: Use go-check fork.

This commit is contained in:
Fernandez Ludovic 2017-09-15 21:08:13 +02:00 committed by Traefiker
parent 3942f3366d
commit ce3b255f1a
7 changed files with 152 additions and 103 deletions

8
glide.lock generated
View file

@ -1,5 +1,5 @@
hash: 7b973a5de5444f7f29252ae78529ee50569174b2c17f4aa89bf15aaf2553c6b7 hash: f742f45c92013191b9840880a200060d58344828ed28fb4e02680adc7b508882
updated: 2017-08-25T11:52:16.848940186+02:00 updated: 2017-09-15T11:52:16.848940186+02:00
imports: imports:
- name: cloud.google.com/go - name: cloud.google.com/go
version: 2e6a95edb1071d750f6d7db777bf66cd2997af6c version: 2e6a95edb1071d750f6d7db777bf66cd2997af6c
@ -779,7 +779,9 @@ testImports:
- name: github.com/flynn/go-shlex - name: github.com/flynn/go-shlex
version: 3f9db97f856818214da2e1057f8ad84803971cff version: 3f9db97f856818214da2e1057f8ad84803971cff
- name: github.com/go-check/check - name: github.com/go-check/check
version: 11d3bc7aa68e238947792f30573146a3231fc0f1 version: ca0bf163426aa183d03fd4949101785c0347f273
repo: https://github.com/containous/check.git
vcs: git
- name: github.com/gorilla/mux - name: github.com/gorilla/mux
version: e444e69cbd2e2e3e0749a2f3c717cec491552bbf version: e444e69cbd2e2e3e0749a2f3c717cec491552bbf
- name: github.com/libkermit/compose - name: github.com/libkermit/compose

View file

@ -208,7 +208,9 @@ testImport:
- package: github.com/docker/libcompose - package: github.com/docker/libcompose
version: 1b708aac26a4fc6f9bff31728a8e3a252ef57dbd version: 1b708aac26a4fc6f9bff31728a8e3a252ef57dbd
- package: github.com/go-check/check - package: github.com/go-check/check
version: 11d3bc7aa68e238947792f30573146a3231fc0f1 version: fork-containous
repo: https://github.com/containous/check.git
vcs: git
- package: github.com/libkermit/compose - package: github.com/libkermit/compose
version: 2048f803f56422a65b455f918d4a61704dc94603 version: 2048f803f56422a65b455f918d4a61704dc94603
subpackages: subpackages:

View file

@ -156,7 +156,7 @@ func (td *tempDir) newPath() string {
} }
} }
result := filepath.Join(td.path, strconv.Itoa(td.counter)) result := filepath.Join(td.path, strconv.Itoa(td.counter))
td.counter += 1 td.counter++
return result return result
} }
@ -274,7 +274,7 @@ func (c *C) logString(issue string) {
func (c *C) logCaller(skip int) { func (c *C) logCaller(skip int) {
// This is a bit heavier than it ought to be. // This is a bit heavier than it ought to be.
skip += 1 // Our own frame. skip++ // Our own frame.
pc, callerFile, callerLine, ok := runtime.Caller(skip) pc, callerFile, callerLine, ok := runtime.Caller(skip)
if !ok { if !ok {
return return
@ -284,7 +284,7 @@ func (c *C) logCaller(skip int) {
testFunc := runtime.FuncForPC(c.method.PC()) testFunc := runtime.FuncForPC(c.method.PC())
if runtime.FuncForPC(pc) != testFunc { if runtime.FuncForPC(pc) != testFunc {
for { for {
skip += 1 skip++
if pc, file, line, ok := runtime.Caller(skip); ok { if pc, file, line, ok := runtime.Caller(skip); ok {
// Note that the test line may be different on // Note that the test line may be different on
// distinct calls for the same test. Showing // distinct calls for the same test. Showing
@ -460,10 +460,10 @@ func (tracker *resultTracker) _loopRoutine() {
// Calls still running. Can't stop. // Calls still running. Can't stop.
select { select {
// XXX Reindent this (not now to make diff clear) // XXX Reindent this (not now to make diff clear)
case c = <-tracker._expectChan: case <-tracker._expectChan:
tracker._waiting += 1 tracker._waiting++
case c = <-tracker._doneChan: case c = <-tracker._doneChan:
tracker._waiting -= 1 tracker._waiting--
switch c.status() { switch c.status() {
case succeededSt: case succeededSt:
if c.kind == testKd { if c.kind == testKd {
@ -498,9 +498,9 @@ func (tracker *resultTracker) _loopRoutine() {
select { select {
case tracker._stopChan <- true: case tracker._stopChan <- true:
return return
case c = <-tracker._expectChan: case <-tracker._expectChan:
tracker._waiting += 1 tracker._waiting++
case c = <-tracker._doneChan: case <-tracker._doneChan:
panic("Tracker got an unexpected done call.") panic("Tracker got an unexpected done call.")
} }
} }
@ -522,6 +522,7 @@ type suiteRunner struct {
reportedProblemLast bool reportedProblemLast bool
benchTime time.Duration benchTime time.Duration
benchMem bool benchMem bool
abort bool
} }
type RunConf struct { type RunConf struct {
@ -533,6 +534,7 @@ type RunConf struct {
BenchmarkTime time.Duration // Defaults to 1 second BenchmarkTime time.Duration // Defaults to 1 second
BenchmarkMem bool BenchmarkMem bool
KeepWorkDir bool KeepWorkDir bool
Abort bool
} }
// Create a new suiteRunner able to run all methods in the given suite. // Create a new suiteRunner able to run all methods in the given suite.
@ -561,6 +563,7 @@ func newSuiteRunner(suite interface{}, runConf *RunConf) *suiteRunner {
tempDir: &tempDir{}, tempDir: &tempDir{},
keepDir: conf.KeepWorkDir, keepDir: conf.KeepWorkDir,
tests: make([]*methodType, 0, suiteNumMethods), tests: make([]*methodType, 0, suiteNumMethods),
abort: conf.Abort,
} }
if runner.benchTime == 0 { if runner.benchTime == 0 {
runner.benchTime = 1 * time.Second runner.benchTime = 1 * time.Second
@ -568,13 +571,13 @@ func newSuiteRunner(suite interface{}, runConf *RunConf) *suiteRunner {
var filterRegexp *regexp.Regexp var filterRegexp *regexp.Regexp
if conf.Filter != "" { if conf.Filter != "" {
if regexp, err := regexp.Compile(conf.Filter); err != nil { regexp, err := regexp.Compile(conf.Filter)
if err != nil {
msg := "Bad filter expression: " + err.Error() msg := "Bad filter expression: " + err.Error()
runner.tracker.result.RunError = errors.New(msg) runner.tracker.result.RunError = errors.New(msg)
return runner return runner
} else {
filterRegexp = regexp
} }
filterRegexp = regexp
} }
for i := 0; i != suiteNumMethods; i++ { for i := 0; i != suiteNumMethods; i++ {
@ -613,7 +616,9 @@ func (runner *suiteRunner) run() *Result {
if c == nil || c.status() == succeededSt { if c == nil || c.status() == succeededSt {
for i := 0; i != len(runner.tests); i++ { for i := 0; i != len(runner.tests); i++ {
c := runner.runTest(runner.tests[i]) c := runner.runTest(runner.tests[i])
if c.status() == fixturePanickedSt { status := c.status()
if status == fixturePanickedSt || runner.abort &&
(status == failedSt || status == panickedSt) {
runner.skipTests(missedSt, runner.tests[i+1:]) runner.skipTests(missedSt, runner.tests[i+1:])
break break
} }
@ -637,6 +642,16 @@ func (runner *suiteRunner) run() *Result {
return &runner.tracker.result return &runner.tracker.result
} }
// Skip all methods in the given suite.
func (runner *suiteRunner) skip() *Result {
if runner.tracker.result.RunError == nil && len(runner.tests) > 0 {
runner.tracker.start()
runner.skipTests(missedSt, runner.tests)
runner.tracker.waitAndStop()
}
return &runner.tracker.result
}
// Create a call object with the given suite method, and fork a // Create a call object with the given suite method, and fork a
// goroutine with the provided dispatcher for running it. // 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 { func (runner *suiteRunner) forkCall(method *methodType, kind funcKind, testName string, logb *logger, dispatcher func(c *C)) *C {
@ -871,84 +886,3 @@ func (runner *suiteRunner) reportCallDone(c *C) {
runner.output.WriteCallSuccess("MISS", c) runner.output.WriteCallSuccess("MISS", c)
} }
} }
// -----------------------------------------------------------------------
// Output writer manages atomic output writing according to settings.
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}
}
func (ow *outputWriter) Write(content []byte) (n int, err error) {
ow.m.Lock()
n, err = ow.writer.Write(content)
ow.m.Unlock()
return
}
func (ow *outputWriter) WriteCallStarted(label string, c *C) {
if ow.Stream {
header := renderCallHeader(label, c, "", "\n")
ow.m.Lock()
ow.writer.Write([]byte(header))
ow.m.Unlock()
}
}
func (ow *outputWriter) WriteCallProblem(label string, c *C) {
var prefix string
if !ow.Stream {
prefix = "\n-----------------------------------" +
"-----------------------------------\n"
}
header := renderCallHeader(label, c, prefix, "\n\n")
ow.m.Lock()
ow.wroteCallProblemLast = true
ow.writer.Write([]byte(header))
if !ow.Stream {
c.logb.WriteTo(ow.writer)
}
ow.m.Unlock()
}
func (ow *outputWriter) WriteCallSuccess(label string, c *C) {
if ow.Stream || (ow.Verbose && c.kind == testKd) {
// TODO Use a buffer here.
var suffix string
if c.reason != "" {
suffix = " (" + c.reason + ")"
}
if c.status() == succeededSt {
suffix += "\t" + c.timerString()
}
suffix += "\n"
if ow.Stream {
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 {
header = "\n-----------------------------------" +
"-----------------------------------\n" +
header
}
ow.wroteCallProblemLast = false
ow.writer.Write([]byte(header))
ow.m.Unlock()
}
}
func renderCallHeader(label string, c *C, prefix, suffix string) string {
pc := c.method.PC()
return fmt.Sprintf("%s%s: %s: %s%s", prefix, label, niceFuncPath(pc),
niceFuncName(pc), suffix)
}

View file

@ -88,7 +88,7 @@ func (checker *notChecker) Info() *CheckerInfo {
} }
func (checker *notChecker) Check(params []interface{}, names []string) (result bool, error string) { func (checker *notChecker) Check(params []interface{}, names []string) (result bool, error string) {
result, error = checker.sub.Check(params, names) result, _ = checker.sub.Check(params, names)
result = !result result = !result
return return
} }
@ -212,7 +212,7 @@ type hasLenChecker struct {
// The HasLen checker verifies that the obtained value has the // The HasLen checker verifies that the obtained value has the
// provided length. In many cases this is superior to using Equals // provided length. In many cases this is superior to using Equals
// in conjuction with the len function because in case the check // in conjunction with the len function because in case the check
// fails the value itself will be printed, instead of its length, // fails the value itself will be printed, instead of its length,
// providing more details for figuring the problem. // providing more details for figuring the problem.
// //
@ -235,7 +235,10 @@ func (checker *hasLenChecker) Check(params []interface{}, names []string) (resul
default: default:
return false, "obtained value type has no length" return false, "obtained value type has no length"
} }
return value.Len() == n, "" if value.Len() == n {
return true, ""
}
return false, fmt.Sprintf("obtained length = %d", value.Len())
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------

View file

@ -212,7 +212,7 @@ func (c *C) internalCheck(funcName string, obtained interface{}, checker Checker
// Do the actual check. // Do the actual check.
result, error := checker.Check(params, names) result, error := checker.Check(params, names)
if !result || error != "" { if !result {
c.logCaller(2) c.logCaller(2)
for i := 0; i != len(params); i++ { for i := 0; i != len(params); i++ {
c.logValue(names[i], params[i]) c.logValue(names[i], params[i])

88
vendor/github.com/go-check/check/reporter.go generated vendored Normal file
View file

@ -0,0 +1,88 @@
package check
import (
"fmt"
"io"
"sync"
)
// -----------------------------------------------------------------------
// Output writer manages atomic output writing according to settings.
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}
}
func (ow *outputWriter) Write(content []byte) (n int, err error) {
ow.m.Lock()
n, err = ow.writer.Write(content)
ow.m.Unlock()
return
}
func (ow *outputWriter) WriteCallStarted(label string, c *C) {
if ow.Stream {
header := renderCallHeader(label, c, "", "\n")
ow.m.Lock()
ow.writer.Write([]byte(header))
ow.m.Unlock()
}
}
func (ow *outputWriter) WriteCallProblem(label string, c *C) {
var prefix string
if !ow.Stream {
prefix = "\n-----------------------------------" +
"-----------------------------------\n"
}
header := renderCallHeader(label, c, prefix, "\n\n")
ow.m.Lock()
ow.wroteCallProblemLast = true
ow.writer.Write([]byte(header))
if !ow.Stream {
c.logb.WriteTo(ow.writer)
}
ow.m.Unlock()
}
func (ow *outputWriter) WriteCallSuccess(label string, c *C) {
if ow.Stream || (ow.Verbose && c.kind == testKd) {
// TODO Use a buffer here.
var suffix string
if c.reason != "" {
suffix = " (" + c.reason + ")"
}
if c.status() == succeededSt {
suffix += "\t" + c.timerString()
}
suffix += "\n"
if ow.Stream {
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 {
header = "\n-----------------------------------" +
"-----------------------------------\n" +
header
}
ow.wroteCallProblemLast = false
ow.writer.Write([]byte(header))
ow.m.Unlock()
}
}
func renderCallHeader(label string, c *C, prefix, suffix string) string {
pc := c.method.PC()
return fmt.Sprintf("%s%s: %s: %s%s", prefix, label, niceFuncPath(pc),
niceFuncName(pc), suffix)
}

View file

@ -42,6 +42,7 @@ var (
newBenchMem = flag.Bool("check.bmem", false, "Report memory benchmarks") newBenchMem = flag.Bool("check.bmem", false, "Report memory benchmarks")
newListFlag = flag.Bool("check.list", false, "List the names of all tests that will be run") newListFlag = flag.Bool("check.list", false, "List the names of all tests that will be run")
newWorkFlag = flag.Bool("check.work", false, "Display and do not remove the test working directory") newWorkFlag = flag.Bool("check.work", false, "Display and do not remove the test working directory")
abort = flag.Bool("check.abort", true, "Stop testing the suite if a test has failed")
) )
// TestingT runs all test suites registered with the Suite function, // TestingT runs all test suites registered with the Suite function,
@ -60,6 +61,7 @@ func TestingT(testingT *testing.T) {
BenchmarkTime: benchTime, BenchmarkTime: benchTime,
BenchmarkMem: *newBenchMem, BenchmarkMem: *newBenchMem,
KeepWorkDir: *oldWorkFlag || *newWorkFlag, KeepWorkDir: *oldWorkFlag || *newWorkFlag,
Abort: *abort,
} }
if *oldListFlag || *newListFlag { if *oldListFlag || *newListFlag {
w := bufio.NewWriter(os.Stdout) w := bufio.NewWriter(os.Stdout)
@ -80,8 +82,21 @@ func TestingT(testingT *testing.T) {
// provided run configuration. // provided run configuration.
func RunAll(runConf *RunConf) *Result { func RunAll(runConf *RunConf) *Result {
result := Result{} result := Result{}
skipTests := false
for _, suite := range allSuites { for _, suite := range allSuites {
result.Add(Run(suite, runConf)) var res *Result
if skipTests {
// Count missed tests.
res = skipSuite(suite, runConf)
} else {
res = Run(suite, runConf)
}
result.Add(res)
if runConf.Abort && (res.Failed > 0 || res.Panicked > 0) {
skipTests = true
continue
}
} }
return &result return &result
} }
@ -92,6 +107,11 @@ func Run(suite interface{}, runConf *RunConf) *Result {
return runner.run() return runner.run()
} }
func skipSuite(suite interface{}, runConf *RunConf) *Result {
runner := newSuiteRunner(suite, runConf)
return runner.skip()
}
// ListAll returns the names of all the test functions registered with the // ListAll returns the names of all the test functions registered with the
// Suite function that will be run with the provided run configuration. // Suite function that will be run with the provided run configuration.
func ListAll(runConf *RunConf) []string { func ListAll(runConf *RunConf) []string {