| 1 | // These initial tests are for bootstrapping. They verify that we can |
| 2 | // basically use the testing infrastructure itself to check if the test |
| 3 | // system is working. |
| 4 | // |
| 5 | // These tests use will break down the test runner badly in case of |
| 6 | // errors because if they simply fail, we can't be sure the developer |
| 7 | // will ever see anything (because failing means the failing system |
| 8 | // somehow isn't working! :-) |
| 9 | // |
| 10 | // Do not assume *any* internal functionality works as expected besides |
| 11 | // what's actually tested here. |
| 12 | |
| 13 | package check_test |
| 14 | |
| 15 | import ( |
| 16 | "fmt" |
| 17 | "strings" |
| 18 | |
| 19 | "github.com/pingcap/check" |
| 20 | ) |
| 21 | |
| 22 | type BootstrapS struct{} |
| 23 | |
| 24 | var boostrapS = check.Suite(&BootstrapS{}) |
| 25 | |
| 26 | func (s *BootstrapS) TestCountSuite(c *check.C) { |
| 27 | suitesRun += 1 |
| 28 | } |
| 29 | |
| 30 | func (s *BootstrapS) TestFailedAndFail(c *check.C) { |
| 31 | if c.Failed() { |
| 32 | critical("c.Failed() must be false first!") |
| 33 | } |
| 34 | c.Fail() |
| 35 | if !c.Failed() { |
| 36 | critical("c.Fail() didn't put the test in a failed state!") |
| 37 | } |
| 38 | c.Succeed() |
| 39 | } |
| 40 | |
| 41 | func (s *BootstrapS) TestFailedAndSucceed(c *check.C) { |
| 42 | c.Fail() |
| 43 | c.Succeed() |
| 44 | if c.Failed() { |
| 45 | critical("c.Succeed() didn't put the test back in a non-failed state") |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | func (s *BootstrapS) TestLogAndGetTestLog(c *check.C) { |
| 50 | c.Log("Hello there!") |
| 51 | log := c.GetTestLog() |
| 52 | if log != "Hello there!\n" { |
| 53 | critical(fmt.Sprintf("Log() or GetTestLog() is not working! Got: %#v", log)) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | func (s *BootstrapS) TestLogfAndGetTestLog(c *check.C) { |
| 58 | c.Logf("Hello %v", "there!") |
| 59 | log := c.GetTestLog() |
| 60 | if log != "Hello there!\n" { |
| 61 | critical(fmt.Sprintf("Logf() or GetTestLog() is not working! Got: %#v", log)) |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | func (s *BootstrapS) TestRunShowsErrors(c *check.C) { |
| 66 | output := String{} |
| 67 | check.Run(&FailHelper{}, &check.RunConf{Output: &output}) |
| 68 | if strings.Index(output.value, "Expected failure!") == -1 { |
| 69 | critical(fmt.Sprintf("RunWithWriter() output did not contain the "+ |
| 70 | "expected failure! Got: %#v", |
| 71 | output.value)) |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | func (s *BootstrapS) TestRunDoesntShowSuccesses(c *check.C) { |
| 76 | output := String{} |
| 77 | check.Run(&SuccessHelper{}, &check.RunConf{Output: &output}) |
| 78 | if strings.Index(output.value, "Expected success!") != -1 { |
| 79 | critical(fmt.Sprintf("RunWithWriter() output contained a successful "+ |
| 80 | "test! Got: %#v", |
| 81 | output.value)) |
| 82 | } |
| 83 | } |