Ejemplo n.º 1
0
func (s *HelpersS) TestCheckWithNilChecker(c *gocheck.C) {
	log := "helpers_test\\.go:[0-9]+ > helpers_test\\.go:[0-9]+:\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)
		})
}
Ejemplo n.º 2
0
func (s *HelpersS) TestCheckSucceedWithoutExpected(c *gocheck.C) {
	checker := &MyChecker{noExpectedValue: true}
	testHelperSuccess(c, "Check(1, checker)", true, func() interface{} {
		return c.Check(1, checker)
	})
	if checker.obtained != 1 || checker.expected != nil {
		c.Fatalf("Bad (obtained, expected) values for check (%d, %d)",
			checker.obtained, checker.expected)
	}
}
Ejemplo n.º 3
0
func (s *HelpersS) TestCheckFailWithoutExpected(c *gocheck.C) {
	checker := &MyChecker{failCheck: true, noExpectedValue: true}
	log := "helpers_test\\.go:[0-9]+ > helpers_test\\.go:[0-9]+:\n" +
		"\\.+ Check\\(myobtained, MyChecker\\):\n" +
		"\\.+ Myobtained \\(int\\): 1\n\n"
	testHelperFailure(c, "Check(1, checker)", false, false, log,
		func() interface{} {
			return c.Check(1, checker)
		})
}
Ejemplo n.º 4
0
func (s *HelpersS) TestValueLoggingWithArrays(c *gocheck.C) {
	checker := &MyChecker{failCheck: true}
	log := "helpers_test.go:[0-9]+ > helpers_test.go:[0-9]+:\n" +
		"\\.+ Check\\(myobtained, MyChecker, myexpected\\):\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})
		})
}
Ejemplo n.º 5
0
func (s *HelpersS) TestCheckWithTooManyExpected(c *gocheck.C) {
	checker := &MyChecker{noExpectedValue: true}
	log := "helpers_test\\.go:[0-9]+ > helpers_test\\.go:[0-9]+:\n" +
		"\\.+ Check\\(myobtained, MyChecker, >myexpected<\\):\n" +
		"\\.+ Wrong number of myexpected args for MyChecker: " +
		"want 0, got 1\n\n"
	testHelperFailure(c, "Check(1, checker, !?)", false, false, log,
		func() interface{} {
			return c.Check(1, checker, 1)
		})
}
Ejemplo n.º 6
0
func (s *HelpersS) TestCheckWithError(c *gocheck.C) {
	checker := &MyChecker{checkError: "Some not so cool data provided!"}
	log := "helpers_test\\.go:[0-9]+ > helpers_test\\.go:[0-9]+:\n" +
		"\\.+ Check\\(myobtained, MyChecker, myexpected\\):\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)
		})
}
Ejemplo n.º 7
0
func (s *HelpersS) TestCheckFailWithExpectedAndBugInfo(c *gocheck.C) {
	checker := &MyChecker{failCheck: true}
	log := "helpers_test\\.go:[0-9]+ > helpers_test\\.go:[0-9]+:\n" +
		"\\.+ Check\\(myobtained, MyChecker, myexpected\\):\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, myBug("Hello world!"))
		})
}
Ejemplo n.º 8
0
func (s *HelpersS) TestMkDir(c *gocheck.C) {
	helper := MkDirHelper{}
	output := String{}
	gocheck.Run(&helper, &gocheck.RunConf{Output: &output})
	c.Assert(output.value, gocheck.Equals, "")
	c.Check(helper.isDir1, gocheck.Equals, true)
	c.Check(helper.isDir2, gocheck.Equals, true)
	c.Check(helper.isDir3, gocheck.Equals, true)
	c.Check(helper.isDir4, gocheck.Equals, true)
	c.Check(helper.path1, gocheck.Not(gocheck.Equals),
		helper.path2)
	c.Check(isDir(helper.path1), gocheck.Equals, false)
	c.Check(isDir(helper.path2), gocheck.Equals, false)
}
Ejemplo n.º 9
0
func (s *HelpersS) TestCheckerInterface(c *gocheck.C) {
	testHelperSuccess(c, "Check(1, Equals, 1)", true, func() interface{} {
		return c.Check(1, gocheck.Equals, 1)
	})
}
Ejemplo n.º 10
0
// Trivial wrapper to test errors happening on a different file
// than the test itself.
func checkEqualWrapper(c *gocheck.C,
	expected interface{},
	obtained interface{}) (result bool, line int) {
	return c.Check(expected, gocheck.Equals, obtained), getMyLine()
}