From b019f3ee29ce55c3d515ee8bafe0f4bb14221c0a Mon Sep 17 00:00:00 2001 From: Péter Szilágyi Date: Thu, 11 Feb 2016 16:16:52 +0200 Subject: Godeps: update all dependencies to latest code --- .../_workspace/src/gopkg.in/check.v1/benchmark.go | 30 +- .../src/gopkg.in/check.v1/benchmark_test.go | 91 ---- .../src/gopkg.in/check.v1/bootstrap_test.go | 82 ---- Godeps/_workspace/src/gopkg.in/check.v1/check.go | 132 ++---- .../_workspace/src/gopkg.in/check.v1/check_test.go | 207 -------- .../src/gopkg.in/check.v1/checkers_test.go | 272 ----------- .../src/gopkg.in/check.v1/export_test.go | 9 - .../src/gopkg.in/check.v1/fixture_test.go | 484 ------------------- .../src/gopkg.in/check.v1/foundation_test.go | 335 ------------- Godeps/_workspace/src/gopkg.in/check.v1/helpers.go | 8 +- .../src/gopkg.in/check.v1/helpers_test.go | 519 --------------------- .../src/gopkg.in/check.v1/printer_test.go | 104 ----- .../_workspace/src/gopkg.in/check.v1/reporter.go | 88 ++++ .../_workspace/src/gopkg.in/check.v1/run_test.go | 419 ----------------- .../src/gopkg.in/fatih/set.v0/set_nots_test.go | 282 ----------- .../src/gopkg.in/fatih/set.v0/set_test.go | 188 -------- .../src/gopkg.in/fatih/set.v0/set_ts_test.go | 321 ------------- .../src/gopkg.in/karalabe/cookiejar.v2/LICENSE | 25 + .../cookiejar.v2/collections/prque/example_test.go | 44 -- .../cookiejar.v2/collections/prque/prque_test.go | 130 ------ .../cookiejar.v2/collections/prque/sstack_test.go | 100 ---- 21 files changed, 174 insertions(+), 3696 deletions(-) delete mode 100644 Godeps/_workspace/src/gopkg.in/check.v1/benchmark_test.go delete mode 100644 Godeps/_workspace/src/gopkg.in/check.v1/bootstrap_test.go delete mode 100644 Godeps/_workspace/src/gopkg.in/check.v1/check_test.go delete mode 100644 Godeps/_workspace/src/gopkg.in/check.v1/checkers_test.go delete mode 100644 Godeps/_workspace/src/gopkg.in/check.v1/export_test.go delete mode 100644 Godeps/_workspace/src/gopkg.in/check.v1/fixture_test.go delete mode 100644 Godeps/_workspace/src/gopkg.in/check.v1/foundation_test.go delete mode 100644 Godeps/_workspace/src/gopkg.in/check.v1/helpers_test.go delete mode 100644 Godeps/_workspace/src/gopkg.in/check.v1/printer_test.go create mode 100644 Godeps/_workspace/src/gopkg.in/check.v1/reporter.go delete mode 100644 Godeps/_workspace/src/gopkg.in/check.v1/run_test.go delete mode 100644 Godeps/_workspace/src/gopkg.in/fatih/set.v0/set_nots_test.go delete mode 100644 Godeps/_workspace/src/gopkg.in/fatih/set.v0/set_test.go delete mode 100644 Godeps/_workspace/src/gopkg.in/fatih/set.v0/set_ts_test.go create mode 100644 Godeps/_workspace/src/gopkg.in/karalabe/cookiejar.v2/LICENSE delete mode 100644 Godeps/_workspace/src/gopkg.in/karalabe/cookiejar.v2/collections/prque/example_test.go delete mode 100644 Godeps/_workspace/src/gopkg.in/karalabe/cookiejar.v2/collections/prque/prque_test.go delete mode 100644 Godeps/_workspace/src/gopkg.in/karalabe/cookiejar.v2/collections/prque/sstack_test.go (limited to 'Godeps/_workspace/src/gopkg.in') diff --git a/Godeps/_workspace/src/gopkg.in/check.v1/benchmark.go b/Godeps/_workspace/src/gopkg.in/check.v1/benchmark.go index 48cb8c811..46ea9dc6d 100644 --- a/Godeps/_workspace/src/gopkg.in/check.v1/benchmark.go +++ b/Godeps/_workspace/src/gopkg.in/check.v1/benchmark.go @@ -1,6 +1,30 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. +// Copyright (c) 2012 The Go Authors. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package check diff --git a/Godeps/_workspace/src/gopkg.in/check.v1/benchmark_test.go b/Godeps/_workspace/src/gopkg.in/check.v1/benchmark_test.go deleted file mode 100644 index 4dd827c16..000000000 --- a/Godeps/_workspace/src/gopkg.in/check.v1/benchmark_test.go +++ /dev/null @@ -1,91 +0,0 @@ -// These tests verify the test running logic. - -package check_test - -import ( - "time" - . "gopkg.in/check.v1" -) - -var benchmarkS = Suite(&BenchmarkS{}) - -type BenchmarkS struct{} - -func (s *BenchmarkS) TestCountSuite(c *C) { - suitesRun += 1 -} - -func (s *BenchmarkS) TestBasicTestTiming(c *C) { - helper := FixtureHelper{sleepOn: "Test1", sleep: 1000000 * time.Nanosecond} - output := String{} - runConf := RunConf{Output: &output, Verbose: true} - Run(&helper, &runConf) - - expected := "PASS: check_test\\.go:[0-9]+: FixtureHelper\\.Test1\t0\\.001s\n" + - "PASS: check_test\\.go:[0-9]+: FixtureHelper\\.Test2\t0\\.000s\n" - c.Assert(output.value, Matches, expected) -} - -func (s *BenchmarkS) TestStreamTestTiming(c *C) { - helper := FixtureHelper{sleepOn: "SetUpSuite", sleep: 1000000 * time.Nanosecond} - output := String{} - runConf := RunConf{Output: &output, Stream: true} - Run(&helper, &runConf) - - expected := "(?s).*\nPASS: check_test\\.go:[0-9]+: FixtureHelper\\.SetUpSuite\t *0\\.001s\n.*" - c.Assert(output.value, Matches, expected) -} - -func (s *BenchmarkS) TestBenchmark(c *C) { - helper := FixtureHelper{sleep: 100000} - output := String{} - runConf := RunConf{ - Output: &output, - Benchmark: true, - BenchmarkTime: 10000000, - Filter: "Benchmark1", - } - Run(&helper, &runConf) - c.Check(helper.calls[0], Equals, "SetUpSuite") - c.Check(helper.calls[1], Equals, "SetUpTest") - c.Check(helper.calls[2], Equals, "Benchmark1") - c.Check(helper.calls[3], Equals, "TearDownTest") - c.Check(helper.calls[4], Equals, "SetUpTest") - c.Check(helper.calls[5], Equals, "Benchmark1") - c.Check(helper.calls[6], Equals, "TearDownTest") - // ... and more. - - expected := "PASS: check_test\\.go:[0-9]+: FixtureHelper\\.Benchmark1\t *100\t *[12][0-9]{5} ns/op\n" - c.Assert(output.value, Matches, expected) -} - -func (s *BenchmarkS) TestBenchmarkBytes(c *C) { - helper := FixtureHelper{sleep: 100000} - output := String{} - runConf := RunConf{ - Output: &output, - Benchmark: true, - BenchmarkTime: 10000000, - Filter: "Benchmark2", - } - Run(&helper, &runConf) - - expected := "PASS: check_test\\.go:[0-9]+: FixtureHelper\\.Benchmark2\t *100\t *[12][0-9]{5} ns/op\t *[4-9]\\.[0-9]{2} MB/s\n" - c.Assert(output.value, Matches, expected) -} - -func (s *BenchmarkS) TestBenchmarkMem(c *C) { - helper := FixtureHelper{sleep: 100000} - output := String{} - runConf := RunConf{ - Output: &output, - Benchmark: true, - BenchmarkMem: true, - BenchmarkTime: 10000000, - Filter: "Benchmark3", - } - Run(&helper, &runConf) - - expected := "PASS: check_test\\.go:[0-9]+: FixtureHelper\\.Benchmark3\t *100\t *[12][0-9]{5} ns/op\t *[0-9]+ B/op\t *[1-9] allocs/op\n" - c.Assert(output.value, Matches, expected) -} diff --git a/Godeps/_workspace/src/gopkg.in/check.v1/bootstrap_test.go b/Godeps/_workspace/src/gopkg.in/check.v1/bootstrap_test.go deleted file mode 100644 index e55f327c7..000000000 --- a/Godeps/_workspace/src/gopkg.in/check.v1/bootstrap_test.go +++ /dev/null @@ -1,82 +0,0 @@ -// These initial tests are for bootstrapping. They verify that we can -// basically use the testing infrastructure itself to check if the test -// system is working. -// -// These tests use will break down the test runner badly in case of -// errors because if they simply fail, we can't be sure the developer -// will ever see anything (because failing means the failing system -// somehow isn't working! :-) -// -// Do not assume *any* internal functionality works as expected besides -// what's actually tested here. - -package check_test - -import ( - "fmt" - "gopkg.in/check.v1" - "strings" -) - -type BootstrapS struct{} - -var boostrapS = check.Suite(&BootstrapS{}) - -func (s *BootstrapS) TestCountSuite(c *check.C) { - suitesRun += 1 -} - -func (s *BootstrapS) TestFailedAndFail(c *check.C) { - if c.Failed() { - critical("c.Failed() must be false first!") - } - c.Fail() - if !c.Failed() { - critical("c.Fail() didn't put the test in a failed state!") - } - c.Succeed() -} - -func (s *BootstrapS) TestFailedAndSucceed(c *check.C) { - c.Fail() - c.Succeed() - if c.Failed() { - critical("c.Succeed() didn't put the test back in a non-failed state") - } -} - -func (s *BootstrapS) TestLogAndGetTestLog(c *check.C) { - c.Log("Hello there!") - log := c.GetTestLog() - if log != "Hello there!\n" { - critical(fmt.Sprintf("Log() or GetTestLog() is not working! Got: %#v", log)) - } -} - -func (s *BootstrapS) TestLogfAndGetTestLog(c *check.C) { - c.Logf("Hello %v", "there!") - log := c.GetTestLog() - if log != "Hello there!\n" { - critical(fmt.Sprintf("Logf() or GetTestLog() is not working! Got: %#v", log)) - } -} - -func (s *BootstrapS) TestRunShowsErrors(c *check.C) { - output := String{} - check.Run(&FailHelper{}, &check.RunConf{Output: &output}) - if strings.Index(output.value, "Expected failure!") == -1 { - critical(fmt.Sprintf("RunWithWriter() output did not contain the "+ - "expected failure! Got: %#v", - output.value)) - } -} - -func (s *BootstrapS) TestRunDoesntShowSuccesses(c *check.C) { - output := String{} - check.Run(&SuccessHelper{}, &check.RunConf{Output: &output}) - if strings.Index(output.value, "Expected success!") != -1 { - critical(fmt.Sprintf("RunWithWriter() output contained a successful "+ - "test! Got: %#v", - output.value)) - } -} diff --git a/Godeps/_workspace/src/gopkg.in/check.v1/check.go b/Godeps/_workspace/src/gopkg.in/check.v1/check.go index ca8c0f92d..82c26fa73 100644 --- a/Godeps/_workspace/src/gopkg.in/check.v1/check.go +++ b/Godeps/_workspace/src/gopkg.in/check.v1/check.go @@ -21,6 +21,7 @@ import ( "strconv" "strings" "sync" + "sync/atomic" "time" ) @@ -43,7 +44,7 @@ const ( missedSt ) -type funcStatus int +type funcStatus uint32 // A method value can't reach its own Method structure. type methodType struct { @@ -81,7 +82,7 @@ type C struct { method *methodType kind funcKind testName string - status funcStatus + _status funcStatus logb *logger logw io.Writer done chan *C @@ -93,6 +94,14 @@ type C struct { timer } +func (c *C) status() funcStatus { + return funcStatus(atomic.LoadUint32((*uint32)(&c._status))) +} + +func (c *C) setStatus(s funcStatus) { + atomic.StoreUint32((*uint32)(&c._status), uint32(s)) +} + func (c *C) stopNow() { runtime.Goexit() } @@ -326,7 +335,7 @@ func (c *C) logPanic(skip int, value interface{}) { if name == "Value.call" && strings.HasSuffix(path, valueGo) { continue } - if name == "call16" && strings.Contains(path, asmGo) { + if (name == "call16" || name == "call32") && strings.Contains(path, asmGo) { continue } c.logf("%s:%d\n in %s", nicePath(file), line, name) @@ -455,7 +464,7 @@ func (tracker *resultTracker) _loopRoutine() { tracker._waiting += 1 case c = <-tracker._doneChan: tracker._waiting -= 1 - switch c.status { + switch c.status() { case succeededSt: if c.kind == testKd { if c.mustFail { @@ -601,15 +610,15 @@ func (runner *suiteRunner) run() *Result { runner.tracker.start() if runner.checkFixtureArgs() { c := runner.runFixture(runner.setUpSuite, "", nil) - if c == nil || c.status == succeededSt { + if c == nil || c.status() == succeededSt { for i := 0; i != len(runner.tests); i++ { c := runner.runTest(runner.tests[i]) - if c.status == fixturePanickedSt { + if c.status() == fixturePanickedSt { runner.skipTests(missedSt, runner.tests[i+1:]) break } } - } else if c != nil && c.status == skippedSt { + } else if c != nil && c.status() == skippedSt { runner.skipTests(skippedSt, runner.tests) } else { runner.skipTests(missedSt, runner.tests) @@ -674,22 +683,22 @@ func (runner *suiteRunner) callDone(c *C) { switch v := value.(type) { case *fixturePanic: if v.status == skippedSt { - c.status = skippedSt + c.setStatus(skippedSt) } else { c.logSoftPanic("Fixture has panicked (see related PANIC)") - c.status = fixturePanickedSt + c.setStatus(fixturePanickedSt) } default: c.logPanic(1, value) - c.status = panickedSt + c.setStatus(panickedSt) } } if c.mustFail { - switch c.status { + switch c.status() { case failedSt: - c.status = succeededSt + c.setStatus(succeededSt) case succeededSt: - c.status = failedSt + c.setStatus(failedSt) c.logString("Error: Test succeeded, but was expected to fail") c.logString("Reason: " + c.reason) } @@ -724,11 +733,11 @@ func (runner *suiteRunner) runFixtureWithPanic(method *methodType, testName stri return nil } c := runner.runFixture(method, testName, logb) - if c != nil && c.status != succeededSt { + if c != nil && c.status() != succeededSt { if skipped != nil { - *skipped = c.status == skippedSt + *skipped = c.status() == skippedSt } - panic(&fixturePanic{c.status, method}) + panic(&fixturePanic{c.status(), method}) } return c } @@ -753,7 +762,7 @@ func (runner *suiteRunner) forkTest(method *methodType) *C { if mt.NumIn() != 1 || mt.In(0) != reflect.TypeOf(c) { // Rather than a plain panic, provide a more helpful message when // the argument type is incorrect. - c.status = panickedSt + c.setStatus(panickedSt) c.logArgPanic(c.method, "*check.C") return } @@ -773,7 +782,7 @@ func (runner *suiteRunner) forkTest(method *methodType) *C { c.StartTimer() c.method.Call([]reflect.Value{reflect.ValueOf(c)}) c.StopTimer() - if c.status != succeededSt || c.duration >= c.benchTime || benchN >= 1e9 { + if c.status() != succeededSt || c.duration >= c.benchTime || benchN >= 1e9 { return } perOpN := int(1e9) @@ -808,7 +817,7 @@ func (runner *suiteRunner) runTest(method *methodType) *C { func (runner *suiteRunner) skipTests(status funcStatus, methods []*methodType) { for _, method := range methods { runner.runFunc(method, testKd, "", nil, func(c *C) { - c.status = status + c.setStatus(status) }) } } @@ -825,7 +834,7 @@ func (runner *suiteRunner) checkFixtureArgs() bool { succeeded = false runner.runFunc(method, fixtureKd, "", nil, func(c *C) { c.logArgPanic(method, "*check.C") - c.status = panickedSt + c.setStatus(panickedSt) }) } } @@ -839,7 +848,7 @@ func (runner *suiteRunner) reportCallStarted(c *C) { func (runner *suiteRunner) reportCallDone(c *C) { runner.tracker.callDone(c) - switch c.status { + switch c.status() { case succeededSt: if c.mustFail { runner.output.WriteCallSuccess("FAIL EXPECTED", c) @@ -862,84 +871,3 @@ func (runner *suiteRunner) reportCallDone(c *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) -} diff --git a/Godeps/_workspace/src/gopkg.in/check.v1/check_test.go b/Godeps/_workspace/src/gopkg.in/check.v1/check_test.go deleted file mode 100644 index 871b32527..000000000 --- a/Godeps/_workspace/src/gopkg.in/check.v1/check_test.go +++ /dev/null @@ -1,207 +0,0 @@ -// This file contains just a few generic helpers which are used by the -// other test files. - -package check_test - -import ( - "flag" - "fmt" - "os" - "regexp" - "runtime" - "testing" - "time" - - "gopkg.in/check.v1" -) - -// We count the number of suites run at least to get a vague hint that the -// test suite is behaving as it should. Otherwise a bug introduced at the -// very core of the system could go unperceived. -const suitesRunExpected = 8 - -var suitesRun int = 0 - -func Test(t *testing.T) { - check.TestingT(t) - if suitesRun != suitesRunExpected && flag.Lookup("check.f").Value.String() == "" { - critical(fmt.Sprintf("Expected %d suites to run rather than %d", - suitesRunExpected, suitesRun)) - } -} - -// ----------------------------------------------------------------------- -// Helper functions. - -// Break down badly. This is used in test cases which can't yet assume -// that the fundamental bits are working. -func critical(error string) { - fmt.Fprintln(os.Stderr, "CRITICAL: "+error) - os.Exit(1) -} - -// Return the file line where it's called. -func getMyLine() int { - if _, _, line, ok := runtime.Caller(1); ok { - return line - } - return -1 -} - -// ----------------------------------------------------------------------- -// Helper type implementing a basic io.Writer for testing output. - -// Type implementing the io.Writer interface for analyzing output. -type String struct { - value string -} - -// The only function required by the io.Writer interface. Will append -// written data to the String.value string. -func (s *String) Write(p []byte) (n int, err error) { - s.value += string(p) - return len(p), nil -} - -// 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() -} - -// ----------------------------------------------------------------------- -// Helper suite for testing basic fail behavior. - -type FailHelper struct { - testLine int -} - -func (s *FailHelper) TestLogAndFail(c *check.C) { - s.testLine = getMyLine() - 1 - c.Log("Expected failure!") - c.Fail() -} - -// ----------------------------------------------------------------------- -// Helper suite for testing basic success behavior. - -type SuccessHelper struct{} - -func (s *SuccessHelper) TestLogAndSucceed(c *check.C) { - c.Log("Expected success!") -} - -// ----------------------------------------------------------------------- -// Helper suite for testing ordering and behavior of fixture. - -type FixtureHelper struct { - calls []string - panicOn string - skip bool - skipOnN int - sleepOn string - sleep time.Duration - bytes int64 -} - -func (s *FixtureHelper) trace(name string, c *check.C) { - s.calls = append(s.calls, name) - if name == s.panicOn { - panic(name) - } - if s.sleep > 0 && s.sleepOn == name { - time.Sleep(s.sleep) - } - if s.skip && s.skipOnN == len(s.calls)-1 { - c.Skip("skipOnN == n") - } -} - -func (s *FixtureHelper) SetUpSuite(c *check.C) { - s.trace("SetUpSuite", c) -} - -func (s *FixtureHelper) TearDownSuite(c *check.C) { - s.trace("TearDownSuite", c) -} - -func (s *FixtureHelper) SetUpTest(c *check.C) { - s.trace("SetUpTest", c) -} - -func (s *FixtureHelper) TearDownTest(c *check.C) { - s.trace("TearDownTest", c) -} - -func (s *FixtureHelper) Test1(c *check.C) { - s.trace("Test1", c) -} - -func (s *FixtureHelper) Test2(c *check.C) { - s.trace("Test2", c) -} - -func (s *FixtureHelper) Benchmark1(c *check.C) { - s.trace("Benchmark1", c) - for i := 0; i < c.N; i++ { - time.Sleep(s.sleep) - } -} - -func (s *FixtureHelper) Benchmark2(c *check.C) { - s.trace("Benchmark2", c) - c.SetBytes(1024) - for i := 0; i < c.N; i++ { - time.Sleep(s.sleep) - } -} - -func (s *FixtureHelper) Benchmark3(c *check.C) { - var x []int64 - s.trace("Benchmark3", c) - for i := 0; i < c.N; i++ { - time.Sleep(s.sleep) - x = make([]int64, 5) - _ = x - } -} - -// ----------------------------------------------------------------------- -// Helper which checks the state of the test and ensures that it matches -// the given expectations. Depends on c.Errorf() working, so shouldn't -// be used to test this one function. - -type expectedState struct { - name string - result interface{} - failed bool - log string -} - -// 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) { - failed := c.Failed() - c.Succeed() - log := c.GetTestLog() - matched, matchError := regexp.MatchString("^"+expected.log+"$", log) - if matchError != nil { - c.Errorf("Error in matching expression used in testing %s", - expected.name) - } else if !matched { - c.Errorf("%s logged:\n----------\n%s----------\n\nExpected:\n----------\n%s\n----------", - expected.name, log, expected.log) - } - if result != expected.result { - c.Errorf("%s returned %#v rather than %#v", - expected.name, result, expected.result) - } - if failed != expected.failed { - if failed { - c.Errorf("%s has failed when it shouldn't", expected.name) - } else { - c.Errorf("%s has not failed when it should", expected.name) - } - } -} diff --git a/Godeps/_workspace/src/gopkg.in/check.v1/checkers_test.go b/Godeps/_workspace/src/gopkg.in/check.v1/checkers_test.go deleted file mode 100644 index 5c6974746..000000000 --- a/Godeps/_workspace/src/gopkg.in/check.v1/checkers_test.go +++ /dev/null @@ -1,272 +0,0 @@ -package check_test - -import ( - "errors" - "gopkg.in/check.v1" - "reflect" - "runtime" -) - -type CheckersS struct{} - -var _ = check.Suite(&CheckersS{}) - -func testInfo(c *check.C, checker check.Checker, name string, paramNames []string) { - info := checker.Info() - if info.Name != name { - c.Fatalf("Got name %s, expected %s", info.Name, name) - } - if !reflect.DeepEqual(info.Params, paramNames) { - c.Fatalf("Got param names %#v, expected %#v", info.Params, paramNames) - } -} - -func testCheck(c *check.C, checker check.Checker, result bool, error string, params ...interface{}) ([]interface{}, []string) { - info := checker.Info() - if len(params) != len(info.Params) { - c.Fatalf("unexpected param count in test; expected %d got %d", len(info.Params), len(params)) - } - names := append([]string{}, info.Params...) - result_, error_ := checker.Check(params, names) - if result_ != result || error_ != error { - c.Fatalf("%s.Check(%#v) returned (%#v, %#v) rather than (%#v, %#v)", - info.Name, params, result_, error_, result, error) - } - return params, names -} - -func (s *CheckersS) TestComment(c *check.C) { - bug := check.Commentf("a %d bc", 42) - comment := bug.CheckCommentString() - if comment != "a 42 bc" { - c.Fatalf("Commentf returned %#v", comment) - } -} - -func (s *CheckersS) TestIsNil(c *check.C) { - testInfo(c, check.IsNil, "IsNil", []string{"value"}) - - testCheck(c, check.IsNil, true, "", nil) - testCheck(c, check.IsNil, false, "", "a") - - testCheck(c, check.IsNil, true, "", (chan int)(nil)) - testCheck(c, check.IsNil, false, "", make(chan int)) - testCheck(c, check.IsNil, true, "", (error)(nil)) - testCheck(c, check.IsNil, false, "", errors.New("")) - testCheck(c, check.IsNil, true, "", ([]int)(nil)) - testCheck(c, check.IsNil, false, "", make([]int, 1)) - testCheck(c, check.IsNil, false, "", int(0)) -} - -func (s *CheckersS) TestNotNil(c *check.C) { - testInfo(c, check.NotNil, "NotNil", []string{"value"}) - - testCheck(c, check.NotNil, false, "", nil) - testCheck(c, check.NotNil, true, "", "a") - - testCheck(c, check.NotNil, false, "", (chan int)(nil)) - testCheck(c, check.NotNil, true, "", make(chan int)) - testCheck(c, check.NotNil, false, "", (error)(nil)) - testCheck(c, check.NotNil, true, "", errors.New("")) - testCheck(c, check.NotNil, false, "", ([]int)(nil)) - testCheck(c, check.NotNil, true, "", make([]int, 1)) -} - -func (s *CheckersS) TestNot(c *check.C) { - testInfo(c, check.Not(check.IsNil), "Not(IsNil)", []string{"value"}) - - testCheck(c, check.Not(check.IsNil), false, "", nil) - testCheck(c, check.Not(check.IsNil), true, "", "a") -} - -type simpleStruct struct { - i int -} - -func (s *CheckersS) TestEquals(c *check.C) { - testInfo(c, check.Equals, "Equals", []string{"obtained", "expected"}) - - // The simplest. - testCheck(c, check.Equals, true, "", 42, 42) - testCheck(c, check.Equals, false, "", 42, 43) - - // Different native types. - testCheck(c, check.Equals, false, "", int32(42), int64(42)) - - // With nil. - testCheck(c, check.Equals, false, "", 42, nil) - - // Slices - testCheck(c, check.Equals, false, "runtime error: comparing uncomparable type []uint8", []byte{1, 2}, []byte{1, 2}) - - // Struct values - testCheck(c, check.Equals, true, "", simpleStruct{1}, simpleStruct{1}) - testCheck(c, check.Equals, false, "", simpleStruct{1}, simpleStruct{2}) - - // Struct pointers - testCheck(c, check.Equals, false, "", &simpleStruct{1}, &simpleStruct{1}) - testCheck(c, check.Equals, false, "", &simpleStruct{1}, &simpleStruct{2}) -} - -func (s *CheckersS) TestDeepEquals(c *check.C) { - testInfo(c, check.DeepEquals, "DeepEquals", []string{"obtained", "expected"}) - - // The simplest. - testCheck(c, check.DeepEquals, true, "", 42, 42) - testCheck(c, check.DeepEquals, false, "", 42, 43) - - // Different native types. - testCheck(c, check.DeepEquals, false, "", int32(42), int64(42)) - - // With nil. - testCheck(c, check.DeepEquals, false, "", 42, nil) - - // Slices - testCheck(c, check.DeepEquals, true, "", []byte{1, 2}, []byte{1, 2}) - testCheck(c, check.DeepEquals, false, "", []byte{1, 2}, []byte{1, 3}) - - // Struct values - testCheck(c, check.DeepEquals, true, "", simpleStruct{1}, simpleStruct{1}) - testCheck(c, check.DeepEquals, false, "", simpleStruct{1}, simpleStruct{2}) - - // Struct pointers - testCheck(c, check.DeepEquals, true, "", &simpleStruct{1}, &simpleStruct{1}) - testCheck(c, check.DeepEquals, false, "", &simpleStruct{1}, &simpleStruct{2}) -} - -func (s *CheckersS) TestHasLen(c *check.C) { - testInfo(c, check.HasLen, "HasLen", []string{"obtained", "n"}) - - testCheck(c, check.HasLen, true, "", "abcd", 4) - testCheck(c, check.HasLen, true, "", []int{1, 2}, 2) - testCheck(c, check.HasLen, false, "", []int{1, 2}, 3) - - testCheck(c, check.HasLen, false, "n must be an int", []int{1, 2}, "2") - testCheck(c, check.HasLen, false, "obtained value type has no length", nil, 2) -} - -func (s *CheckersS) TestErrorMatches(c *check.C) { - testInfo(c, check.ErrorMatches, "ErrorMatches", []string{"value", "regex"}) - - testCheck(c, check.ErrorMatches, false, "Error value is nil", nil, "some error") - testCheck(c, check.ErrorMatches, false, "Value is not an error", 1, "some error") - testCheck(c, check.ErrorMatches, true, "", errors.New("some error"), "some error") - testCheck(c, check.ErrorMatches, true, "", errors.New("some error"), "so.*or") - - // Verify params mutation - params, names := testCheck(c, check.ErrorMatches, false, "", errors.New("some error"), "other error") - c.Assert(params[0], check.Equals, "some error") - c.Assert(names[0], check.Equals, "error") -} - -func (s *CheckersS) TestMatches(c *check.C) { - testInfo(c, check.Matches, "Matches", []string{"value", "regex"}) - - // Simple matching - testCheck(c, check.Matches, true, "", "abc", "abc") - testCheck(c, check.Matches, true, "", "abc", "a.c") - - // Must match fully - testCheck(c, check.Matches, false, "", "abc", "ab") - testCheck(c, check.Matches, false, "", "abc", "bc") - - // String()-enabled values accepted - testCheck(c, check.Matches, true, "", reflect.ValueOf("abc"), "a.c") - testCheck(c, check.Matches, false, "", reflect.ValueOf("abc"), "a.d") - - // Some error conditions. - testCheck(c, check.Matches, false, "Obtained value is not a string and has no .String()", 1, "a.c") - testCheck(c, check.Matches, false, "Can't compile regex: error parsing regexp: missing closing ]: `[c$`", "abc", "a[c") -} - -func (s *CheckersS) TestPanics(c *check.C) { - testInfo(c, check.Panics, "Panics", []string{"function", "expected"}) - - // Some errors. - testCheck(c, check.Panics, false, "Function has not panicked", func() bool { return false }, "BOOM") - testCheck(c, check.Panics, false, "Function must take zero arguments", 1, "BOOM") - - // Plain strings. - testCheck(c, check.Panics, true, "", func() { panic("BOOM") }, "BOOM") - testCheck(c, check.Panics, false, "", func() { panic("KABOOM") }, "BOOM") - testCheck(c, check.Panics, true, "", func() bool { panic("BOOM") }, "BOOM") - - // Error values. - testCheck(c, check.Panics, true, "", func() { panic(errors.New("BOOM")) }, errors.New("BOOM")) - testCheck(c, check.Panics, false, "", func() { panic(errors.New("KABOOM")) }, errors.New("BOOM")) - - type deep struct{ i int } - // Deep value - testCheck(c, check.Panics, true, "", func() { panic(&deep{99}) }, &deep{99}) - - // Verify params/names mutation - params, names := testCheck(c, check.Panics, false, "", func() { panic(errors.New("KABOOM")) }, errors.New("BOOM")) - c.Assert(params[0], check.ErrorMatches, "KABOOM") - c.Assert(names[0], check.Equals, "panic") - - // Verify a nil panic - testCheck(c, check.Panics, true, "", func() { panic(nil) }, nil) - testCheck(c, check.Panics, false, "", func() { panic(nil) }, "NOPE") -} - -func (s *CheckersS) TestPanicMatches(c *check.C) { - testInfo(c, check.PanicMatches, "PanicMatches", []string{"function", "expected"}) - - // Error matching. - testCheck(c, check.PanicMatches, true, "", func() { panic(errors.New("BOOM")) }, "BO.M") - testCheck(c, check.PanicMatches, false, "", func() { panic(errors.New("KABOOM")) }, "BO.M") - - // Some errors. - testCheck(c, check.PanicMatches, false, "Function has not panicked", func() bool { return false }, "BOOM") - testCheck(c, check.PanicMatches, false, "Function must take zero arguments", 1, "BOOM") - - // Plain strings. - testCheck(c, check.PanicMatches, true, "", func() { panic("BOOM") }, "BO.M") - testCheck(c, check.PanicMatches, false, "", func() { panic("KABOOM") }, "BOOM") - testCheck(c, check.PanicMatches, true, "", func() bool { panic("BOOM") }, "BO.M") - - // Verify params/names mutation - params, names := testCheck(c, check.PanicMatches, false, "", func() { panic(errors.New("KABOOM")) }, "BOOM") - c.Assert(params[0], check.Equals, "KABOOM") - c.Assert(names[0], check.Equals, "panic") - - // Verify a nil panic - testCheck(c, check.PanicMatches, false, "Panic value is not a string or an error", func() { panic(nil) }, "") -} - -func (s *CheckersS) TestFitsTypeOf(c *check.C) { - testInfo(c, check.FitsTypeOf, "FitsTypeOf", []string{"obtained", "sample"}) - - // Basic types - testCheck(c, check.FitsTypeOf, true, "", 1, 0) - testCheck(c, check.FitsTypeOf, false, "", 1, int64(0)) - - // Aliases - testCheck(c, check.FitsTypeOf, false, "", 1, errors.New("")) - testCheck(c, check.FitsTypeOf, false, "", "error", errors.New("")) - testCheck(c, check.FitsTypeOf, true, "", errors.New("error"), errors.New("")) - - // Structures - testCheck(c, check.FitsTypeOf, false, "", 1, simpleStruct{}) - testCheck(c, check.FitsTypeOf, false, "", simpleStruct{42}, &simpleStruct{}) - testCheck(c, check.FitsTypeOf, true, "", simpleStruct{42}, simpleStruct{}) - testCheck(c, check.FitsTypeOf, true, "", &simpleStruct{42}, &simpleStruct{}) - - // Some bad values - testCheck(c, check.FitsTypeOf, false, "Invalid sample value", 1, interface{}(nil)) - testCheck(c, check.FitsTypeOf, false, "", interface{}(nil), 0) -} - -func (s *CheckersS) TestImplements(c *check.C) { - testInfo(c, check.Implements, "Implements", []string{"obtained", "ifaceptr"}) - - var e error - var re runtime.Error - testCheck(c, check.Implements, true, "", errors.New(""), &e) - testCheck(c, check.Implements, false, "", errors.New(""), &re) - - // Some bad values - testCheck(c, check.Implements, false, "ifaceptr should be a pointer to an interface variable", 0, errors.New("")) - testCheck(c, check.Implements, false, "ifaceptr should be a pointer to an interface variable", 0, interface{}(nil)) - testCheck(c, check.Implements, false, "", interface{}(nil), &e) -} diff --git a/Godeps/_workspace/src/gopkg.in/check.v1/export_test.go b/Godeps/_workspace/src/gopkg.in/check.v1/export_test.go deleted file mode 100644 index 0e6cfe0f2..000000000 --- a/Godeps/_workspace/src/gopkg.in/check.v1/export_test.go +++ /dev/null @@ -1,9 +0,0 @@ -package check - -func PrintLine(filename string, line int) (string, error) { - return printLine(filename, line) -} - -func Indent(s, with string) string { - return indent(s, with) -} diff --git a/Godeps/_workspace/src/gopkg.in/check.v1/fixture_test.go b/Godeps/_workspace/src/gopkg.in/check.v1/fixture_test.go deleted file mode 100644 index 2bff9e163..000000000 --- a/Godeps/_workspace/src/gopkg.in/check.v1/fixture_test.go +++ /dev/null @@ -1,484 +0,0 @@ -// Tests for the behavior of the test fixture system. - -package check_test - -import ( - . "gopkg.in/check.v1" -) - -// ----------------------------------------------------------------------- -// Fixture test suite. - -type FixtureS struct{} - -var fixtureS = Suite(&FixtureS{}) - -func (s *FixtureS) TestCountSuite(c *C) { - suitesRun += 1 -} - -// ----------------------------------------------------------------------- -// Basic fixture ordering verification. - -func (s *FixtureS) TestOrder(c *C) { - helper := FixtureHelper{} - Run(&helper, nil) - c.Check(helper.calls[0], Equals, "SetUpSuite") - c.Check(helper.calls[1], Equals, "SetUpTest") - c.Check(helper.calls[2], Equals, "Test1") - c.Check(helper.calls[3], Equals, "TearDownTest") - c.Check(helper.calls[4], Equals, "SetUpTest") - c.Check(helper.calls[5], Equals, "Test2") - c.Check(helper.calls[6], Equals, "TearDownTest") - c.Check(helper.calls[7], Equals, "TearDownSuite") - c.Check(len(helper.calls), Equals, 8) -} - -// ----------------------------------------------------------------------- -// Check the behavior when panics occur within tests and fixtures. - -func (s *FixtureS) TestPanicOnTest(c *C) { - helper := FixtureHelper{panicOn: "Test1"} - output := String{} - Run(&helper, &RunConf{Output: &output}) - c.Check(helper.calls[0], Equals, "SetUpSuite") - c.Check(helper.calls[1], Equals, "SetUpTest") - c.Check(helper.calls[2], Equals, "Test1") - c.Check(helper.calls[3], Equals, "TearDownTest") - c.Check(helper.calls[4], Equals, "SetUpTest") - c.Check(helper.calls[5], Equals, "Test2") - c.Check(helper.calls[6], Equals, "TearDownTest") - c.Check(helper.calls[7], Equals, "TearDownSuite") - c.Check(len(helper.calls), Equals, 8) - - expected := "^\n-+\n" + - "PANIC: check_test\\.go:[0-9]+: FixtureHelper.Test1\n\n" + - "\\.\\.\\. Panic: Test1 \\(PC=[xA-F0-9]+\\)\n\n" + - ".+:[0-9]+\n" + - " in (go)?panic\n" + - ".*check_test.go:[0-9]+\n" + - " in FixtureHelper.trace\n" + - ".*check_test.go:[0-9]+\n" + - " in FixtureHelper.Test1\n" + - "(.|\n)*$" - - c.Check(output.value, Matches, expected) -} - -func (s *FixtureS) TestPanicOnSetUpTest(c *C) { - helper := FixtureHelper{panicOn: "SetUpTest"} - output := String{} - Run(&helper, &RunConf{Output: &output}) - c.Check(helper.calls[0], Equals, "SetUpSuite") - c.Check(helper.calls[1], Equals, "SetUpTest") - c.Check(helper.calls[2], Equals, "TearDownTest") - c.Check(helper.calls[3], Equals, "TearDownSuite") - c.Check(len(helper.calls), Equals, 4) - - expected := "^\n-+\n" + - "PANIC: check_test\\.go:[0-9]+: " + - "FixtureHelper\\.SetUpTest\n\n" + - "\\.\\.\\. Panic: SetUpTest \\(PC=[xA-F0-9]+\\)\n\n" + - ".+:[0-9]+\n" + - " in (go)?panic\n" + - ".*check_test.go:[0-9]+\n" + - " in FixtureHelper.trace\n" + - ".*check_test.go:[0-9]+\n" + - " in FixtureHelper.SetUpTest\n" + - "(.|\n)*" + - "\n-+\n" + - "PANIC: check_test\\.go:[0-9]+: " + - "FixtureHelper\\.Test1\n\n" + - "\\.\\.\\. Panic: Fixture has panicked " + - "\\(see related PANIC\\)\n$" - - c.Check(output.value, Matches, expected) -} - -func (s *FixtureS) TestPanicOnTearDownTest(c *C) { - helper := FixtureHelper{panicOn: "TearDownTest"} - output := String{} - Run(&helper, &RunConf{Output: &output}) - c.Check(helper.calls[0], Equals, "SetUpSuite") - c.Check(helper.calls[1], Equals, "SetUpTest") - c.Check(helper.calls[2], Equals, "Test1") - c.Check(helper.calls[3], Equals, "TearDownTest") - c.Check(helper.calls[4], Equals, "TearDownSuite") - c.Check(len(helper.calls), Equals, 5) - - expected := "^\n-+\n" + - "PANIC: check_test\\.go:[0-9]+: " + - "FixtureHelper.TearDownTest\n\n" + - "\\.\\.\\. Panic: TearDownTest \\(PC=[xA-F0-9]+\\)\n\n" + - ".+:[0-9]+\n" + - " in (go)?panic\n" + - ".*check_test.go:[0-9]+\n" + - " in FixtureHelper.trace\n" + - ".*check_test.go:[0-9]+\n" + - " in FixtureHelper.TearDownTest\n" + - "(.|\n)*" + - "\n-+\n" + - "PANIC: check_test\\.go:[0-9]+: " + - "FixtureHelper\\.Test1\n\n" + - "\\.\\.\\. Panic: Fixture has panicked " + - "\\(see related PANIC\\)\n$" - - c.Check(output.value, Matches, expected) -} - -func (s *FixtureS) TestPanicOnSetUpSuite(c *C) { - helper := FixtureHelper{panicOn: "SetUpSuite"} - output := String{} - Run(&helper, &RunConf{Output: &output}) - c.Check(helper.calls[0], Equals, "SetUpSuite") - c.Check(helper.calls[1], Equals, "TearDownSuite") - c.Check(len(helper.calls), Equals, 2) - - expected := "^\n-+\n" + - "PANIC: check_test\\.go:[0-9]+: " + - "FixtureHelper.SetUpSuite\n\n" + - "\\.\\.\\. Panic: SetUpSuite \\(PC=[xA-F0-9]+\\)\n\n" + - ".+:[0-9]+\n" + - " in (go)?panic\n" + - ".*check_test.go:[0-9]+\n" + - " in FixtureHelper.trace\n" + - ".*check_test.go:[0-9]+\n" + - " in FixtureHelper.SetUpSuite\n" + - "(.|\n)*$" - - c.Check(output.value, Matches, expected) -} - -func (s *FixtureS) TestPanicOnTearDownSuite(c *C) { - helper := FixtureHelper{panicOn: "TearDownSuite"} - output := String{} - Run(&helper, &RunConf{Output: &output}) - c.Check(helper.calls[0], Equals, "SetUpSuite") - c.Check(helper.calls[1], Equals, "SetUpTest") - c.Check(helper.calls[2], Equals, "Test1") - c.Check(helper.calls[3], Equals, "TearDownTest") - c.Check(helper.calls[4], Equals, "SetUpTest") - c.Check(helper.calls[5], Equals, "Test2") - c.Check(helper.calls[6], Equals, "TearDownTest") - c.Check(helper.calls[7], Equals, "TearDownSuite") - c.Check(len(helper.calls), Equals, 8) - - expected := "^\n-+\n" + - "PANIC: check_test\\.go:[0-9]+: " + - "FixtureHelper.TearDownSuite\n\n" + - "\\.\\.\\. Panic: TearDownSuite \\(PC=[xA-F0-9]+\\)\n\n" + - ".+:[0-9]+\n" + - " in (go)?panic\n" + - ".*check_test.go:[0-9]+\n" + - " in FixtureHelper.trace\n" + - ".*check_test.go:[0-9]+\n" + - " in FixtureHelper.TearDownSuite\n" + - "(.|\n)*$" - - c.Check(output.value, Matches, expected) -} - -// ----------------------------------------------------------------------- -// A wrong argument on a test or fixture will produce a nice error. - -func (s *FixtureS) TestPanicOnWrongTestArg(c *C) { - helper := WrongTestArgHelper{} - output := String{} - Run(&helper, &RunConf{Output: &output}) - c.Check(helper.calls[0], Equals, "SetUpSuite") - c.Check(helper.calls[1], Equals, "SetUpTest") - c.Check(helper.calls[2], Equals, "TearDownTest") - c.Check(helper.calls[3], Equals, "SetUpTest") - c.Check(helper.calls[4], Equals, "Test2") - c.Check(helper.calls[5], Equals, "TearDownTest") - c.Check(helper.calls[6], Equals, "TearDownSuite") - c.Check(len(helper.calls), Equals, 7) - - expected := "^\n-+\n" + - "PANIC: fixture_test\\.go:[0-9]+: " + - "WrongTestArgHelper\\.Test1\n\n" + - "\\.\\.\\. Panic: WrongTestArgHelper\\.Test1 argument " + - "should be \\*check\\.C\n" - - c.Check(output.value, Matches, expected) -} - -func (s *FixtureS) TestPanicOnWrongSetUpTestArg(c *C) { - helper := WrongSetUpTestArgHelper{} - output := String{} - Run(&helper, &RunConf{Output: &output}) - c.Check(len(helper.calls), Equals, 0) - - expected := - "^\n-+\n" + - "PANIC: fixture_test\\.go:[0-9]+: " + - "WrongSetUpTestArgHelper\\.SetUpTest\n\n" + - "\\.\\.\\. Panic: WrongSetUpTestArgHelper\\.SetUpTest argument " + - "should be \\*check\\.C\n" - - c.Check(output.value, Matches, expected) -} - -func (s *FixtureS) TestPanicOnWrongSetUpSuiteArg(c *C) { - helper := WrongSetUpSuiteArgHelper{} - output := String{} - Run(&helper, &RunConf{Output: &output}) - c.Check(len(helper.calls), Equals, 0) - - expected := - "^\n-+\n" + - "PANIC: fixture_test\\.go:[0-9]+: " + - "WrongSetUpSuiteArgHelper\\.SetUpSuite\n\n" + - "\\.\\.\\. Panic: WrongSetUpSuiteArgHelper\\.SetUpSuite argument " + - "should be \\*check\\.C\n" - - c.Check(output.value, Matches, expected) -} - -// ----------------------------------------------------------------------- -// Nice errors also when tests or fixture have wrong arg count. - -func (s *FixtureS) TestPanicOnWrongTestArgCount(c *C) { - helper := WrongTestArgCountHelper{} - output := String{} - Run(&helper, &RunConf{Output: &output}) - c.Check(helper.calls[0], Equals, "SetUpSuite") - c.Check(helper.calls[1], Equals, "SetUpTest") - c.Check(helper.calls[2], Equals, "TearDownTest") - c.Check(helper.calls[3], Equals, "SetUpTest") - c.Check(helper.calls[4], Equals, "Test2") - c.Check(helper.calls[5], Equals, "TearDownTest") - c.Check(helper.calls[6], Equals, "TearDownSuite") - c.Check(len(helper.calls), Equals, 7) - - expected := "^\n-+\n" + - "PANIC: fixture_test\\.go:[0-9]+: " + - "WrongTestArgCountHelper\\.Test1\n\n" + - "\\.\\.\\. Panic: WrongTestArgCountHelper\\.Test1 argument " + - "should be \\*check\\.C\n" - - c.Check(output.value, Matches, expected) -} - -func (s *FixtureS) TestPanicOnWrongSetUpTestArgCount(c *C) { - helper := WrongSetUpTestArgCountHelper{} - output := String{} - Run(&helper, &RunConf{Output: &output}) - c.Check(len(helper.calls), Equals, 0) - - expected := - "^\n-+\n" + - "PANIC: fixture_test\\.go:[0-9]+: " + - "WrongSetUpTestArgCountHelper\\.SetUpTest\n\n" + - "\\.\\.\\. Panic: WrongSetUpTestArgCountHelper\\.SetUpTest argument " + - "should be \\*check\\.C\n" - - c.Check(output.value, Matches, expected) -} - -func (s *FixtureS) TestPanicOnWrongSetUpSuiteArgCount(c *C) { - helper := WrongSetUpSuiteArgCountHelper{} - output := String{} - Run(&helper, &RunConf{Output: &output}) - c.Check(len(helper.calls), Equals, 0) - - expected := - "^\n-+\n" + - "PANIC: fixture_test\\.go:[0-9]+: " + - "WrongSetUpSuiteArgCountHelper\\.SetUpSuite\n\n" + - "\\.\\.\\. Panic: WrongSetUpSuiteArgCountHelper" + - "\\.SetUpSuite argument should be \\*check\\.C\n" - - c.Check(output.value, Matches, expected) -} - -// ----------------------------------------------------------------------- -// Helper test suites with wrong function arguments. - -type WrongTestArgHelper struct { - FixtureHelper -} - -func (s *WrongTestArgHelper) Test1(t int) { -} - -type WrongSetUpTestArgHelper struct { - FixtureHelper -} - -func (s *WrongSetUpTestArgHelper) SetUpTest(t int) { -} - -type WrongSetUpSuiteArgHelper struct { - FixtureHelper -} - -func (s *WrongSetUpSuiteArgHelper) SetUpSuite(t int) { -} - -type WrongTestArgCountHelper struct { - FixtureHelper -} - -func (s *WrongTestArgCountHelper) Test1(c *C, i int) { -} - -type WrongSetUpTestArgCountHelper struct { - FixtureHelper -} - -func (s *WrongSetUpTestArgCountHelper) SetUpTest(c *C, i int) { -} - -type WrongSetUpSuiteArgCountHelper struct { - FixtureHelper -} - -func (s *WrongSetUpSuiteArgCountHelper) SetUpSuite(c *C, i int) { -} - -// ----------------------------------------------------------------------- -// Ensure fixture doesn't run without tests. - -type NoTestsHelper struct { - hasRun bool -} - -func (s *NoTestsHelper) SetUpSuite(c *C) { - s.hasRun = true -} - -func (s *NoTestsHelper) TearDownSuite(c *C) { - s.hasRun = true -} - -func (s *FixtureS) TestFixtureDoesntRunWithoutTests(c *C) { - helper := NoTestsHelper{} - output := String{} - Run(&helper, &RunConf{Output: &output}) - c.Check(helper.hasRun, Equals, false) -} - -// ----------------------------------------------------------------------- -// Verify that checks and assertions work correctly inside the fixture. - -type FixtureCheckHelper struct { - fail string - completed bool -} - -func (s *FixtureCheckHelper) SetUpSuite(c *C) { - switch s.fail { - case "SetUpSuiteAssert": - c.Assert(false, Equals, true) - case "SetUpSuiteCheck": - c.Check(false, Equals, true) - } - s.completed = true -} - -func (s *FixtureCheckHelper) SetUpTest(c *C) { - switch s.fail { - case "SetUpTestAssert": - c.Assert(false, Equals, true) - case "SetUpTestCheck": - c.Check(false, Equals, true) - } - s.completed = true -} - -func (s *FixtureCheckHelper) Test(c *C) { - // Do nothing. -} - -func (s *FixtureS) TestSetUpSuiteCheck(c *C) { - helper := FixtureCheckHelper{fail: "SetUpSuiteCheck"} - output := String{} - Run(&helper, &RunConf{Output: &output}) - c.Assert(output.value, Matches, - "\n---+\n"+ - "FAIL: fixture_test\\.go:[0-9]+: "+ - "FixtureCheckHelper\\.SetUpSuite\n\n"+ - "fixture_test\\.go:[0-9]+:\n"+ - " c\\.Check\\(false, Equals, true\\)\n"+ - "\\.+ obtained bool = false\n"+ - "\\.+ expected bool = true\n\n") - c.Assert(helper.completed, Equals, true) -} - -func (s *FixtureS) TestSetUpSuiteAssert(c *C) { - helper := FixtureCheckHelper{fail: "SetUpSuiteAssert"} - output := String{} - Run(&helper, &RunConf{Output: &output}) - c.Assert(output.value, Matches, - "\n---+\n"+ - "FAIL: fixture_test\\.go:[0-9]+: "+ - "FixtureCheckHelper\\.SetUpSuite\n\n"+ - "fixture_test\\.go:[0-9]+:\n"+ - " c\\.Assert\\(false, Equals, true\\)\n"+ - "\\.+ obtained bool = false\n"+ - "\\.+ expected bool = true\n\n") - c.Assert(helper.completed, Equals, false) -} - -// ----------------------------------------------------------------------- -// Verify that logging within SetUpTest() persists within the test log itself. - -type FixtureLogHelper struct { - c *C -} - -func (s *FixtureLogHelper) SetUpTest(c *C) { - s.c = c - c.Log("1") -} - -func (s *FixtureLogHelper) Test(c *C) { - c.Log("2") - s.c.Log("3") - c.Log("4") - c.Fail() -} - -func (s *FixtureLogHelper) TearDownTest(c *C) { - s.c.Log("5") -} - -func (s *FixtureS) TestFixtureLogging(c *C) { - helper := FixtureLogHelper{} - output := String{} - Run(&helper, &RunConf{Output: &output}) - c.Assert(output.value, Matches, - "\n---+\n"+ - "FAIL: fixture_test\\.go:[0-9]+: "+ - "FixtureLogHelper\\.Test\n\n"+ - "1\n2\n3\n4\n5\n") -} - -// ----------------------------------------------------------------------- -// Skip() within fixture methods. - -func (s *FixtureS) TestSkipSuite(c *C) { - helper := FixtureHelper{skip: true, skipOnN: 0} - output := String{} - result := Run(&helper, &RunConf{Output: &output}) - c.Assert(output.value, Equals, "") - c.Assert(helper.calls[0], Equals, "SetUpSuite") - c.Assert(helper.calls[1], Equals, "TearDownSuite") - c.Assert(len(helper.calls), Equals, 2) - c.Assert(result.Skipped, Equals, 2) -} - -func (s *FixtureS) TestSkipTest(c *C) { - helper := FixtureHelper{skip: true, skipOnN: 1} - output := String{} - result := Run(&helper, &RunConf{Output: &output}) - c.Assert(helper.calls[0], Equals, "SetUpSuite") - c.Assert(helper.calls[1], Equals, "SetUpTest") - c.Assert(helper.calls[2], Equals, "SetUpTest") - c.Assert(helper.calls[3], Equals, "Test2") - c.Assert(helper.calls[4], Equals, "TearDownTest") - c.Assert(helper.calls[5], Equals, "TearDownSuite") - c.Assert(len(helper.calls), Equals, 6) - c.Assert(result.Skipped, Equals, 1) -} diff --git a/Godeps/_workspace/src/gopkg.in/check.v1/foundation_test.go b/Godeps/_workspace/src/gopkg.in/check.v1/foundation_test.go deleted file mode 100644 index 8ecf7915f..000000000 --- a/Godeps/_workspace/src/gopkg.in/check.v1/foundation_test.go +++ /dev/null @@ -1,335 +0,0 @@ -// These tests check that the foundations of gocheck are working properly. -// They already assume that fundamental failing is working already, though, -// since this was tested in bootstrap_test.go. Even then, some care may -// still have to be taken when using external functions, since they should -// of course not rely on functionality tested here. - -package check_test - -import ( - "fmt" - "gopkg.in/check.v1" - "log" - "os" - "regexp" - "strings" -) - -// ----------------------------------------------------------------------- -// Foundation test suite. - -type FoundationS struct{} - -var foundationS = check.Suite(&FoundationS{}) - -func (s *FoundationS) TestCountSuite(c *check.C) { - suitesRun += 1 -} - -func (s *FoundationS) TestErrorf(c *check.C) { - // Do not use checkState() here. It depends on Errorf() working. - expectedLog := fmt.Sprintf("foundation_test.go:%d:\n"+ - " c.Errorf(\"Error %%v!\", \"message\")\n"+ - "... Error: Error message!\n\n", - getMyLine()+1) - c.Errorf("Error %v!", "message") - failed := c.Failed() - c.Succeed() - if log := c.GetTestLog(); log != expectedLog { - c.Logf("Errorf() logged %#v rather than %#v", log, expectedLog) - c.Fail() - } - if !failed { - c.Logf("Errorf() didn't put the test in a failed state") - c.Fail() - } -} - -func (s *FoundationS) TestError(c *check.C) { - expectedLog := fmt.Sprintf("foundation_test.go:%d:\n"+ - " c\\.Error\\(\"Error \", \"message!\"\\)\n"+ - "\\.\\.\\. Error: Error message!\n\n", - getMyLine()+1) - c.Error("Error ", "message!") - checkState(c, nil, - &expectedState{ - name: "Error(`Error `, `message!`)", - failed: true, - log: expectedLog, - }) -} - -func (s *FoundationS) TestFailNow(c *check.C) { - defer (func() { - if !c.Failed() { - c.Error("FailNow() didn't fail the test") - } else { - c.Succeed() - if c.GetTestLog() != "" { - c.Error("Something got logged:\n" + c.GetTestLog()) - } - } - })() - - c.FailNow() - c.Log("FailNow() didn't stop the test") -} - -func (s *FoundationS) TestSucceedNow(c *check.C) { - defer (func() { - if c.Failed() { - c.Error("SucceedNow() didn't succeed the test") - } - if c.GetTestLog() != "" { - c.Error("Something got logged:\n" + c.GetTestLog()) - } - })() - - c.Fail() - c.SucceedNow() - c.Log("SucceedNow() didn't stop the test") -} - -func (s *FoundationS) TestFailureHeader(c *check.C) { - output := String{} - failHelper := FailHelper{} - check.Run(&failHelper, &check.RunConf{Output: &output}) - header := fmt.Sprintf(""+ - "\n-----------------------------------"+ - "-----------------------------------\n"+ - "FAIL: check_test.go:%d: FailHelper.TestLogAndFail\n", - failHelper.testLine) - if strings.Index(output.value, header) == -1 { - c.Errorf(""+ - "Failure didn't print a proper header.\n"+ - "... Got:\n%s... Expected something with:\n%s", - output.value, header) - } -} - -func (s *FoundationS) TestFatal(c *check.C) { - var line int - defer (func() { - if !c.Failed() { - c.Error("Fatal() didn't fail the test") - } else { - c.Succeed() - expected := fmt.Sprintf("foundation_test.go:%d:\n"+ - " c.Fatal(\"Die \", \"now!\")\n"+ - "... Error: Die now!\n\n", - line) - if c.GetTestLog() != expected { - c.Error("Incorrect log:", c.GetTestLog()) - } - } - })() - - line = getMyLine() + 1 - c.Fatal("Die ", "now!") - c.Log("Fatal() didn't stop the test") -} - -func (s *FoundationS) TestFatalf(c *check.C) { - var line int - defer (func() { - if !c.Failed() { - c.Error("Fatalf() didn't fail the test") - } else { - c.Succeed() - expected := fmt.Sprintf("foundation_test.go:%d:\n"+ - " c.Fatalf(\"Die %%s!\", \"now\")\n"+ - "... Error: Die now!\n\n", - line) - if c.GetTestLog() != expected { - c.Error("Incorrect log:", c.GetTestLog()) - } - } - })() - - line = getMyLine() + 1 - c.Fatalf("Die %s!", "now") - c.Log("Fatalf() didn't stop the test") -} - -func (s *FoundationS) TestCallerLoggingInsideTest(c *check.C) { - log := fmt.Sprintf(""+ - "foundation_test.go:%d:\n"+ - " result := c.Check\\(10, check.Equals, 20\\)\n"+ - "\\.\\.\\. obtained int = 10\n"+ - "\\.\\.\\. expected int = 20\n\n", - getMyLine()+1) - result := c.Check(10, check.Equals, 20) - checkState(c, result, - &expectedState{ - name: "Check(10, Equals, 20)", - result: false, - failed: true, - log: log, - }) -} - -func (s *FoundationS) TestCallerLoggingInDifferentFile(c *check.C) { - result, line := checkEqualWrapper(c, 10, 20) - testLine := getMyLine() - 1 - log := fmt.Sprintf(""+ - "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"+ - "\\.\\.\\. obtained int = 10\n"+ - "\\.\\.\\. expected int = 20\n\n", - testLine, line) - checkState(c, result, - &expectedState{ - name: "Check(10, Equals, 20)", - result: false, - failed: true, - log: log, - }) -} - -// ----------------------------------------------------------------------- -// ExpectFailure() inverts the logic of failure. - -type ExpectFailureSucceedHelper struct{} - -func (s *ExpectFailureSucceedHelper) TestSucceed(c *check.C) { - c.ExpectFailure("It booms!") - c.Error("Boom!") -} - -type ExpectFailureFailHelper struct{} - -func (s *ExpectFailureFailHelper) TestFail(c *check.C) { - c.ExpectFailure("Bug #XYZ") -} - -func (s *FoundationS) TestExpectFailureFail(c *check.C) { - helper := ExpectFailureFailHelper{} - output := String{} - result := check.Run(&helper, &check.RunConf{Output: &output}) - - expected := "" + - "^\n-+\n" + - "FAIL: foundation_test\\.go:[0-9]+:" + - " ExpectFailureFailHelper\\.TestFail\n\n" + - "\\.\\.\\. Error: Test succeeded, but was expected to fail\n" + - "\\.\\.\\. Reason: Bug #XYZ\n$" - - matched, err := regexp.MatchString(expected, output.value) - if err != nil { - c.Error("Bad expression: ", expected) - } else if !matched { - c.Error("ExpectFailure() didn't log properly:\n", output.value) - } - - c.Assert(result.ExpectedFailures, check.Equals, 0) -} - -func (s *FoundationS) TestExpectFailureSucceed(c *check.C) { - helper := ExpectFailureSucceedHelper{} - output := String{} - result := check.Run(&helper, &check.RunConf{Output: &output}) - - c.Assert(output.value, check.Equals, "") - c.Assert(result.ExpectedFailures, check.Equals, 1) -} - -func (s *FoundationS) TestExpectFailureSucceedVerbose(c *check.C) { - helper := ExpectFailureSucceedHelper{} - output := String{} - result := check.Run(&helper, &check.RunConf{Output: &output, Verbose: true}) - - expected := "" + - "FAIL EXPECTED: foundation_test\\.go:[0-9]+:" + - " ExpectFailureSucceedHelper\\.TestSucceed \\(It booms!\\)\t *[.0-9]+s\n" - - matched, err := regexp.MatchString(expected, output.value) - if err != nil { - c.Error("Bad expression: ", expected) - } else if !matched { - c.Error("ExpectFailure() didn't log properly:\n", output.value) - } - - c.Assert(result.ExpectedFailures, check.Equals, 1) -} - -// ----------------------------------------------------------------------- -// Skip() allows stopping a test without positive/negative results. - -type SkipTestHelper struct{} - -func (s *SkipTestHelper) TestFail(c *check.C) { - c.Skip("Wrong platform or whatever") - c.Error("Boom!") -} - -func (s *FoundationS) TestSkip(c *check.C) { - helper := SkipTestHelper{} - output := String{} - check.Run(&helper, &check.RunConf{Output: &output}) - - if output.value != "" { - c.Error("Skip() logged something:\n", output.value) - } -} - -func (s *FoundationS) TestSkipVerbose(c *check.C) { - helper := SkipTestHelper{} - output := String{} - check.Run(&helper, &check.RunConf{Output: &output, Verbose: true}) - - expected := "SKIP: foundation_test\\.go:[0-9]+: SkipTestHelper\\.TestFail" + - " \\(Wrong platform or whatever\\)" - matched, err := regexp.MatchString(expected, output.value) - if err != nil { - c.Error("Bad expression: ", expected) - } else if !matched { - c.Error("Skip() didn't log properly:\n", output.value) - } -} - -// ----------------------------------------------------------------------- -// Check minimum *log.Logger interface provided by *check.C. - -type minLogger interface { - Output(calldepth int, s string) error -} - -func (s *BootstrapS) TestMinLogger(c *check.C) { - var logger minLogger - logger = log.New(os.Stderr, "", 0) - logger = c - logger.Output(0, "Hello there") - expected := `\[LOG\] [0-9]+:[0-9][0-9]\.[0-9][0-9][0-9] +Hello there\n` - output := c.GetTestLog() - c.Assert(output, check.Matches, expected) -} - -// ----------------------------------------------------------------------- -// Ensure that suites with embedded types are working fine, including the -// the workaround for issue 906. - -type EmbeddedInternalS struct { - called bool -} - -type EmbeddedS struct { - EmbeddedInternalS -} - -var embeddedS = check.Suite(&EmbeddedS{}) - -func (s *EmbeddedS) TestCountSuite(c *check.C) { - suitesRun += 1 -} - -func (s *EmbeddedInternalS) TestMethod(c *check.C) { - c.Error("TestMethod() of the embedded type was called!?") -} - -func (s *EmbeddedS) TestMethod(c *check.C) { - // http://code.google.com/p/go/issues/detail?id=906 - c.Check(s.called, check.Equals, false) // Go issue 906 is affecting the runner? - s.called = true -} diff --git a/Godeps/_workspace/src/gopkg.in/check.v1/helpers.go b/Godeps/_workspace/src/gopkg.in/check.v1/helpers.go index 4b6c26da4..58a733b50 100644 --- a/Godeps/_workspace/src/gopkg.in/check.v1/helpers.go +++ b/Godeps/_workspace/src/gopkg.in/check.v1/helpers.go @@ -16,7 +16,7 @@ func (c *C) TestName() string { // Failed returns whether the currently running test has already failed. func (c *C) Failed() bool { - return c.status == failedSt + return c.status() == failedSt } // Fail marks the currently running test as failed. @@ -25,7 +25,7 @@ func (c *C) Failed() bool { // what went wrong. The higher level helper functions will fail the test // and do the logging properly. func (c *C) Fail() { - c.status = failedSt + c.setStatus(failedSt) } // FailNow marks the currently running test as failed and stops running it. @@ -40,7 +40,7 @@ func (c *C) FailNow() { // Succeed marks the currently running test as succeeded, undoing any // previous failures. func (c *C) Succeed() { - c.status = succeededSt + c.setStatus(succeededSt) } // SucceedNow marks the currently running test as succeeded, undoing any @@ -72,7 +72,7 @@ func (c *C) Skip(reason string) { panic("Missing reason why the test is being skipped") } c.reason = reason - c.status = skippedSt + c.setStatus(skippedSt) c.stopNow() } diff --git a/Godeps/_workspace/src/gopkg.in/check.v1/helpers_test.go b/Godeps/_workspace/src/gopkg.in/check.v1/helpers_test.go deleted file mode 100644 index 4baa656ba..000000000 --- a/Godeps/_workspace/src/gopkg.in/check.v1/helpers_test.go +++ /dev/null @@ -1,519 +0,0 @@ -// These tests verify the inner workings of the helper methods associated -// with check.T. - -package check_test - -import ( - "gopkg.in/check.v1" - "os" - "reflect" - "runtime" - "sync" -) - -var helpersS = check.Suite(&HelpersS{}) - -type HelpersS struct{} - -func (s *HelpersS) TestCountSuite(c *check.C) { - suitesRun += 1 -} - -// ----------------------------------------------------------------------- -// Fake checker and bug info to verify the behavior of Assert() and Check(). - -type MyChecker struct { - info *check.CheckerInfo - params []interface{} - names []string - result bool - error string -} - -func (checker *MyChecker) Info() *check.CheckerInfo { - if checker.info == nil { - return &check.CheckerInfo{Name: "MyChecker", Params: []string{"myobtained", "myexpected"}} - } - return checker.info -} - -func (checker *MyChecker) Check(params []interface{}, names []string) (bool, string) { - rparams := checker.params - rnames := checker.names - checker.params = append([]interface{}{}, params...) - checker.names = append([]string{}, names...) - if rparams != nil { - copy(params, rparams) - } - if rnames != nil { - copy(names, rnames) - } - return checker.result, checker.error -} - -type myCommentType string - -func (c myCommentType) CheckCommentString() string { - return string(c) -} - -func myComment(s string) myCommentType { - return myCommentType(s) -} - -// ----------------------------------------------------------------------- -// Ensure a real checker actually works fine. - -func (s *HelpersS) TestCheckerInterface(c *check.C) { - testHelperSuccess(c, "Check(1, Equals, 1)", true, func() interface{} { - return c.Check(1, check.Equals, 1) - }) -} - -// ----------------------------------------------------------------------- -// Tests for Check(), mostly the same as for Assert() following these. - -func (s *HelpersS) TestCheckSucceedWithExpected(c *check.C) { - checker := &MyChecker{result: true} - testHelperSuccess(c, "Check(1, checker, 2)", true, func() interface{} { - return c.Check(1, checker, 2) - }) - if !reflect.DeepEqual(checker.params, []interface{}{1, 2}) { - c.Fatalf("Bad params for check: %#v", checker.params) - } -} - -func (s *HelpersS) TestCheckSucceedWithoutExpected(c *check.C) { - checker := &MyChecker{result: true, info: &check.CheckerInfo{Params: []string{"myvalue"}}} - testHelperSuccess(c, "Check(1, checker)", true, func() interface{} { - return c.Check(1, checker) - }) - if !reflect.DeepEqual(checker.params, []interface{}{1}) { - c.Fatalf("Bad params for check: %#v", checker.params) - } -} - -func (s *HelpersS) TestCheckFailWithExpected(c *check.C) { - checker := &MyChecker{result: false} - log := "(?s)helpers_test\\.go:[0-9]+:.*\nhelpers_test\\.go:[0-9]+:\n" + - " return c\\.Check\\(1, checker, 2\\)\n" + - "\\.+ myobtained int = 1\n" + - "\\.+ myexpected int = 2\n\n" - testHelperFailure(c, "Check(1, checker, 2)", false, false, log, - func() interface{} { - return c.Check(1, checker, 2) - }) -} - -func (s *HelpersS) TestCheckFailWithExpectedAndComment(c *check.C) { - checker := &MyChecker{result: false} - log := "(?s)helpers_test\\.go:[0-9]+:.*\nhelpers_test\\.go:[0-9]+:\n" + - " return c\\.Check\\(1, checker, 2, myComment\\(\"Hello world!\"\\)\\)\n" + - "\\.+ myobtained int = 1\n" + - "\\.+ myexpected int = 2\n" + - "\\.+ Hello world!\n\n" - testHelperFailure(c, "Check(1, checker, 2, msg)", false, false, log, - func() interface{} { - return c.Check(1, checker, 2, myComment("Hello world!")) - }) -} - -func (s *HelpersS) TestCheckFailWithExpectedAndStaticComment(c *check.C) { - checker := &MyChecker{result: false} - log := "(?s)helpers_test\\.go:[0-9]+:.*\nhelpers_test\\.go:[0-9]+:\n" + - " // Nice leading comment\\.\n" + - " return c\\.Check\\(1, checker, 2\\) // Hello there\n" + - "\\.+ myobtained int = 1\n" + - "\\.+ myexpected int = 2\n\n" - testHelperFailure(c, "Check(1, checker, 2, msg)", false, false, log, - func() interface{} { - // Nice leading comment. - return c.Check(1, checker, 2) // Hello there - }) -} - -func (s *HelpersS) TestCheckFailWithoutExpected(c *check.C) { - checker := &MyChecker{result: false, info: &check.CheckerInfo{Params: []string{"myvalue"}}} - log := "(?s)helpers_test\\.go:[0-9]+:.*\nhelpers_test\\.go:[0-9]+:\n" + - " return c\\.Check\\(1, checker\\)\n" + - "\\.+ myvalue int = 1\n\n" - testHelperFailure(c, "Check(1, checker)", false, false, log, - func() interface{} { - return c.Check(1, checker) - }) -} - -func (s *HelpersS) TestCheckFailWithoutExpectedAndMessage(c *check.C) { - checker := &MyChecker{result: false, info: &check.CheckerInfo{Params: []string{"myvalue"}}} - log := "(?s)helpers_test\\.go:[0-9]+:.*\nhelpers_test\\.go:[0-9]+:\n" + - " return c\\.Check\\(1, checker, myComment\\(\"Hello world!\"\\)\\)\n" + - "\\.+ myvalue int = 1\n" + - "\\.+ Hello world!\n\n" - testHelperFailure(c, "Check(1, checker, msg)", false, false, log, - func() interface{} { - return c.Check(1, checker, myComment("Hello world!")) - }) -} - -func (s *HelpersS) TestCheckWithMissingExpected(c *check.C) { - checker := &MyChecker{result: true} - log := "(?s)helpers_test\\.go:[0-9]+:.*\nhelpers_test\\.go:[0-9]+:\n" + - " return c\\.Check\\(1, checker\\)\n" + - "\\.+ Check\\(myobtained, MyChecker, myexpected\\):\n" + - "\\.+ Wrong number of parameters for MyChecker: " + - "want 3, got 2\n\n" - testHelperFailure(c, "Check(1, checker, !?)", false, false, log, - func() interface{} { - return c.Check(1, checker) - }) -} - -func (s *HelpersS) TestCheckWithTooManyExpected(c *check.C) { - checker := &MyChecker{result: true} - log := "(?s)helpers_test\\.go:[0-9]+:.*\nhelpers_test\\.go:[0-9]+:\n" + - " return c\\.Check\\(1, checker, 2, 3\\)\n" + - "\\.+ Check\\(myobtained, MyChecker, myexpected\\):\n" + - "\\.+ Wrong number of parameters for MyChecker: " + - "want 3, got 4\n\n" - testHelperFailure(c, "Check(1, checker, 2, 3)", false, false, log, - func() interface{} { - return c.Check(1, checker, 2, 3) - }) -} - -func (s *HelpersS) TestCheckWithError(c *check.C) { - checker := &MyChecker{result: false, error: "Some not so cool data provided!"} - log := "(?s)helpers_test\\.go:[0-9]+:.*\nhelpers_test\\.go:[0-9]+:\n" + - " return c\\.Check\\(1, checker, 2\\)\n" + - "\\.+ myobtained int = 1\n" + - "\\.+ myexpected int = 2\n" + - "\\.+ Some not so cool data provided!\n\n" - testHelperFailure(c, "Check(1, checker, 2)", false, false, log, - func() interface{} { - return c.Check(1, checker, 2) - }) -} - -func (s *HelpersS) TestCheckWithNilChecker(c *check.C) { - log := "(?s)helpers_test\\.go:[0-9]+:.*\nhelpers_test\\.go:[0-9]+:\n" + - " return c\\.Check\\(1, nil\\)\n" + - "\\.+ Check\\(obtained, nil!\\?, \\.\\.\\.\\):\n" + - "\\.+ Oops\\.\\. you've provided a nil checker!\n\n" - testHelperFailure(c, "Check(obtained, nil)", false, false, log, - func() interface{} { - return c.Check(1, nil) - }) -} - -func (s *HelpersS) TestCheckWithParamsAndNamesMutation(c *check.C) { - checker := &MyChecker{result: false, params: []interface{}{3, 4}, names: []string{"newobtained", "newexpected"}} - log := "(?s)helpers_test\\.go:[0-9]+:.*\nhelpers_test\\.go:[0-9]+:\n" + - " return c\\.Check\\(1, checker, 2\\)\n" + - "\\.+ newobtained int = 3\n" + - "\\.+ newexpected int = 4\n\n" - testHelperFailure(c, "Check(1, checker, 2) with mutation", false, false, log, - func() interface{} { - return c.Check(1, checker, 2) - }) -} - -// ----------------------------------------------------------------------- -// Tests for Assert(), mostly the same as for Check() above. - -func (s *HelpersS) TestAssertSucceedWithExpected(c *check.C) { - checker := &MyChecker{result: true} - testHelperSuccess(c, "Assert(1, checker, 2)", nil, func() interface{} { - c.Assert(1, checker, 2) - return nil - }) - if !reflect.DeepEqual(checker.params, []interface{}{1, 2}) { - c.Fatalf("Bad params for check: %#v", checker.params) - } -} - -func (s *HelpersS) TestAssertSucceedWithoutExpected(c *check.C) { - checker := &MyChecker{result: true, info: &check.CheckerInfo{Params: []string{"myvalue"}}} - testHelperSuccess(c, "Assert(1, checker)", nil, func() interface{} { - c.Assert(1, checker) - return nil - }) - if !reflect.DeepEqual(checker.params, []interface{}{1}) { - c.Fatalf("Bad params for check: %#v", checker.params) - } -} - -func (s *HelpersS) TestAssertFailWithExpected(c *check.C) { - checker := &MyChecker{result: false} - log := "(?s)helpers_test\\.go:[0-9]+:.*\nhelpers_test\\.go:[0-9]+:\n" + - " c\\.Assert\\(1, checker, 2\\)\n" + - "\\.+ myobtained int = 1\n" + - "\\.+ myexpected int = 2\n\n" - testHelperFailure(c, "Assert(1, checker, 2)", nil, true, log, - func() interface{} { - c.Assert(1, checker, 2) - return nil - }) -} - -func (s *HelpersS) TestAssertFailWithExpectedAndMessage(c *check.C) { - checker := &MyChecker{result: false} - log := "(?s)helpers_test\\.go:[0-9]+:.*\nhelpers_test\\.go:[0-9]+:\n" + - " c\\.Assert\\(1, checker, 2, myComment\\(\"Hello world!\"\\)\\)\n" + - "\\.+ myobtained int = 1\n" + - "\\.+ myexpected int = 2\n" + - "\\.+ Hello world!\n\n" - testHelperFailure(c, "Assert(1, checker, 2, msg)", nil, true, log, - func() interface{} { - c.Assert(1, checker, 2, myComment("Hello world!")) - return nil - }) -} - -func (s *HelpersS) TestAssertFailWithoutExpected(c *check.C) { - checker := &MyChecker{result: false, info: &check.CheckerInfo{Params: []string{"myvalue"}}} - log := "(?s)helpers_test\\.go:[0-9]+:.*\nhelpers_test\\.go:[0-9]+:\n" + - " c\\.Assert\\(1, checker\\)\n" + - "\\.+ myvalue int = 1\n\n" - testHelperFailure(c, "Assert(1, checker)", nil, true, log, - func() interface{} { - c.Assert(1, checker) - return nil - }) -} - -func (s *HelpersS) TestAssertFailWithoutExpectedAndMessage(c *check.C) { - checker := &MyChecker{result: false, info: &check.CheckerInfo{Params: []string{"myvalue"}}} - log := "(?s)helpers_test\\.go:[0-9]+:.*\nhelpers_test\\.go:[0-9]+:\n" + - " c\\.Assert\\(1, checker, myComment\\(\"Hello world!\"\\)\\)\n" + - "\\.+ myvalue int = 1\n" + - "\\.+ Hello world!\n\n" - testHelperFailure(c, "Assert(1, checker, msg)", nil, true, log, - func() interface{} { - c.Assert(1, checker, myComment("Hello world!")) - return nil - }) -} - -func (s *HelpersS) TestAssertWithMissingExpected(c *check.C) { - checker := &MyChecker{result: true} - log := "(?s)helpers_test\\.go:[0-9]+:.*\nhelpers_test\\.go:[0-9]+:\n" + - " c\\.Assert\\(1, checker\\)\n" + - "\\.+ Assert\\(myobtained, MyChecker, myexpected\\):\n" + - "\\.+ Wrong number of parameters for MyChecker: " + - "want 3, got 2\n\n" - testHelperFailure(c, "Assert(1, checker, !?)", nil, true, log, - func() interface{} { - c.Assert(1, checker) - return nil - }) -} - -func (s *HelpersS) TestAssertWithError(c *check.C) { - checker := &MyChecker{result: false, error: "Some not so cool data provided!"} - log := "(?s)helpers_test\\.go:[0-9]+:.*\nhelpers_test\\.go:[0-9]+:\n" + - " c\\.Assert\\(1, checker, 2\\)\n" + - "\\.+ myobtained int = 1\n" + - "\\.+ myexpected int = 2\n" + - "\\.+ Some not so cool data provided!\n\n" - testHelperFailure(c, "Assert(1, checker, 2)", nil, true, log, - func() interface{} { - c.Assert(1, checker, 2) - return nil - }) -} - -func (s *HelpersS) TestAssertWithNilChecker(c *check.C) { - log := "(?s)helpers_test\\.go:[0-9]+:.*\nhelpers_test\\.go:[0-9]+:\n" + - " c\\.Assert\\(1, nil\\)\n" + - "\\.+ Assert\\(obtained, nil!\\?, \\.\\.\\.\\):\n" + - "\\.+ Oops\\.\\. you've provided a nil checker!\n\n" - testHelperFailure(c, "Assert(obtained, nil)", nil, true, log, - func() interface{} { - c.Assert(1, nil) - return nil - }) -} - -// ----------------------------------------------------------------------- -// Ensure that values logged work properly in some interesting cases. - -func (s *HelpersS) TestValueLoggingWithArrays(c *check.C) { - checker := &MyChecker{result: false} - log := "(?s)helpers_test.go:[0-9]+:.*\nhelpers_test.go:[0-9]+:\n" + - " return c\\.Check\\(\\[\\]byte{1, 2}, checker, \\[\\]byte{1, 3}\\)\n" + - "\\.+ myobtained \\[\\]uint8 = \\[\\]byte{0x1, 0x2}\n" + - "\\.+ myexpected \\[\\]uint8 = \\[\\]byte{0x1, 0x3}\n\n" - testHelperFailure(c, "Check([]byte{1}, chk, []byte{3})", false, false, log, - func() interface{} { - return c.Check([]byte{1, 2}, checker, []byte{1, 3}) - }) -} - -func (s *HelpersS) TestValueLoggingWithMultiLine(c *check.C) { - checker := &MyChecker{result: false} - log := "(?s)helpers_test.go:[0-9]+:.*\nhelpers_test.go:[0-9]+:\n" + - " return c\\.Check\\(\"a\\\\nb\\\\n\", checker, \"a\\\\nb\\\\nc\"\\)\n" + - "\\.+ myobtained string = \"\" \\+\n" + - "\\.+ \"a\\\\n\" \\+\n" + - "\\.+ \"b\\\\n\"\n" + - "\\.+ myexpected string = \"\" \\+\n" + - "\\.+ \"a\\\\n\" \\+\n" + - "\\.+ \"b\\\\n\" \\+\n" + - "\\.+ \"c\"\n\n" - testHelperFailure(c, `Check("a\nb\n", chk, "a\nb\nc")`, false, false, log, - func() interface{} { - return c.Check("a\nb\n", checker, "a\nb\nc") - }) -} - -func (s *HelpersS) TestValueLoggingWithMultiLineException(c *check.C) { - // If the newline is at the end of the string, don't log as multi-line. - checker := &MyChecker{result: false} - log := "(?s)helpers_test.go:[0-9]+:.*\nhelpers_test.go:[0-9]+:\n" + - " return c\\.Check\\(\"a b\\\\n\", checker, \"a\\\\nb\"\\)\n" + - "\\.+ myobtained string = \"a b\\\\n\"\n" + - "\\.+ myexpected string = \"\" \\+\n" + - "\\.+ \"a\\\\n\" \\+\n" + - "\\.+ \"b\"\n\n" - testHelperFailure(c, `Check("a b\n", chk, "a\nb")`, false, false, log, - func() interface{} { - return c.Check("a b\n", checker, "a\nb") - }) -} - -// ----------------------------------------------------------------------- -// MakeDir() tests. - -type MkDirHelper struct { - path1 string - path2 string - isDir1 bool - isDir2 bool - isDir3 bool - isDir4 bool -} - -func (s *MkDirHelper) SetUpSuite(c *check.C) { - s.path1 = c.MkDir() - s.isDir1 = isDir(s.path1) -} - -func (s *MkDirHelper) Test(c *check.C) { - s.path2 = c.MkDir() - s.isDir2 = isDir(s.path2) -} - -func (s *MkDirHelper) TearDownSuite(c *check.C) { - s.isDir3 = isDir(s.path1) - s.isDir4 = isDir(s.path2) -} - -func (s *HelpersS) TestMkDir(c *check.C) { - helper := MkDirHelper{} - output := String{} - check.Run(&helper, &check.RunConf{Output: &output}) - c.Assert(output.value, check.Equals, "") - c.Check(helper.isDir1, check.Equals, true) - c.Check(helper.isDir2, check.Equals, true) - c.Check(helper.isDir3, check.Equals, true) - c.Check(helper.isDir4, check.Equals, true) - c.Check(helper.path1, check.Not(check.Equals), - helper.path2) - c.Check(isDir(helper.path1), check.Equals, false) - c.Check(isDir(helper.path2), check.Equals, false) -} - -func isDir(path string) bool { - if stat, err := os.Stat(path); err == nil { - return stat.IsDir() - } - return false -} - -// Concurrent logging should not corrupt the underling buffer. -// Use go test -race to detect the race in this test. -func (s *HelpersS) TestConcurrentLogging(c *check.C) { - defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(runtime.NumCPU())) - var start, stop sync.WaitGroup - start.Add(1) - for i, n := 0, runtime.NumCPU()*2; i < n; i++ { - stop.Add(1) - go func(i int) { - start.Wait() - for j := 0; j < 30; j++ { - c.Logf("Worker %d: line %d", i, j) - } - stop.Done() - }(i) - } - start.Done() - stop.Wait() -} - -// ----------------------------------------------------------------------- -// Test the TestName function - -type TestNameHelper struct { - name1 string - name2 string - name3 string - name4 string - name5 string -} - -func (s *TestNameHelper) SetUpSuite(c *check.C) { s.name1 = c.TestName() } -func (s *TestNameHelper) SetUpTest(c *check.C) { s.name2 = c.TestName() } -func (s *TestNameHelper) Test(c *check.C) { s.name3 = c.TestName() } -func (s *TestNameHelper) TearDownTest(c *check.C) { s.name4 = c.TestName() } -func (s *TestNameHelper) TearDownSuite(c *check.C) { s.name5 = c.TestName() } - -func (s *HelpersS) TestTestName(c *check.C) { - helper := TestNameHelper{} - output := String{} - check.Run(&helper, &check.RunConf{Output: &output}) - c.Check(helper.name1, check.Equals, "") - c.Check(helper.name2, check.Equals, "TestNameHelper.Test") - c.Check(helper.name3, check.Equals, "TestNameHelper.Test") - c.Check(helper.name4, check.Equals, "TestNameHelper.Test") - c.Check(helper.name5, check.Equals, "") -} - -// ----------------------------------------------------------------------- -// A couple of helper functions to test helper functions. :-) - -func testHelperSuccess(c *check.C, name string, expectedResult interface{}, closure func() interface{}) { - var result interface{} - defer (func() { - if err := recover(); err != nil { - panic(err) - } - checkState(c, result, - &expectedState{ - name: name, - result: expectedResult, - failed: false, - log: "", - }) - })() - result = closure() -} - -func testHelperFailure(c *check.C, name string, expectedResult interface{}, shouldStop bool, log string, closure func() interface{}) { - var result interface{} - defer (func() { - if err := recover(); err != nil { - panic(err) - } - checkState(c, result, - &expectedState{ - name: name, - result: expectedResult, - failed: true, - log: log, - }) - })() - result = closure() - if shouldStop { - c.Logf("%s didn't stop when it should", name) - } -} diff --git a/Godeps/_workspace/src/gopkg.in/check.v1/printer_test.go b/Godeps/_workspace/src/gopkg.in/check.v1/printer_test.go deleted file mode 100644 index 538b2d52e..000000000 --- a/Godeps/_workspace/src/gopkg.in/check.v1/printer_test.go +++ /dev/null @@ -1,104 +0,0 @@ -package check_test - -import ( - . "gopkg.in/check.v1" -) - -var _ = Suite(&PrinterS{}) - -type PrinterS struct{} - -func (s *PrinterS) TestCountSuite(c *C) { - suitesRun += 1 -} - -var printTestFuncLine int - -func init() { - printTestFuncLine = getMyLine() + 3 -} - -func printTestFunc() { - println(1) // Comment1 - if 2 == 2 { // Comment2 - println(3) // Comment3 - } - switch 5 { - case 6: println(6) // Comment6 - println(7) - } - switch interface{}(9).(type) {// Comment9 - case int: println(10) - println(11) - } - select { - case <-(chan bool)(nil): println(14) - println(15) - default: println(16) - println(17) - } - println(19, - 20) - _ = func() { println(21) - println(22) - } - println(24, func() { - println(25) - }) - // Leading comment - // with multiple lines. - println(29) // Comment29 -} - -var printLineTests = []struct { - line int - output string -}{ - {1, "println(1) // Comment1"}, - {2, "if 2 == 2 { // Comment2\n ...\n}"}, - {3, "println(3) // Comment3"}, - {5, "switch 5 {\n...\n}"}, - {6, "case 6:\n println(6) // Comment6\n ..."}, - {7, "println(7)"}, - {9, "switch interface{}(9).(type) { // Comment9\n...\n}"}, - {10, "case int:\n println(10)\n ..."}, - {14, "case <-(chan bool)(nil):\n println(14)\n ..."}, - {15, "println(15)"}, - {16, "default:\n println(16)\n ..."}, - {17, "println(17)"}, - {19, "println(19,\n 20)"}, - {20, "println(19,\n 20)"}, - {21, "_ = func() {\n println(21)\n println(22)\n}"}, - {22, "println(22)"}, - {24, "println(24, func() {\n println(25)\n})"}, - {25, "println(25)"}, - {26, "println(24, func() {\n println(25)\n})"}, - {29, "// Leading comment\n// with multiple lines.\nprintln(29) // Comment29"}, -} - -func (s *PrinterS) TestPrintLine(c *C) { - for _, test := range printLineTests { - output, err := PrintLine("printer_test.go", printTestFuncLine+test.line) - c.Assert(err, IsNil) - c.Assert(output, Equals, test.output) - } -} - -var indentTests = []struct { - in, out string -}{ - {"", ""}, - {"\n", "\n"}, - {"a", ">>>a"}, - {"a\n", ">>>a\n"}, - {"a\nb", ">>>a\n>>>b"}, - {" ", ">>> "}, -} - -func (s *PrinterS) TestIndent(c *C) { - for _, test := range indentTests { - out := Indent(test.in, ">>>") - c.Assert(out, Equals, test.out) - } - -} diff --git a/Godeps/_workspace/src/gopkg.in/check.v1/reporter.go b/Godeps/_workspace/src/gopkg.in/check.v1/reporter.go new file mode 100644 index 000000000..fb04f76f6 --- /dev/null +++ b/Godeps/_workspace/src/gopkg.in/check.v1/reporter.go @@ -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) +} diff --git a/Godeps/_workspace/src/gopkg.in/check.v1/run_test.go b/Godeps/_workspace/src/gopkg.in/check.v1/run_test.go deleted file mode 100644 index f41fffc3f..000000000 --- a/Godeps/_workspace/src/gopkg.in/check.v1/run_test.go +++ /dev/null @@ -1,419 +0,0 @@ -// These tests verify the test running logic. - -package check_test - -import ( - "errors" - . "gopkg.in/check.v1" - "os" - "sync" -) - -var runnerS = Suite(&RunS{}) - -type RunS struct{} - -func (s *RunS) TestCountSuite(c *C) { - suitesRun += 1 -} - -// ----------------------------------------------------------------------- -// Tests ensuring result counting works properly. - -func (s *RunS) TestSuccess(c *C) { - output := String{} - result := Run(&SuccessHelper{}, &RunConf{Output: &output}) - c.Check(result.Succeeded, Equals, 1) - c.Check(result.Failed, Equals, 0) - c.Check(result.Skipped, Equals, 0) - c.Check(result.Panicked, Equals, 0) - c.Check(result.FixturePanicked, Equals, 0) - c.Check(result.Missed, Equals, 0) - c.Check(result.RunError, IsNil) -} - -func (s *RunS) TestFailure(c *C) { - output := String{} - result := Run(&FailHelper{}, &RunConf{Output: &output}) - c.Check(result.Succeeded, Equals, 0) - c.Check(result.Failed, Equals, 1) - c.Check(result.Skipped, Equals, 0) - c.Check(result.Panicked, Equals, 0) - c.Check(result.FixturePanicked, Equals, 0) - c.Check(result.Missed, Equals, 0) - c.Check(result.RunError, IsNil) -} - -func (s *RunS) TestFixture(c *C) { - output := String{} - result := Run(&FixtureHelper{}, &RunConf{Output: &output}) - c.Check(result.Succeeded, Equals, 2) - c.Check(result.Failed, Equals, 0) - c.Check(result.Skipped, Equals, 0) - c.Check(result.Panicked, Equals, 0) - c.Check(result.FixturePanicked, Equals, 0) - c.Check(result.Missed, Equals, 0) - c.Check(result.RunError, IsNil) -} - -func (s *RunS) TestPanicOnTest(c *C) { - output := String{} - helper := &FixtureHelper{panicOn: "Test1"} - result := Run(helper, &RunConf{Output: &output}) - c.Check(result.Succeeded, Equals, 1) - c.Check(result.Failed, Equals, 0) - c.Check(result.Skipped, Equals, 0) - c.Check(result.Panicked, Equals, 1) - c.Check(result.FixturePanicked, Equals, 0) - c.Check(result.Missed, Equals, 0) - c.Check(result.RunError, IsNil) -} - -func (s *RunS) TestPanicOnSetUpTest(c *C) { - output := String{} - helper := &FixtureHelper{panicOn: "SetUpTest"} - result := Run(helper, &RunConf{Output: &output}) - c.Check(result.Succeeded, Equals, 0) - c.Check(result.Failed, Equals, 0) - c.Check(result.Skipped, Equals, 0) - c.Check(result.Panicked, Equals, 0) - c.Check(result.FixturePanicked, Equals, 1) - c.Check(result.Missed, Equals, 2) - c.Check(result.RunError, IsNil) -} - -func (s *RunS) TestPanicOnSetUpSuite(c *C) { - output := String{} - helper := &FixtureHelper{panicOn: "SetUpSuite"} - result := Run(helper, &RunConf{Output: &output}) - c.Check(result.Succeeded, Equals, 0) - c.Check(result.Failed, Equals, 0) - c.Check(result.Skipped, Equals, 0) - c.Check(result.Panicked, Equals, 0) - c.Check(result.FixturePanicked, Equals, 1) - c.Check(result.Missed, Equals, 2) - c.Check(result.RunError, IsNil) -} - -// ----------------------------------------------------------------------- -// Check result aggregation. - -func (s *RunS) TestAdd(c *C) { - result := &Result{ - Succeeded: 1, - Skipped: 2, - Failed: 3, - Panicked: 4, - FixturePanicked: 5, - Missed: 6, - ExpectedFailures: 7, - } - result.Add(&Result{ - Succeeded: 10, - Skipped: 20, - Failed: 30, - Panicked: 40, - FixturePanicked: 50, - Missed: 60, - ExpectedFailures: 70, - }) - c.Check(result.Succeeded, Equals, 11) - c.Check(result.Skipped, Equals, 22) - c.Check(result.Failed, Equals, 33) - c.Check(result.Panicked, Equals, 44) - c.Check(result.FixturePanicked, Equals, 55) - c.Check(result.Missed, Equals, 66) - c.Check(result.ExpectedFailures, Equals, 77) - c.Check(result.RunError, IsNil) -} - -// ----------------------------------------------------------------------- -// Check the Passed() method. - -func (s *RunS) TestPassed(c *C) { - c.Assert((&Result{}).Passed(), Equals, true) - c.Assert((&Result{Succeeded: 1}).Passed(), Equals, true) - c.Assert((&Result{Skipped: 1}).Passed(), Equals, true) - c.Assert((&Result{Failed: 1}).Passed(), Equals, false) - c.Assert((&Result{Panicked: 1}).Passed(), Equals, false) - c.Assert((&Result{FixturePanicked: 1}).Passed(), Equals, false) - c.Assert((&Result{Missed: 1}).Passed(), Equals, false) - c.Assert((&Result{RunError: errors.New("!")}).Passed(), Equals, false) -} - -// ----------------------------------------------------------------------- -// Check that result printing is working correctly. - -func (s *RunS) TestPrintSuccess(c *C) { - result := &Result{Succeeded: 5} - c.Check(result.String(), Equals, "OK: 5 passed") -} - -func (s *RunS) TestPrintFailure(c *C) { - result := &Result{Failed: 5} - c.Check(result.String(), Equals, "OOPS: 0 passed, 5 FAILED") -} - -func (s *RunS) TestPrintSkipped(c *C) { - result := &Result{Skipped: 5} - c.Check(result.String(), Equals, "OK: 0 passed, 5 skipped") -} - -func (s *RunS) TestPrintExpectedFailures(c *C) { - result := &Result{ExpectedFailures: 5} - c.Check(result.String(), Equals, "OK: 0 passed, 5 expected failures") -} - -func (s *RunS) TestPrintPanicked(c *C) { - result := &Result{Panicked: 5} - c.Check(result.String(), Equals, "OOPS: 0 passed, 5 PANICKED") -} - -func (s *RunS) TestPrintFixturePanicked(c *C) { - result := &Result{FixturePanicked: 5} - c.Check(result.String(), Equals, "OOPS: 0 passed, 5 FIXTURE-PANICKED") -} - -func (s *RunS) TestPrintMissed(c *C) { - result := &Result{Missed: 5} - c.Check(result.String(), Equals, "OOPS: 0 passed, 5 MISSED") -} - -func (s *RunS) TestPrintAll(c *C) { - result := &Result{Succeeded: 1, Skipped: 2, ExpectedFailures: 3, - Panicked: 4, FixturePanicked: 5, Missed: 6} - c.Check(result.String(), Equals, - "OOPS: 1 passed, 2 skipped, 3 expected failures, 4 PANICKED, "+ - "5 FIXTURE-PANICKED, 6 MISSED") -} - -func (s *RunS) TestPrintRunError(c *C) { - result := &Result{Succeeded: 1, Failed: 1, - RunError: errors.New("Kaboom!")} - c.Check(result.String(), Equals, "ERROR: Kaboom!") -} - -// ----------------------------------------------------------------------- -// Verify that the method pattern flag works correctly. - -func (s *RunS) TestFilterTestName(c *C) { - helper := FixtureHelper{} - output := String{} - runConf := RunConf{Output: &output, Filter: "Test[91]"} - Run(&helper, &runConf) - c.Check(helper.calls[0], Equals, "SetUpSuite") - c.Check(helper.calls[1], Equals, "SetUpTest") - c.Check(helper.calls[2], Equals, "Test1") - c.Check(helper.calls[3], Equals, "TearDownTest") - c.Check(helper.calls[4], Equals, "TearDownSuite") - c.Check(len(helper.calls), Equals, 5) -} - -func (s *RunS) TestFilterTestNameWithAll(c *C) { - helper := FixtureHelper{} - output := String{} - runConf := RunConf{Output: &output, Filter: ".*"} - Run(&helper, &runConf) - c.Check(helper.calls[0], Equals, "SetUpSuite") - c.Check(helper.calls[1], Equals, "SetUpTest") - c.Check(helper.calls[2], Equals, "Test1") - c.Check(helper.calls[3], Equals, "TearDownTest") - c.Check(helper.calls[4], Equals, "SetUpTest") - c.Check(helper.calls[5], Equals, "Test2") - c.Check(helper.calls[6], Equals, "TearDownTest") - c.Check(helper.calls[7], Equals, "TearDownSuite") - c.Check(len(helper.calls), Equals, 8) -} - -func (s *RunS) TestFilterSuiteName(c *C) { - helper := FixtureHelper{} - output := String{} - runConf := RunConf{Output: &output, Filter: "FixtureHelper"} - Run(&helper, &runConf) - c.Check(helper.calls[0], Equals, "SetUpSuite") - c.Check(helper.calls[1], Equals, "SetUpTest") - c.Check(helper.calls[2], Equals, "Test1") - c.Check(helper.calls[3], Equals, "TearDownTest") - c.Check(helper.calls[4], Equals, "SetUpTest") - c.Check(helper.calls[5], Equals, "Test2") - c.Check(helper.calls[6], Equals, "TearDownTest") - c.Check(helper.calls[7], Equals, "TearDownSuite") - c.Check(len(helper.calls), Equals, 8) -} - -func (s *RunS) TestFilterSuiteNameAndTestName(c *C) { - helper := FixtureHelper{} - output := String{} - runConf := RunConf{Output: &output, Filter: "FixtureHelper\\.Test2"} - Run(&helper, &runConf) - c.Check(helper.calls[0], Equals, "SetUpSuite") - c.Check(helper.calls[1], Equals, "SetUpTest") - c.Check(helper.calls[2], Equals, "Test2") - c.Check(helper.calls[3], Equals, "TearDownTest") - c.Check(helper.calls[4], Equals, "TearDownSuite") - c.Check(len(helper.calls), Equals, 5) -} - -func (s *RunS) TestFilterAllOut(c *C) { - helper := FixtureHelper{} - output := String{} - runConf := RunConf{Output: &output, Filter: "NotFound"} - Run(&helper, &runConf) - c.Check(len(helper.calls), Equals, 0) -} - -func (s *RunS) TestRequirePartialMatch(c *C) { - helper := FixtureHelper{} - output := String{} - runConf := RunConf{Output: &output, Filter: "est"} - Run(&helper, &runConf) - c.Check(len(helper.calls), Equals, 8) -} - -func (s *RunS) TestFilterError(c *C) { - helper := FixtureHelper{} - output := String{} - runConf := RunConf{Output: &output, Filter: "]["} - result := Run(&helper, &runConf) - c.Check(result.String(), Equals, - "ERROR: Bad filter expression: error parsing regexp: missing closing ]: `[`") - c.Check(len(helper.calls), Equals, 0) -} - -// ----------------------------------------------------------------------- -// Verify that List works correctly. - -func (s *RunS) TestListFiltered(c *C) { - names := List(&FixtureHelper{}, &RunConf{Filter: "1"}) - c.Assert(names, DeepEquals, []string{ - "FixtureHelper.Test1", - }) -} - -func (s *RunS) TestList(c *C) { - names := List(&FixtureHelper{}, &RunConf{}) - c.Assert(names, DeepEquals, []string{ - "FixtureHelper.Test1", - "FixtureHelper.Test2", - }) -} - -// ----------------------------------------------------------------------- -// 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: check_test\\.go:[0-9]+: FixtureHelper\\.Test1\t *[.0-9]+s\n" + - "PASS: check_test\\.go:[0-9]+: FixtureHelper\\.Test2\t *[.0-9]+s\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 := "(?s).*PANIC.*\n-+\n" + // Should have an extra line. - "PASS: check_test\\.go:[0-9]+: FixtureHelper\\.Test2\t *[.0-9]+s\n" - - c.Assert(output.value, Matches, expected) -} - -// ----------------------------------------------------------------------- -// Verify the stream output mode. In this mode there's no output caching. - -type StreamHelper struct { - l2 sync.Mutex - l3 sync.Mutex -} - -func (s *StreamHelper) SetUpSuite(c *C) { - c.Log("0") -} - -func (s *StreamHelper) Test1(c *C) { - c.Log("1") - s.l2.Lock() - s.l3.Lock() - go func() { - s.l2.Lock() // Wait for "2". - c.Log("3") - s.l3.Unlock() - }() -} - -func (s *StreamHelper) Test2(c *C) { - c.Log("2") - s.l2.Unlock() - s.l3.Lock() // Wait for "3". - c.Fail() - c.Log("4") -} - -func (s *RunS) TestStreamMode(c *C) { - helper := &StreamHelper{} - output := String{} - runConf := RunConf{Output: &output, Stream: true} - Run(helper, &runConf) - - expected := "START: run_test\\.go:[0-9]+: StreamHelper\\.SetUpSuite\n0\n" + - "PASS: run_test\\.go:[0-9]+: StreamHelper\\.SetUpSuite\t *[.0-9]+s\n\n" + - "START: run_test\\.go:[0-9]+: StreamHelper\\.Test1\n1\n" + - "PASS: run_test\\.go:[0-9]+: StreamHelper\\.Test1\t *[.0-9]+s\n\n" + - "START: run_test\\.go:[0-9]+: StreamHelper\\.Test2\n2\n3\n4\n" + - "FAIL: run_test\\.go:[0-9]+: StreamHelper\\.Test2\n\n" - - c.Assert(output.value, Matches, expected) -} - -type StreamMissHelper struct{} - -func (s *StreamMissHelper) SetUpSuite(c *C) { - c.Log("0") - c.Fail() -} - -func (s *StreamMissHelper) Test1(c *C) { - c.Log("1") -} - -func (s *RunS) TestStreamModeWithMiss(c *C) { - helper := &StreamMissHelper{} - output := String{} - runConf := RunConf{Output: &output, Stream: true} - Run(helper, &runConf) - - expected := "START: run_test\\.go:[0-9]+: StreamMissHelper\\.SetUpSuite\n0\n" + - "FAIL: run_test\\.go:[0-9]+: StreamMissHelper\\.SetUpSuite\n\n" + - "START: run_test\\.go:[0-9]+: StreamMissHelper\\.Test1\n" + - "MISS: run_test\\.go:[0-9]+: StreamMissHelper\\.Test1\n\n" - - c.Assert(output.value, Matches, expected) -} - -// ----------------------------------------------------------------------- -// Verify that that the keep work dir request indeed does so. - -type WorkDirSuite struct {} - -func (s *WorkDirSuite) Test(c *C) { - c.MkDir() -} - -func (s *RunS) TestKeepWorkDir(c *C) { - output := String{} - runConf := RunConf{Output: &output, Verbose: true, KeepWorkDir: true} - result := Run(&WorkDirSuite{}, &runConf) - - c.Assert(result.String(), Matches, ".*\nWORK=" + result.WorkDir) - - stat, err := os.Stat(result.WorkDir) - c.Assert(err, IsNil) - c.Assert(stat.IsDir(), Equals, true) -} diff --git a/Godeps/_workspace/src/gopkg.in/fatih/set.v0/set_nots_test.go b/Godeps/_workspace/src/gopkg.in/fatih/set.v0/set_nots_test.go deleted file mode 100644 index fd599699f..000000000 --- a/Godeps/_workspace/src/gopkg.in/fatih/set.v0/set_nots_test.go +++ /dev/null @@ -1,282 +0,0 @@ -package set - -import ( - "reflect" - "strings" - "testing" -) - -func TestSetNonTS_NewNonTS_parameters(t *testing.T) { - s := NewNonTS("string", "another_string", 1, 3.14) - - if s.Size() != 4 { - t.Error("NewNonTS: calling with parameters should create a set with size of four") - } -} - -func TestSetNonTS_Add(t *testing.T) { - s := NewNonTS() - s.Add(1) - s.Add(2) - s.Add(2) // duplicate - s.Add("fatih") - s.Add("zeynep") - s.Add("zeynep") // another duplicate - - if s.Size() != 4 { - t.Error("Add: items are not unique. The set size should be four") - } - - if !s.Has(1, 2, "fatih", "zeynep") { - t.Error("Add: added items are not availabile in the set.") - } -} - -func TestSetNonTS_Add_multiple(t *testing.T) { - s := NewNonTS() - s.Add("ankara", "san francisco", 3.14) - - if s.Size() != 3 { - t.Error("Add: items are not unique. The set size should be three") - } - - if !s.Has("ankara", "san francisco", 3.14) { - t.Error("Add: added items are not availabile in the set.") - } -} - -func TestSetNonTS_Remove(t *testing.T) { - s := NewNonTS() - s.Add(1) - s.Add(2) - s.Add("fatih") - - s.Remove(1) - if s.Size() != 2 { - t.Error("Remove: set size should be two after removing") - } - - s.Remove(1) - if s.Size() != 2 { - t.Error("Remove: set size should be not change after trying to remove a non-existing item") - } - - s.Remove(2) - s.Remove("fatih") - if s.Size() != 0 { - t.Error("Remove: set size should be zero") - } - - s.Remove("fatih") // try to remove something from a zero length set -} - -func TestSetNonTS_Remove_multiple(t *testing.T) { - s := NewNonTS() - s.Add("ankara", "san francisco", 3.14, "istanbul") - s.Remove("ankara", "san francisco", 3.14) - - if s.Size() != 1 { - t.Error("Remove: items are not unique. The set size should be four") - } - - if !s.Has("istanbul") { - t.Error("Add: added items are not availabile in the set.") - } -} - -func TestSetNonTS_Pop(t *testing.T) { - s := NewNonTS() - s.Add(1) - s.Add(2) - s.Add("fatih") - - a := s.Pop() - if s.Size() != 2 { - t.Error("Pop: set size should be two after popping out") - } - - if s.Has(a) { - t.Error("Pop: returned item should not exist") - } - - s.Pop() - s.Pop() - b := s.Pop() - if b != nil { - t.Error("Pop: should return nil because set is empty") - } - - s.Pop() // try to remove something from a zero length set -} - -func TestSetNonTS_Has(t *testing.T) { - s := NewNonTS("1", "2", "3", "4") - - if !s.Has("1") { - t.Error("Has: the item 1 exist, but 'Has' is returning false") - } - - if !s.Has("1", "2", "3", "4") { - t.Error("Has: the items all exist, but 'Has' is returning false") - } -} - -func TestSetNonTS_Clear(t *testing.T) { - s := NewNonTS() - s.Add(1) - s.Add("istanbul") - s.Add("san francisco") - - s.Clear() - if s.Size() != 0 { - t.Error("Clear: set size should be zero") - } -} - -func TestSetNonTS_IsEmpty(t *testing.T) { - s := NewNonTS() - - empty := s.IsEmpty() - if !empty { - t.Error("IsEmpty: set is empty, it should be true") - } - - s.Add(2) - s.Add(3) - notEmpty := s.IsEmpty() - - if notEmpty { - t.Error("IsEmpty: set is filled, it should be false") - } -} - -func TestSetNonTS_IsEqual(t *testing.T) { - s := NewNonTS("1", "2", "3") - u := NewNonTS("1", "2", "3") - - ok := s.IsEqual(u) - if !ok { - t.Error("IsEqual: set s and t are equal. However it returns false") - } - - // same size, different content - a := NewNonTS("1", "2", "3") - b := NewNonTS("4", "5", "6") - - ok = a.IsEqual(b) - if ok { - t.Error("IsEqual: set a and b are now equal (1). However it returns true") - } - - // different size, similar content - a = NewNonTS("1", "2", "3") - b = NewNonTS("1", "2", "3", "4") - - ok = a.IsEqual(b) - if ok { - t.Error("IsEqual: set s and t are now equal (2). However it returns true") - } - -} - -func TestSetNonTS_IsSubset(t *testing.T) { - s := NewNonTS("1", "2", "3", "4") - u := NewNonTS("1", "2", "3") - - ok := s.IsSubset(u) - if !ok { - t.Error("IsSubset: u is a subset of s. However it returns false") - } - - ok = u.IsSubset(s) - if ok { - t.Error("IsSubset: s is not a subset of u. However it returns true") - } - -} - -func TestSetNonTS_IsSuperset(t *testing.T) { - s := NewNonTS("1", "2", "3", "4") - u := NewNonTS("1", "2", "3") - - ok := u.IsSuperset(s) - if !ok { - t.Error("IsSuperset: s is a superset of u. However it returns false") - } - - ok = s.IsSuperset(u) - if ok { - t.Error("IsSuperset: u is not a superset of u. However it returns true") - } - -} - -func TestSetNonTS_String(t *testing.T) { - s := NewNonTS() - if s.String() != "[]" { - t.Errorf("String: output is not what is excepted '%s'", s.String()) - } - - s.Add("1", "2", "3", "4") - if !strings.HasPrefix(s.String(), "[") { - t.Error("String: output should begin with a square bracket") - } - - if !strings.HasSuffix(s.String(), "]") { - t.Error("String: output should end with a square bracket") - } - -} - -func TestSetNonTS_List(t *testing.T) { - s := NewNonTS("1", "2", "3", "4") - - // this returns a slice of interface{} - if len(s.List()) != 4 { - t.Error("List: slice size should be four.") - } - - for _, item := range s.List() { - r := reflect.TypeOf(item) - if r.Kind().String() != "string" { - t.Error("List: slice item should be a string") - } - } -} - -func TestSetNonTS_Copy(t *testing.T) { - s := NewNonTS("1", "2", "3", "4") - r := s.Copy() - - if !s.IsEqual(r) { - t.Error("Copy: set s and r are not equal") - } -} - -func TestSetNonTS_Merge(t *testing.T) { - s := NewNonTS("1", "2", "3") - r := NewNonTS("3", "4", "5") - s.Merge(r) - - if s.Size() != 5 { - t.Error("Merge: the set doesn't have all items in it.") - } - - if !s.Has("1", "2", "3", "4", "5") { - t.Error("Merge: merged items are not availabile in the set.") - } -} - -func TestSetNonTS_Separate(t *testing.T) { - s := NewNonTS("1", "2", "3") - r := NewNonTS("3", "5") - s.Separate(r) - - if s.Size() != 2 { - t.Error("Separate: the set doesn't have all items in it.") - } - - if !s.Has("1", "2") { - t.Error("Separate: items after separation are not availabile in the set.") - } -} diff --git a/Godeps/_workspace/src/gopkg.in/fatih/set.v0/set_test.go b/Godeps/_workspace/src/gopkg.in/fatih/set.v0/set_test.go deleted file mode 100644 index 83dd5806d..000000000 --- a/Godeps/_workspace/src/gopkg.in/fatih/set.v0/set_test.go +++ /dev/null @@ -1,188 +0,0 @@ -package set - -import ( - "reflect" - "testing" -) - -func Test_Union(t *testing.T) { - s := New("1", "2", "3") - r := New("3", "4", "5") - x := NewNonTS("5", "6", "7") - - u := Union(s, r, x) - if settype := reflect.TypeOf(u).String(); settype != "*set.Set" { - t.Error("Union should derive its set type from the first passed set, got", settype) - } - if u.Size() != 7 { - t.Error("Union: the merged set doesn't have all items in it.") - } - - if !u.Has("1", "2", "3", "4", "5", "6", "7") { - t.Error("Union: merged items are not availabile in the set.") - } - - z := Union(x, r) - if z.Size() != 5 { - t.Error("Union: Union of 2 sets doesn't have the proper number of items.") - } - if settype := reflect.TypeOf(z).String(); settype != "*set.SetNonTS" { - t.Error("Union should derive its set type from the first passed set, got", settype) - } - -} - -func Test_Difference(t *testing.T) { - s := New("1", "2", "3") - r := New("3", "4", "5") - x := New("5", "6", "7") - u := Difference(s, r, x) - - if u.Size() != 2 { - t.Error("Difference: the set doesn't have all items in it.") - } - - if !u.Has("1", "2") { - t.Error("Difference: items are not availabile in the set.") - } - - y := Difference(r, r) - if y.Size() != 0 { - t.Error("Difference: size should be zero") - } - -} - -func Test_Intersection(t *testing.T) { - s1 := New("1", "3", "4", "5") - s2 := New("2", "3", "5", "6") - s3 := New("4", "5", "6", "7") - u := Intersection(s1, s2, s3) - - if u.Size() != 1 { - t.Error("Intersection: the set doesn't have all items in it.") - } - - if !u.Has("5") { - t.Error("Intersection: items after intersection are not availabile in the set.") - } -} - -func Test_SymmetricDifference(t *testing.T) { - s := New("1", "2", "3") - r := New("3", "4", "5") - u := SymmetricDifference(s, r) - - if u.Size() != 4 { - t.Error("SymmetricDifference: the set doesn't have all items in it.") - } - - if !u.Has("1", "2", "4", "5") { - t.Error("SymmetricDifference: items are not availabile in the set.") - } -} - -func Test_StringSlice(t *testing.T) { - s := New("san francisco", "istanbul", 3.14, 1321, "ankara") - u := StringSlice(s) - - if len(u) != 3 { - t.Error("StringSlice: slice should only have three items") - } - - for _, item := range u { - r := reflect.TypeOf(item) - if r.Kind().String() != "string" { - t.Error("StringSlice: slice item should be a string") - } - } -} - -func Test_IntSlice(t *testing.T) { - s := New("san francisco", "istanbul", 3.14, 1321, "ankara", 8876) - u := IntSlice(s) - - if len(u) != 2 { - t.Error("IntSlice: slice should only have two items") - } - - for _, item := range u { - r := reflect.TypeOf(item) - if r.Kind().String() != "int" { - t.Error("Intslice: slice item should be a int") - } - } -} - -func BenchmarkSetEquality(b *testing.B) { - s := New() - u := New() - - for i := 0; i < b.N; i++ { - s.Add(i) - u.Add(i) - } - - b.ResetTimer() - - for i := 0; i < b.N; i++ { - s.IsEqual(u) - } -} - -func BenchmarkSubset(b *testing.B) { - s := New() - u := New() - - for i := 0; i < b.N; i++ { - s.Add(i) - u.Add(i) - } - - b.ResetTimer() - - for i := 0; i < b.N; i++ { - s.IsSubset(u) - } -} - -func benchmarkIntersection(b *testing.B, numberOfItems int) { - s1 := New() - s2 := New() - - for i := 0; i < numberOfItems/2; i++ { - s1.Add(i) - } - for i := 0; i < numberOfItems; i++ { - s2.Add(i) - } - - b.ResetTimer() - for i := 0; i < b.N; i++ { - Intersection(s1, s2) - } -} - -func BenchmarkIntersection10(b *testing.B) { - benchmarkIntersection(b, 10) -} - -func BenchmarkIntersection100(b *testing.B) { - benchmarkIntersection(b, 100) -} - -func BenchmarkIntersection1000(b *testing.B) { - benchmarkIntersection(b, 1000) -} - -func BenchmarkIntersection10000(b *testing.B) { - benchmarkIntersection(b, 10000) -} - -func BenchmarkIntersection100000(b *testing.B) { - benchmarkIntersection(b, 100000) -} - -func BenchmarkIntersection1000000(b *testing.B) { - benchmarkIntersection(b, 1000000) -} diff --git a/Godeps/_workspace/src/gopkg.in/fatih/set.v0/set_ts_test.go b/Godeps/_workspace/src/gopkg.in/fatih/set.v0/set_ts_test.go deleted file mode 100644 index 8d2f509d0..000000000 --- a/Godeps/_workspace/src/gopkg.in/fatih/set.v0/set_ts_test.go +++ /dev/null @@ -1,321 +0,0 @@ -package set - -import ( - "reflect" - "strconv" - "strings" - "testing" -) - -func TestSet_New(t *testing.T) { - s := New() - - if s.Size() != 0 { - t.Error("New: calling without any parameters should create a set with zero size") - } - - u := s.New() - if u.Size() != 0 { - t.Error("New: creating a new set via s.New() should create a set with zero size") - } -} - -func TestSet_New_parameters(t *testing.T) { - s := New("string", "another_string", 1, 3.14) - - if s.Size() != 4 { - t.Error("New: calling with parameters should create a set with size of four") - } -} - -func TestSet_Add(t *testing.T) { - s := New() - s.Add(1) - s.Add(2) - s.Add(2) // duplicate - s.Add("fatih") - s.Add("zeynep") - s.Add("zeynep") // another duplicate - - if s.Size() != 4 { - t.Error("Add: items are not unique. The set size should be four") - } - - if !s.Has(1, 2, "fatih", "zeynep") { - t.Error("Add: added items are not availabile in the set.") - } -} - -func TestSet_Add_multiple(t *testing.T) { - s := New() - s.Add("ankara", "san francisco", 3.14) - - if s.Size() != 3 { - t.Error("Add: items are not unique. The set size should be three") - } - - if !s.Has("ankara", "san francisco", 3.14) { - t.Error("Add: added items are not availabile in the set.") - } -} - -func TestSet_Remove(t *testing.T) { - s := New() - s.Add(1) - s.Add(2) - s.Add("fatih") - - s.Remove(1) - if s.Size() != 2 { - t.Error("Remove: set size should be two after removing") - } - - s.Remove(1) - if s.Size() != 2 { - t.Error("Remove: set size should be not change after trying to remove a non-existing item") - } - - s.Remove(2) - s.Remove("fatih") - if s.Size() != 0 { - t.Error("Remove: set size should be zero") - } - - s.Remove("fatih") // try to remove something from a zero length set -} - -func TestSet_Remove_multiple(t *testing.T) { - s := New() - s.Add("ankara", "san francisco", 3.14, "istanbul") - s.Remove("ankara", "san francisco", 3.14) - - if s.Size() != 1 { - t.Error("Remove: items are not unique. The set size should be four") - } - - if !s.Has("istanbul") { - t.Error("Add: added items are not availabile in the set.") - } -} - -func TestSet_Pop(t *testing.T) { - s := New() - s.Add(1) - s.Add(2) - s.Add("fatih") - - a := s.Pop() - if s.Size() != 2 { - t.Error("Pop: set size should be two after popping out") - } - - if s.Has(a) { - t.Error("Pop: returned item should not exist") - } - - s.Pop() - s.Pop() - b := s.Pop() - if b != nil { - t.Error("Pop: should return nil because set is empty") - } - - s.Pop() // try to remove something from a zero length set -} - -func TestSet_Has(t *testing.T) { - s := New("1", "2", "3", "4") - - if !s.Has("1") { - t.Error("Has: the item 1 exist, but 'Has' is returning false") - } - - if !s.Has("1", "2", "3", "4") { - t.Error("Has: the items all exist, but 'Has' is returning false") - } -} - -func TestSet_Clear(t *testing.T) { - s := New() - s.Add(1) - s.Add("istanbul") - s.Add("san francisco") - - s.Clear() - if s.Size() != 0 { - t.Error("Clear: set size should be zero") - } -} - -func TestSet_IsEmpty(t *testing.T) { - s := New() - - empty := s.IsEmpty() - if !empty { - t.Error("IsEmpty: set is empty, it should be true") - } - - s.Add(2) - s.Add(3) - notEmpty := s.IsEmpty() - - if notEmpty { - t.Error("IsEmpty: set is filled, it should be false") - } -} - -func TestSet_IsEqual(t *testing.T) { - s := New("1", "2", "3") - u := New("1", "2", "3") - - ok := s.IsEqual(u) - if !ok { - t.Error("IsEqual: set s and t are equal. However it returns false") - } - - // same size, different content - a := New("1", "2", "3") - b := New("4", "5", "6") - - ok = a.IsEqual(b) - if ok { - t.Error("IsEqual: set a and b are now equal (1). However it returns true") - } - - // different size, similar content - a = New("1", "2", "3") - b = New("1", "2", "3", "4") - - ok = a.IsEqual(b) - if ok { - t.Error("IsEqual: set s and t are now equal (2). However it returns true") - } - -} - -func TestSet_IsSubset(t *testing.T) { - s := New("1", "2", "3", "4") - u := New("1", "2", "3") - - ok := s.IsSubset(u) - if !ok { - t.Error("IsSubset: u is a subset of s. However it returns false") - } - - ok = u.IsSubset(s) - if ok { - t.Error("IsSubset: s is not a subset of u. However it returns true") - } - -} - -func TestSet_IsSuperset(t *testing.T) { - s := New("1", "2", "3", "4") - u := New("1", "2", "3") - - ok := u.IsSuperset(s) - if !ok { - t.Error("IsSuperset: s is a superset of u. However it returns false") - } - - ok = s.IsSuperset(u) - if ok { - t.Error("IsSuperset: u is not a superset of u. However it returns true") - } - -} - -func TestSet_String(t *testing.T) { - s := New() - if s.String() != "[]" { - t.Errorf("String: output is not what is excepted '%s'", s.String()) - } - - s.Add("1", "2", "3", "4") - if !strings.HasPrefix(s.String(), "[") { - t.Error("String: output should begin with a square bracket") - } - - if !strings.HasSuffix(s.String(), "]") { - t.Error("String: output should end with a square bracket") - } -} - -func TestSet_List(t *testing.T) { - s := New("1", "2", "3", "4") - - // this returns a slice of interface{} - if len(s.List()) != 4 { - t.Error("List: slice size should be four.") - } - - for _, item := range s.List() { - r := reflect.TypeOf(item) - if r.Kind().String() != "string" { - t.Error("List: slice item should be a string") - } - } -} - -func TestSet_Copy(t *testing.T) { - s := New("1", "2", "3", "4") - r := s.Copy() - - if !s.IsEqual(r) { - t.Error("Copy: set s and r are not equal") - } -} - -func TestSet_Merge(t *testing.T) { - s := New("1", "2", "3") - r := New("3", "4", "5") - s.Merge(r) - - if s.Size() != 5 { - t.Error("Merge: the set doesn't have all items in it.") - } - - if !s.Has("1", "2", "3", "4", "5") { - t.Error("Merge: merged items are not availabile in the set.") - } -} - -func TestSet_Separate(t *testing.T) { - s := New("1", "2", "3") - r := New("3", "5") - s.Separate(r) - - if s.Size() != 2 { - t.Error("Separate: the set doesn't have all items in it.") - } - - if !s.Has("1", "2") { - t.Error("Separate: items after separation are not availabile in the set.") - } -} - -func TestSet_RaceAdd(t *testing.T) { - // Create two sets. Add concurrently items to each of them. Remove from the - // other one. - // "go test -race" should detect this if the library is not thread-safe. - s := New() - u := New() - - go func() { - for i := 0; i < 1000; i++ { - item := "item" + strconv.Itoa(i) - go func(i int) { - s.Add(item) - u.Add(item) - }(i) - } - }() - - for i := 0; i < 1000; i++ { - item := "item" + strconv.Itoa(i) - go func(i int) { - s.Add(item) - u.Add(item) - }(i) - } -} diff --git a/Godeps/_workspace/src/gopkg.in/karalabe/cookiejar.v2/LICENSE b/Godeps/_workspace/src/gopkg.in/karalabe/cookiejar.v2/LICENSE new file mode 100644 index 000000000..467d60878 --- /dev/null +++ b/Godeps/_workspace/src/gopkg.in/karalabe/cookiejar.v2/LICENSE @@ -0,0 +1,25 @@ +Copyright (c) 2014 Péter Szilágyi. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Alternatively, the CookieJar toolbox may be used in accordance with the terms +and conditions contained in a signed written agreement between you and the +author(s). diff --git a/Godeps/_workspace/src/gopkg.in/karalabe/cookiejar.v2/collections/prque/example_test.go b/Godeps/_workspace/src/gopkg.in/karalabe/cookiejar.v2/collections/prque/example_test.go deleted file mode 100644 index 7b2e5ee84..000000000 --- a/Godeps/_workspace/src/gopkg.in/karalabe/cookiejar.v2/collections/prque/example_test.go +++ /dev/null @@ -1,44 +0,0 @@ -// CookieJar - A contestant's algorithm toolbox -// Copyright (c) 2013 Peter Szilagyi. All rights reserved. -// -// CookieJar is dual licensed: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free Software -// Foundation, either version 3 of the License, or (at your option) any later -// version. -// -// The toolbox is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -// more details. -// -// Alternatively, the CookieJar toolbox may be used in accordance with the terms -// and conditions contained in a signed written agreement between you and the -// author(s). - -package prque_test - -import ( - "fmt" - - "gopkg.in/karalabe/cookiejar.v2/collections/prque" -) - -// Insert some data into a priority queue and pop them out in prioritized order. -func Example_usage() { - // Define some data to push into the priority queue - prio := []float32{77.7, 22.2, 44.4, 55.5, 11.1, 88.8, 33.3, 99.9, 0.0, 66.6} - data := []string{"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"} - - // Create the priority queue and insert the prioritized data - pq := prque.New() - for i := 0; i < len(data); i++ { - pq.Push(data[i], prio[i]) - } - // Pop out the data and print them - for !pq.Empty() { - val, prio := pq.Pop() - fmt.Printf("%.1f:%s ", prio, val) - } - // Output: - // 99.9:seven 88.8:five 77.7:zero 66.6:nine 55.5:three 44.4:two 33.3:six 22.2:one 11.1:four 0.0:eight -} diff --git a/Godeps/_workspace/src/gopkg.in/karalabe/cookiejar.v2/collections/prque/prque_test.go b/Godeps/_workspace/src/gopkg.in/karalabe/cookiejar.v2/collections/prque/prque_test.go deleted file mode 100644 index 6a46bb807..000000000 --- a/Godeps/_workspace/src/gopkg.in/karalabe/cookiejar.v2/collections/prque/prque_test.go +++ /dev/null @@ -1,130 +0,0 @@ -// CookieJar - A contestant's algorithm toolbox -// Copyright (c) 2013 Peter Szilagyi. All rights reserved. -// -// CookieJar is dual licensed: use of this source code is governed by a BSD -// license that can be found in the LICENSE file. Alternatively, the CookieJar -// toolbox may be used in accordance with the terms and conditions contained -// in a signed written agreement between you and the author(s). - -package prque - -import ( - "math/rand" - "testing" -) - -func TestPrque(t *testing.T) { - // Generate a batch of random data and a specific priority order - size := 16 * blockSize - prio := rand.Perm(size) - data := make([]int, size) - for i := 0; i < size; i++ { - data[i] = rand.Int() - } - queue := New() - for rep := 0; rep < 2; rep++ { - // Fill a priority queue with the above data - for i := 0; i < size; i++ { - queue.Push(data[i], float32(prio[i])) - if queue.Size() != i+1 { - t.Errorf("queue size mismatch: have %v, want %v.", queue.Size(), i+1) - } - } - // Create a map the values to the priorities for easier verification - dict := make(map[float32]int) - for i := 0; i < size; i++ { - dict[float32(prio[i])] = data[i] - } - // Pop out the elements in priority order and verify them - prevPrio := float32(size + 1) - for !queue.Empty() { - val, prio := queue.Pop() - if prio > prevPrio { - t.Errorf("invalid priority order: %v after %v.", prio, prevPrio) - } - prevPrio = prio - if val != dict[prio] { - t.Errorf("push/pop mismatch: have %v, want %v.", val, dict[prio]) - } - delete(dict, prio) - } - } -} - -func TestReset(t *testing.T) { - // Generate a batch of random data and a specific priority order - size := 16 * blockSize - prio := rand.Perm(size) - data := make([]int, size) - for i := 0; i < size; i++ { - data[i] = rand.Int() - } - queue := New() - for rep := 0; rep < 2; rep++ { - // Fill a priority queue with the above data - for i := 0; i < size; i++ { - queue.Push(data[i], float32(prio[i])) - if queue.Size() != i+1 { - t.Errorf("queue size mismatch: have %v, want %v.", queue.Size(), i+1) - } - } - // Create a map the values to the priorities for easier verification - dict := make(map[float32]int) - for i := 0; i < size; i++ { - dict[float32(prio[i])] = data[i] - } - // Pop out half the elements in priority order and verify them - prevPrio := float32(size + 1) - for i := 0; i < size/2; i++ { - val, prio := queue.Pop() - if prio > prevPrio { - t.Errorf("invalid priority order: %v after %v.", prio, prevPrio) - } - prevPrio = prio - if val != dict[prio] { - t.Errorf("push/pop mismatch: have %v, want %v.", val, dict[prio]) - } - delete(dict, prio) - } - // Reset and ensure it's empty - queue.Reset() - if !queue.Empty() { - t.Errorf("priority queue not empty after reset: %v", queue) - } - } -} - -func BenchmarkPush(b *testing.B) { - // Create some initial data - data := make([]int, b.N) - prio := make([]float32, b.N) - for i := 0; i < len(data); i++ { - data[i] = rand.Int() - prio[i] = rand.Float32() - } - // Execute the benchmark - b.ResetTimer() - queue := New() - for i := 0; i < len(data); i++ { - queue.Push(data[i], prio[i]) - } -} - -func BenchmarkPop(b *testing.B) { - // Create some initial data - data := make([]int, b.N) - prio := make([]float32, b.N) - for i := 0; i < len(data); i++ { - data[i] = rand.Int() - prio[i] = rand.Float32() - } - queue := New() - for i := 0; i < len(data); i++ { - queue.Push(data[i], prio[i]) - } - // Execute the benchmark - b.ResetTimer() - for !queue.Empty() { - queue.Pop() - } -} diff --git a/Godeps/_workspace/src/gopkg.in/karalabe/cookiejar.v2/collections/prque/sstack_test.go b/Godeps/_workspace/src/gopkg.in/karalabe/cookiejar.v2/collections/prque/sstack_test.go deleted file mode 100644 index def121812..000000000 --- a/Godeps/_workspace/src/gopkg.in/karalabe/cookiejar.v2/collections/prque/sstack_test.go +++ /dev/null @@ -1,100 +0,0 @@ -// CookieJar - A contestant's algorithm toolbox -// Copyright (c) 2013 Peter Szilagyi. All rights reserved. -// -// CookieJar is dual licensed: use of this source code is governed by a BSD -// license that can be found in the LICENSE file. Alternatively, the CookieJar -// toolbox may be used in accordance with the terms and conditions contained -// in a signed written agreement between you and the author(s). - -package prque - -import ( - "math/rand" - "sort" - "testing" -) - -func TestSstack(t *testing.T) { - // Create some initial data - size := 16 * blockSize - data := make([]*item, size) - for i := 0; i < size; i++ { - data[i] = &item{rand.Int(), rand.Float32()} - } - stack := newSstack() - for rep := 0; rep < 2; rep++ { - // Push all the data into the stack, pop out every second - secs := []*item{} - for i := 0; i < size; i++ { - stack.Push(data[i]) - if i%2 == 0 { - secs = append(secs, stack.Pop().(*item)) - } - } - rest := []*item{} - for stack.Len() > 0 { - rest = append(rest, stack.Pop().(*item)) - } - // Make sure the contents of the resulting slices are ok - for i := 0; i < size; i++ { - if i%2 == 0 && data[i] != secs[i/2] { - t.Errorf("push/pop mismatch: have %v, want %v.", secs[i/2], data[i]) - } - if i%2 == 1 && data[i] != rest[len(rest)-i/2-1] { - t.Errorf("push/pop mismatch: have %v, want %v.", rest[len(rest)-i/2-1], data[i]) - } - } - } -} - -func TestSstackSort(t *testing.T) { - // Create some initial data - size := 16 * blockSize - data := make([]*item, size) - for i := 0; i < size; i++ { - data[i] = &item{rand.Int(), float32(i)} - } - // Push all the data into the stack - stack := newSstack() - for _, val := range data { - stack.Push(val) - } - // Sort and pop the stack contents (should reverse the order) - sort.Sort(stack) - for _, val := range data { - out := stack.Pop() - if out != val { - t.Errorf("push/pop mismatch after sort: have %v, want %v.", out, val) - } - } -} - -func TestSstackReset(t *testing.T) { - // Create some initial data - size := 16 * blockSize - data := make([]*item, size) - for i := 0; i < size; i++ { - data[i] = &item{rand.Int(), rand.Float32()} - } - stack := newSstack() - for rep := 0; rep < 2; rep++ { - // Push all the data into the stack, pop out every second - secs := []*item{} - for i := 0; i < size; i++ { - stack.Push(data[i]) - if i%2 == 0 { - secs = append(secs, stack.Pop().(*item)) - } - } - // Reset and verify both pulled and stack contents - stack.Reset() - if stack.Len() != 0 { - t.Errorf("stack not empty after reset: %v", stack) - } - for i := 0; i < size; i++ { - if i%2 == 0 && data[i] != secs[i/2] { - t.Errorf("push/pop mismatch: have %v, want %v.", secs[i/2], data[i]) - } - } - } -} -- cgit