Esempio n. 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
		})
}
Esempio n. 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)
	}
}
Esempio n. 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)
		})
}
Esempio n. 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})
		})
}
Esempio n. 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)
		})
}
Esempio n. 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)
		})
}
Esempio n. 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)
		})
}
Esempio n. 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)
	}
}
Esempio n. 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
		})
}
Esempio n. 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
		})
}
Esempio n. 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
		})
}
Esempio n. 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")
		})
}
Esempio n. 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!")
		})
}
Esempio n. 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)
	}
}
Esempio n. 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})
		})
}
Esempio n. 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
		})
}
Esempio n. 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
		})
}
Esempio n. 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)
	}
}
Esempio n. 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
		})
}
Esempio n. 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)
		})
}
Esempio n. 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
		})
}
Esempio n. 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
		})
}
Esempio n. 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!"))
		})
}
Esempio n. 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)
		})
}
Esempio n. 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
		})
}
Esempio n. 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
		})
}
Esempio n. 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)
}
Esempio n. 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)
	}
}
Esempio n. 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)
	}
}
Esempio n. 30
0
func (s *MkDirHelper) Test(c *gocheck.C) {
	s.path2 = c.MkDir()
	s.isDir2 = isDir(s.path2)
}