Example #1
0
func (s *HelpersS) TestAssertNotEqualArraySucceeding(c *gocheck.C) {
	testHelperSuccess(c, "AssertNotEqual([]byte, []byte)", nil,
		func() interface{} {
			c.AssertNotEqual([]byte{1, 2}, []byte{1, 3})
			return nil
		})
}
Example #2
0
func (s *CheckersS) TestBug(c *gocheck.C) {
	bug := gocheck.Bug("a %d bc", 42)
	info := bug.GetBugInfo()
	if info != "a 42 bc" {
		c.Fatalf("Bug() returned %#v", info)
	}
}
Example #3
0
func (s *HelpersS) TestCheckNotEqualFailing(c *gocheck.C) {
	log := "helpers_test.go:[0-9]+ > helpers_test.go:[0-9]+:\n" +
		"\\.+ CheckNotEqual\\(obtained, unexpected\\):\n" +
		"\\.+ Both \\(int\\): 10\n\n"
	testHelperFailure(c, "CheckNotEqual(10, 10)", false, false, log,
		func() interface{} {
			return c.CheckNotEqual(10, 10)
		})
}
Example #4
0
func (s *HelpersS) TestCheckNotEqualArrayFailing(c *gocheck.C) {
	log := "helpers_test.go:[0-9]+ > helpers_test.go:[0-9]+:\n" +
		"\\.+ CheckNotEqual\\(obtained, unexpected\\):\n" +
		"\\.+ Both \\(\\[\\]uint8\\): \\[\\]byte{0x1, 0x2}\n\n"
	testHelperFailure(c, "CheckNotEqual([]byte{2}, []byte{3})", false, false,
		log, func() interface{} {
			return c.CheckNotEqual([]byte{1, 2}, []byte{1, 2})
		})
}
Example #5
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)
		})
}
Example #6
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)
		})
}
Example #7
0
func (s *HelpersS) TestCheckEqualFailingWithNil(c *gocheck.C) {
	log := "helpers_test.go:[0-9]+ > helpers_test.go:[0-9]+:\n" +
		"\\.+ CheckEqual\\(obtained, expected\\):\n" +
		"\\.+ Obtained \\(int\\): 10\n" +
		"\\.+ Expected \\(nil\\): nil\n\n"
	testHelperFailure(c, "CheckEqual(10, nil)", false, false, log,
		func() interface{} {
			return c.CheckEqual(10, nil)
		})
}
Example #8
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)
	}
}
Example #9
0
func (s *HelpersS) TestAssertWithNilChecker(c *gocheck.C) {
	log := "helpers_test\\.go:[0-9]+ > helpers_test\\.go:[0-9]+:\n" +
		"\\.+ Assert\\(obtained, nil!\\?, \\.\\.\\.\\):\n" +
		"\\.+ Oops\\.\\. you've provided a nil checker!\n\n"
	testHelperFailure(c, "Assert(obtained, nil)", nil, true, log,
		func() interface{} {
			c.Assert(1, nil)
			return nil
		})
}
Example #10
0
func (s *HelpersS) TestAssertNotEqualFailing(c *gocheck.C) {
	log := "helpers_test.go:[0-9]+ > helpers_test.go:[0-9]+:\n" +
		"\\.+ AssertNotEqual\\(obtained, unexpected\\):\n" +
		"\\.+ Both \\(int\\): 10\n\n"
	testHelperFailure(c, "AssertNotEqual(10, 10)", nil, true, log,
		func() interface{} {
			c.AssertNotEqual(10, 10)
			return nil
		})
}
Example #11
0
func (s *HelpersS) TestAssertNotEqualArrayFailing(c *gocheck.C) {
	log := "helpers_test.go:[0-9]+ > helpers_test.go:[0-9]+:\n" +
		"\\.+ AssertNotEqual\\(obtained, unexpected\\):\n" +
		"\\.+ Both \\(\\[\\]uint8\\): \\[\\]byte{0x1, 0x2}\n\n"
	testHelperFailure(c, "AssertNotEqual([]byte{2}, []byte{3})", nil, true,
		log, func() interface{} {
			c.AssertNotEqual([]byte{1, 2}, []byte{1, 2})
			return nil
		})
}
Example #12
0
func (s *HelpersS) TestCheckMatchFailing(c *gocheck.C) {
	log := "helpers_test.go:[0-9]+ > helpers_test.go:[0-9]+:\n" +
		"\\.+ CheckMatch\\(value, expression\\):\n" +
		"\\.+ Value \\(string\\): \"foo\"\n" +
		"\\.+ Expected to match expression: \"bar\"\n\n"
	testHelperFailure(c, "CheckMatch('foo', 'bar')", false, false, log,
		func() interface{} {
			return c.CheckMatch("foo", "bar")
		})
}
Example #13
0
func (s *HelpersS) TestCheckNotEqualWithBugInfo(c *gocheck.C) {
	log := "helpers_test.go:[0-9]+ > helpers_test.go:[0-9]+:\n" +
		"\\.+ CheckNotEqual\\(obtained, unexpected\\):\n" +
		"\\.+ Both \\(int\\): 10\n" +
		"\\.+ That's clearly WRONG!\n\n"
	testHelperFailure(c, "CheckNotEqual(10, 10, issue)", false, false, log,
		func() interface{} {
			return c.CheckNotEqual(10, 10, "That's clearly ", "WRONG!")
		})
}
Example #14
0
func testCheck(c *gocheck.C, checker gocheck.Checker,
	obtained, expected interface{},
	wantedResult bool, wantedError string) {
	result, error := checker.Check(obtained, expected)
	if result != wantedResult || error != wantedError {
		c.Fatalf("%s.Check(%#v, %#v) returned "+
			"(%#v, %#v) rather than (%#v, %#v)",
			checker.Name(), obtained, expected,
			result, error, wantedResult, wantedError)
	}
}
Example #15
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})
		})
}
Example #16
0
func (s *HelpersS) TestAssertFailWithoutExpected(c *gocheck.C) {
	checker := &MyChecker{failCheck: true, noExpectedValue: true}
	log := "helpers_test\\.go:[0-9]+ > helpers_test\\.go:[0-9]+:\n" +
		"\\.+ Assert\\(myobtained, MyChecker\\):\n" +
		"\\.+ Myobtained \\(int\\): 1\n\n"
	testHelperFailure(c, "Assert(1, checker)", nil, true, log,
		func() interface{} {
			c.Assert(1, checker)
			return nil
		})
}
Example #17
0
func (s *HelpersS) TestAssertNotEqualWithMessage(c *gocheck.C) {
	log := "helpers_test.go:[0-9]+ > helpers_test.go:[0-9]+:\n" +
		"\\.+ AssertNotEqual\\(obtained, unexpected\\):\n" +
		"\\.+ Both \\(int\\): 10\n" +
		"\\.+ That's clearly WRONG!\n\n"
	testHelperFailure(c, "AssertNotEqual(10, 10, issue)", nil, true, log,
		func() interface{} {
			c.AssertNotEqual(10, 10, "That's clearly ", "WRONG!")
			return nil
		})
}
Example #18
0
func (s *HelpersS) TestAssertSucceedWithExpected(c *gocheck.C) {
	checker := &MyChecker{}
	testHelperSuccess(c, "Assert(1, checker, 2)", nil, func() interface{} {
		c.Assert(1, checker, 2)
		return nil
	})
	if checker.obtained != 1 || checker.expected != 2 {
		c.Fatalf("Bad (obtained, expected) values for check (%d, %d)",
			checker.obtained, checker.expected)
	}
}
Example #19
0
func (s *HelpersS) TestAssertMatchFailingWithPureStrMatch(c *gocheck.C) {
	log := "helpers_test.go:[0-9]+ > helpers_test.go:[0-9]+:\n" +
		"\\.+ AssertMatch\\(value, expression\\):\n" +
		"\\.+ Value \\(string\\): \"foobar\"\n" +
		"\\.+ Expected to match expression: \"foobaz\"\n\n"
	testHelperFailure(c, "AssertMatch('foobar', 'foobaz')", nil, true, log,
		func() interface{} {
			c.AssertMatch("foobar", "foobaz")
			return nil
		})
}
Example #20
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)
		})
}
Example #21
0
func (s *HelpersS) TestAssertMatchFailing(c *gocheck.C) {
	log := "helpers_test.go:[0-9]+ > helpers_test.go:[0-9]+:\n" +
		"\\.+ AssertMatch\\(value, expression\\):\n" +
		"\\.+ Value \\(os\\.Errno\\): 13 \\(permission denied\\)\n" +
		"\\.+ Expected to match expression: \"foo\"\n\n"
	testHelperFailure(c, "AssertMatch(error, foo)", nil, true, log,
		func() interface{} {
			c.AssertMatch(os.Errno(13), "foo")
			return nil
		})
}
Example #22
0
func (s *HelpersS) TestAssertWithMissingExpected(c *gocheck.C) {
	checker := &MyChecker{failCheck: true}
	log := "helpers_test\\.go:[0-9]+ > helpers_test\\.go:[0-9]+:\n" +
		"\\.+ Assert\\(myobtained, MyChecker, >myexpected<\\):\n" +
		"\\.+ Wrong number of myexpected args for MyChecker: " +
		"want 1, got 0\n\n"
	testHelperFailure(c, "Assert(1, checker, !?)", nil, true, log,
		func() interface{} {
			c.Assert(1, checker)
			return nil
		})
}
Example #23
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!"))
		})
}
Example #24
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)
		})
}
Example #25
0
func (s *HelpersS) TestAssertWithError(c *gocheck.C) {
	checker := &MyChecker{checkError: "Some not so cool data provided!"}
	log := "helpers_test\\.go:[0-9]+ > helpers_test\\.go:[0-9]+:\n" +
		"\\.+ Assert\\(myobtained, MyChecker, myexpected\\):\n" +
		"\\.+ Myobtained \\(int\\): 1\n" +
		"\\.+ Myexpected \\(int\\): 2\n" +
		"\\.+ Some not so cool data provided!\n\n"
	testHelperFailure(c, "Assert(1, checker, 2)", nil, true, log,
		func() interface{} {
			c.Assert(1, checker, 2)
			return nil
		})
}
Example #26
0
func (s *HelpersS) TestAssertFailWithExpectedAndMessage(c *gocheck.C) {
	checker := &MyChecker{failCheck: true}
	log := "helpers_test\\.go:[0-9]+ > helpers_test\\.go:[0-9]+:\n" +
		"\\.+ Assert\\(myobtained, MyChecker, myexpected\\):\n" +
		"\\.+ Myobtained \\(int\\): 1\n" +
		"\\.+ Myexpected \\(int\\): 2\n" +
		"\\.+ Hello world!\n\n"
	testHelperFailure(c, "Assert(1, checker, 2, msg)", nil, true, log,
		func() interface{} {
			c.Assert(1, checker, 2, myBug("Hello world!"))
			return nil
		})
}
Example #27
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)
}
Example #28
0
func testHelperFailure(c *gocheck.C, name string,
	expectedResult interface{},
	shouldStop bool, log string,
	closure func() interface{}) {
	var result interface{}
	defer (func() {
		if err := recover(); err != nil {
			panic(err)
		}
		checkState(c, result,
			&expectedState{
				name:   name,
				result: expectedResult,
				failed: true,
				log:    log,
			})
	})()
	result = closure()
	if shouldStop {
		c.Logf("%s didn't stop when it should", name)
	}
}
Example #29
0
func testInfo(c *gocheck.C, checker gocheck.Checker,
	name, obtainedVarName, expectedVarName string) {
	if checker.Name() != name {
		c.Fatalf("Got name %s, expected %s", checker.Name(), name)
	}
	obtainedName, expectedName := checker.VarNames()
	if obtainedName != obtainedVarName {
		c.Fatalf("Got obtained label %#v, expected %#v",
			obtainedName, obtainedVarName)
	}
	if expectedName != expectedVarName {
		c.Fatalf("Got expected label %#v, expected %#v",
			expectedName, expectedVarName)
	}
}
Example #30
0
func (s *MkDirHelper) Test(c *gocheck.C) {
	s.path2 = c.MkDir()
	s.isDir2 = isDir(s.path2)
}