launchpad.net/gocheck@v0.0.0-20140225173054-000000000087/bootstrap_test.go (about) 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 gocheck_test 14 15 import ( 16 "fmt" 17 "launchpad.net/gocheck" 18 "strings" 19 ) 20 21 type BootstrapS struct{} 22 23 var boostrapS = gocheck.Suite(&BootstrapS{}) 24 25 func (s *BootstrapS) TestCountSuite(c *gocheck.C) { 26 suitesRun += 1 27 } 28 29 func (s *BootstrapS) TestFailedAndFail(c *gocheck.C) { 30 if c.Failed() { 31 critical("c.Failed() must be false first!") 32 } 33 c.Fail() 34 if !c.Failed() { 35 critical("c.Fail() didn't put the test in a failed state!") 36 } 37 c.Succeed() 38 } 39 40 func (s *BootstrapS) TestFailedAndSucceed(c *gocheck.C) { 41 c.Fail() 42 c.Succeed() 43 if c.Failed() { 44 critical("c.Succeed() didn't put the test back in a non-failed state") 45 } 46 } 47 48 func (s *BootstrapS) TestLogAndGetTestLog(c *gocheck.C) { 49 c.Log("Hello there!") 50 log := c.GetTestLog() 51 if log != "Hello there!\n" { 52 critical(fmt.Sprintf("Log() or GetTestLog() is not working! Got: %#v", log)) 53 } 54 } 55 56 func (s *BootstrapS) TestLogfAndGetTestLog(c *gocheck.C) { 57 c.Logf("Hello %v", "there!") 58 log := c.GetTestLog() 59 if log != "Hello there!\n" { 60 critical(fmt.Sprintf("Logf() or GetTestLog() is not working! Got: %#v", log)) 61 } 62 } 63 64 func (s *BootstrapS) TestRunShowsErrors(c *gocheck.C) { 65 output := String{} 66 gocheck.Run(&FailHelper{}, &gocheck.RunConf{Output: &output}) 67 if strings.Index(output.value, "Expected failure!") == -1 { 68 critical(fmt.Sprintf("RunWithWriter() output did not contain the "+ 69 "expected failure! Got: %#v", 70 output.value)) 71 } 72 } 73 74 func (s *BootstrapS) TestRunDoesntShowSuccesses(c *gocheck.C) { 75 output := String{} 76 gocheck.Run(&SuccessHelper{}, &gocheck.RunConf{Output: &output}) 77 if strings.Index(output.value, "Expected success!") != -1 { 78 critical(fmt.Sprintf("RunWithWriter() output contained a successful "+ 79 "test! Got: %#v", 80 output.value)) 81 } 82 }