Signed-off-by: Brian Goff <cpuguy83@gmail.com>
| ... | ... |
@@ -11,7 +11,7 @@ clone git github.com/Microsoft/hcsshim 116e0e9f5ced0cec94ae46d0aa1b3002a325f532 |
| 11 | 11 |
clone git github.com/Microsoft/go-winio f778f05015353be65d242f3fedc18695756153bb |
| 12 | 12 |
clone git github.com/Sirupsen/logrus v0.9.0 # logrus is a common dependency among multiple deps |
| 13 | 13 |
clone git github.com/docker/libtrust 9cbd2a1374f46905c68a4eb3694a130610adc62a |
| 14 |
-clone git github.com/go-check/check 11d3bc7aa68e238947792f30573146a3231fc0f1 |
|
| 14 |
+clone git github.com/go-check/check a625211d932a2a643d0d17352095f03fb7774663 https://github.com/cpuguy83/check.git |
|
| 15 | 15 |
clone git github.com/gorilla/context 14f550f51a |
| 16 | 16 |
clone git github.com/gorilla/mux e444e69cbd |
| 17 | 17 |
clone git github.com/kr/pty 5cf931ef8f |
| 18 | 18 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,10 @@ |
| 0 |
+language: go |
|
| 1 |
+go: |
|
| 2 |
+ - 1.5 |
|
| 3 |
+ - tip |
|
| 4 |
+script: |
|
| 5 |
+ - go get -u github.com/golang/lint/golint |
|
| 6 |
+ - # go vet ./... |
|
| 7 |
+ - # test -z "$(golint ./... | tee /dev/stderr)" |
|
| 8 |
+ - # test -z "$(gofmt -s -l . | tee /dev/stderr)" |
|
| 9 |
+ - go test -v ./... |
| ... | ... |
@@ -1,20 +1,10 @@ |
| 1 |
-Instructions |
|
| 2 |
-============ |
|
| 1 |
+Go-check |
|
| 2 |
+======== |
|
| 3 | 3 |
|
| 4 |
-Install the package with: |
|
| 4 |
+This is a fork of https://github.com/go-check/check |
|
| 5 | 5 |
|
| 6 |
- go get gopkg.in/check.v1 |
|
| 7 |
- |
|
| 8 |
-Import it with: |
|
| 6 |
+The intention of this fork is not to change any of the original behavior, but add |
|
| 7 |
+some specific behaviors needed for some of my projects already using this test suite. |
|
| 8 |
+For documentation on the main behavior of go-check see the aforementioned repo. |
|
| 9 | 9 |
|
| 10 |
- import "gopkg.in/check.v1" |
|
| 11 |
- |
|
| 12 |
-and use _check_ as the package name inside the code. |
|
| 13 |
- |
|
| 14 |
-For more details, visit the project page: |
|
| 15 |
- |
|
| 16 |
-* http://labix.org/gocheck |
|
| 17 |
- |
|
| 18 |
-and the API documentation: |
|
| 19 |
- |
|
| 20 |
-* https://gopkg.in/check.v1 |
|
| 10 |
+The original branch is intact at `orig_v1` |
| ... | ... |
@@ -522,6 +522,7 @@ type suiteRunner struct {
|
| 522 | 522 |
reportedProblemLast bool |
| 523 | 523 |
benchTime time.Duration |
| 524 | 524 |
benchMem bool |
| 525 |
+ checkTimeout time.Duration |
|
| 525 | 526 |
} |
| 526 | 527 |
|
| 527 | 528 |
type RunConf struct {
|
| ... | ... |
@@ -533,6 +534,7 @@ type RunConf struct {
|
| 533 | 533 |
BenchmarkTime time.Duration // Defaults to 1 second |
| 534 | 534 |
BenchmarkMem bool |
| 535 | 535 |
KeepWorkDir bool |
| 536 |
+ CheckTimeout time.Duration |
|
| 536 | 537 |
} |
| 537 | 538 |
|
| 538 | 539 |
// Create a new suiteRunner able to run all methods in the given suite. |
| ... | ... |
@@ -553,14 +555,15 @@ func newSuiteRunner(suite interface{}, runConf *RunConf) *suiteRunner {
|
| 553 | 553 |
suiteValue := reflect.ValueOf(suite) |
| 554 | 554 |
|
| 555 | 555 |
runner := &suiteRunner{
|
| 556 |
- suite: suite, |
|
| 557 |
- output: newOutputWriter(conf.Output, conf.Stream, conf.Verbose), |
|
| 558 |
- tracker: newResultTracker(), |
|
| 559 |
- benchTime: conf.BenchmarkTime, |
|
| 560 |
- benchMem: conf.BenchmarkMem, |
|
| 561 |
- tempDir: &tempDir{},
|
|
| 562 |
- keepDir: conf.KeepWorkDir, |
|
| 563 |
- tests: make([]*methodType, 0, suiteNumMethods), |
|
| 556 |
+ suite: suite, |
|
| 557 |
+ output: newOutputWriter(conf.Output, conf.Stream, conf.Verbose), |
|
| 558 |
+ tracker: newResultTracker(), |
|
| 559 |
+ benchTime: conf.BenchmarkTime, |
|
| 560 |
+ benchMem: conf.BenchmarkMem, |
|
| 561 |
+ tempDir: &tempDir{},
|
|
| 562 |
+ keepDir: conf.KeepWorkDir, |
|
| 563 |
+ tests: make([]*methodType, 0, suiteNumMethods), |
|
| 564 |
+ checkTimeout: conf.CheckTimeout, |
|
| 564 | 565 |
} |
| 565 | 566 |
if runner.benchTime == 0 {
|
| 566 | 567 |
runner.benchTime = 1 * time.Second |
| ... | ... |
@@ -670,8 +673,16 @@ func (runner *suiteRunner) forkCall(method *methodType, kind funcKind, testName |
| 670 | 670 |
|
| 671 | 671 |
// Same as forkCall(), but wait for call to finish before returning. |
| 672 | 672 |
func (runner *suiteRunner) runFunc(method *methodType, kind funcKind, testName string, logb *logger, dispatcher func(c *C)) *C {
|
| 673 |
+ var timeout <-chan time.Time |
|
| 674 |
+ if runner.checkTimeout != 0 {
|
|
| 675 |
+ timeout = time.After(runner.checkTimeout) |
|
| 676 |
+ } |
|
| 673 | 677 |
c := runner.forkCall(method, kind, testName, logb, dispatcher) |
| 674 |
- <-c.done |
|
| 678 |
+ select {
|
|
| 679 |
+ case <-c.done: |
|
| 680 |
+ case <-timeout: |
|
| 681 |
+ panic(fmt.Sprintf("test timed out after %v", runner.checkTimeout))
|
|
| 682 |
+ } |
|
| 675 | 683 |
return c |
| 676 | 684 |
} |
| 677 | 685 |
|
| ... | ... |
@@ -806,8 +817,16 @@ func (runner *suiteRunner) forkTest(method *methodType) *C {
|
| 806 | 806 |
|
| 807 | 807 |
// Same as forkTest(), but wait for the test to finish before returning. |
| 808 | 808 |
func (runner *suiteRunner) runTest(method *methodType) *C {
|
| 809 |
+ var timeout <-chan time.Time |
|
| 810 |
+ if runner.checkTimeout != 0 {
|
|
| 811 |
+ timeout = time.After(runner.checkTimeout) |
|
| 812 |
+ } |
|
| 809 | 813 |
c := runner.forkTest(method) |
| 810 |
- <-c.done |
|
| 814 |
+ select {
|
|
| 815 |
+ case <-c.done: |
|
| 816 |
+ case <-timeout: |
|
| 817 |
+ panic(fmt.Sprintf("test timed out after %v", runner.checkTimeout))
|
|
| 818 |
+ } |
|
| 811 | 819 |
return c |
| 812 | 820 |
} |
| 813 | 821 |
|
| ... | ... |
@@ -871,84 +890,3 @@ func (runner *suiteRunner) reportCallDone(c *C) {
|
| 871 | 871 |
runner.output.WriteCallSuccess("MISS", c)
|
| 872 | 872 |
} |
| 873 | 873 |
} |
| 874 |
- |
|
| 875 |
-// ----------------------------------------------------------------------- |
|
| 876 |
-// Output writer manages atomic output writing according to settings. |
|
| 877 |
- |
|
| 878 |
-type outputWriter struct {
|
|
| 879 |
- m sync.Mutex |
|
| 880 |
- writer io.Writer |
|
| 881 |
- wroteCallProblemLast bool |
|
| 882 |
- Stream bool |
|
| 883 |
- Verbose bool |
|
| 884 |
-} |
|
| 885 |
- |
|
| 886 |
-func newOutputWriter(writer io.Writer, stream, verbose bool) *outputWriter {
|
|
| 887 |
- return &outputWriter{writer: writer, Stream: stream, Verbose: verbose}
|
|
| 888 |
-} |
|
| 889 |
- |
|
| 890 |
-func (ow *outputWriter) Write(content []byte) (n int, err error) {
|
|
| 891 |
- ow.m.Lock() |
|
| 892 |
- n, err = ow.writer.Write(content) |
|
| 893 |
- ow.m.Unlock() |
|
| 894 |
- return |
|
| 895 |
-} |
|
| 896 |
- |
|
| 897 |
-func (ow *outputWriter) WriteCallStarted(label string, c *C) {
|
|
| 898 |
- if ow.Stream {
|
|
| 899 |
- header := renderCallHeader(label, c, "", "\n") |
|
| 900 |
- ow.m.Lock() |
|
| 901 |
- ow.writer.Write([]byte(header)) |
|
| 902 |
- ow.m.Unlock() |
|
| 903 |
- } |
|
| 904 |
-} |
|
| 905 |
- |
|
| 906 |
-func (ow *outputWriter) WriteCallProblem(label string, c *C) {
|
|
| 907 |
- var prefix string |
|
| 908 |
- if !ow.Stream {
|
|
| 909 |
- prefix = "\n-----------------------------------" + |
|
| 910 |
- "-----------------------------------\n" |
|
| 911 |
- } |
|
| 912 |
- header := renderCallHeader(label, c, prefix, "\n\n") |
|
| 913 |
- ow.m.Lock() |
|
| 914 |
- ow.wroteCallProblemLast = true |
|
| 915 |
- ow.writer.Write([]byte(header)) |
|
| 916 |
- if !ow.Stream {
|
|
| 917 |
- c.logb.WriteTo(ow.writer) |
|
| 918 |
- } |
|
| 919 |
- ow.m.Unlock() |
|
| 920 |
-} |
|
| 921 |
- |
|
| 922 |
-func (ow *outputWriter) WriteCallSuccess(label string, c *C) {
|
|
| 923 |
- if ow.Stream || (ow.Verbose && c.kind == testKd) {
|
|
| 924 |
- // TODO Use a buffer here. |
|
| 925 |
- var suffix string |
|
| 926 |
- if c.reason != "" {
|
|
| 927 |
- suffix = " (" + c.reason + ")"
|
|
| 928 |
- } |
|
| 929 |
- if c.status() == succeededSt {
|
|
| 930 |
- suffix += "\t" + c.timerString() |
|
| 931 |
- } |
|
| 932 |
- suffix += "\n" |
|
| 933 |
- if ow.Stream {
|
|
| 934 |
- suffix += "\n" |
|
| 935 |
- } |
|
| 936 |
- header := renderCallHeader(label, c, "", suffix) |
|
| 937 |
- ow.m.Lock() |
|
| 938 |
- // Resist temptation of using line as prefix above due to race. |
|
| 939 |
- if !ow.Stream && ow.wroteCallProblemLast {
|
|
| 940 |
- header = "\n-----------------------------------" + |
|
| 941 |
- "-----------------------------------\n" + |
|
| 942 |
- header |
|
| 943 |
- } |
|
| 944 |
- ow.wroteCallProblemLast = false |
|
| 945 |
- ow.writer.Write([]byte(header)) |
|
| 946 |
- ow.m.Unlock() |
|
| 947 |
- } |
|
| 948 |
-} |
|
| 949 |
- |
|
| 950 |
-func renderCallHeader(label string, c *C, prefix, suffix string) string {
|
|
| 951 |
- pc := c.method.PC() |
|
| 952 |
- return fmt.Sprintf("%s%s: %s: %s%s", prefix, label, niceFuncPath(pc),
|
|
| 953 |
- niceFuncName(pc), suffix) |
|
| 954 |
-} |
| 955 | 874 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,88 @@ |
| 0 |
+package check |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "fmt" |
|
| 4 |
+ "io" |
|
| 5 |
+ "sync" |
|
| 6 |
+) |
|
| 7 |
+ |
|
| 8 |
+// ----------------------------------------------------------------------- |
|
| 9 |
+// Output writer manages atomic output writing according to settings. |
|
| 10 |
+ |
|
| 11 |
+type outputWriter struct {
|
|
| 12 |
+ m sync.Mutex |
|
| 13 |
+ writer io.Writer |
|
| 14 |
+ wroteCallProblemLast bool |
|
| 15 |
+ Stream bool |
|
| 16 |
+ Verbose bool |
|
| 17 |
+} |
|
| 18 |
+ |
|
| 19 |
+func newOutputWriter(writer io.Writer, stream, verbose bool) *outputWriter {
|
|
| 20 |
+ return &outputWriter{writer: writer, Stream: stream, Verbose: verbose}
|
|
| 21 |
+} |
|
| 22 |
+ |
|
| 23 |
+func (ow *outputWriter) Write(content []byte) (n int, err error) {
|
|
| 24 |
+ ow.m.Lock() |
|
| 25 |
+ n, err = ow.writer.Write(content) |
|
| 26 |
+ ow.m.Unlock() |
|
| 27 |
+ return |
|
| 28 |
+} |
|
| 29 |
+ |
|
| 30 |
+func (ow *outputWriter) WriteCallStarted(label string, c *C) {
|
|
| 31 |
+ if ow.Stream {
|
|
| 32 |
+ header := renderCallHeader(label, c, "", "\n") |
|
| 33 |
+ ow.m.Lock() |
|
| 34 |
+ ow.writer.Write([]byte(header)) |
|
| 35 |
+ ow.m.Unlock() |
|
| 36 |
+ } |
|
| 37 |
+} |
|
| 38 |
+ |
|
| 39 |
+func (ow *outputWriter) WriteCallProblem(label string, c *C) {
|
|
| 40 |
+ var prefix string |
|
| 41 |
+ if !ow.Stream {
|
|
| 42 |
+ prefix = "\n-----------------------------------" + |
|
| 43 |
+ "-----------------------------------\n" |
|
| 44 |
+ } |
|
| 45 |
+ header := renderCallHeader(label, c, prefix, "\n\n") |
|
| 46 |
+ ow.m.Lock() |
|
| 47 |
+ ow.wroteCallProblemLast = true |
|
| 48 |
+ ow.writer.Write([]byte(header)) |
|
| 49 |
+ if !ow.Stream {
|
|
| 50 |
+ c.logb.WriteTo(ow.writer) |
|
| 51 |
+ } |
|
| 52 |
+ ow.m.Unlock() |
|
| 53 |
+} |
|
| 54 |
+ |
|
| 55 |
+func (ow *outputWriter) WriteCallSuccess(label string, c *C) {
|
|
| 56 |
+ if ow.Stream || (ow.Verbose && c.kind == testKd) {
|
|
| 57 |
+ // TODO Use a buffer here. |
|
| 58 |
+ var suffix string |
|
| 59 |
+ if c.reason != "" {
|
|
| 60 |
+ suffix = " (" + c.reason + ")"
|
|
| 61 |
+ } |
|
| 62 |
+ if c.status() == succeededSt {
|
|
| 63 |
+ suffix += "\t" + c.timerString() |
|
| 64 |
+ } |
|
| 65 |
+ suffix += "\n" |
|
| 66 |
+ if ow.Stream {
|
|
| 67 |
+ suffix += "\n" |
|
| 68 |
+ } |
|
| 69 |
+ header := renderCallHeader(label, c, "", suffix) |
|
| 70 |
+ ow.m.Lock() |
|
| 71 |
+ // Resist temptation of using line as prefix above due to race. |
|
| 72 |
+ if !ow.Stream && ow.wroteCallProblemLast {
|
|
| 73 |
+ header = "\n-----------------------------------" + |
|
| 74 |
+ "-----------------------------------\n" + |
|
| 75 |
+ header |
|
| 76 |
+ } |
|
| 77 |
+ ow.wroteCallProblemLast = false |
|
| 78 |
+ ow.writer.Write([]byte(header)) |
|
| 79 |
+ ow.m.Unlock() |
|
| 80 |
+ } |
|
| 81 |
+} |
|
| 82 |
+ |
|
| 83 |
+func renderCallHeader(label string, c *C, prefix, suffix string) string {
|
|
| 84 |
+ pc := c.method.PC() |
|
| 85 |
+ return fmt.Sprintf("%s%s: %s: %s%s", prefix, label, niceFuncPath(pc),
|
|
| 86 |
+ niceFuncName(pc), suffix) |
|
| 87 |
+} |
| ... | ... |
@@ -42,6 +42,7 @@ var ( |
| 42 | 42 |
newBenchMem = flag.Bool("check.bmem", false, "Report memory benchmarks")
|
| 43 | 43 |
newListFlag = flag.Bool("check.list", false, "List the names of all tests that will be run")
|
| 44 | 44 |
newWorkFlag = flag.Bool("check.work", false, "Display and do not remove the test working directory")
|
| 45 |
+ checkTimeout = flag.String("check.timeout", "", "Panic if test runs longer than specified duration")
|
|
| 45 | 46 |
) |
| 46 | 47 |
|
| 47 | 48 |
// TestingT runs all test suites registered with the Suite function, |
| ... | ... |
@@ -61,6 +62,13 @@ func TestingT(testingT *testing.T) {
|
| 61 | 61 |
BenchmarkMem: *newBenchMem, |
| 62 | 62 |
KeepWorkDir: *oldWorkFlag || *newWorkFlag, |
| 63 | 63 |
} |
| 64 |
+ if *checkTimeout != "" {
|
|
| 65 |
+ timeout, err := time.ParseDuration(*checkTimeout) |
|
| 66 |
+ if err != nil {
|
|
| 67 |
+ testingT.Fatalf("error parsing specified timeout flag: %v", err)
|
|
| 68 |
+ } |
|
| 69 |
+ conf.CheckTimeout = timeout |
|
| 70 |
+ } |
|
| 64 | 71 |
if *oldListFlag || *newListFlag {
|
| 65 | 72 |
w := bufio.NewWriter(os.Stdout) |
| 66 | 73 |
for _, name := range ListAll(conf) {
|