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) 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) 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) 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) 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) 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) 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) }) }
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) 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) 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) 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) 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") }) }
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 *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 *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, "") }
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 (s *HelpersS) TestCheckerInterface(c *check.C) { testHelperSuccess(c, "Check(1, Equals, 1)", true, func() interface{} { return c.Check(1, check.Equals, 1) }) }
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 }
// 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() }