You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

83 lines
2.2 KiB

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