Removed obsolete Assert*(a, b) helper methods. Use the new checker-based
methods Assert(...) and Check(...) instead.
diff --git a/helpers.go b/helpers.go
index be76484..bc364cb 100644
--- a/helpers.go
+++ b/helpers.go
@@ -2,11 +2,8 @@
import (
- "reflect"
"strings"
- "regexp"
"fmt"
- "os"
)
@@ -112,162 +109,6 @@
// -----------------------------------------------------------------------
-// Equality testing.
-
-// Verify if the first value is equal to the second value. In case
-// they're not equal, an error will be logged, the test will be marked as
-// failed, and the test execution will continue. The extra arguments are
-// optional and, if provided, will be assembled together with fmt.Sprint()
-// and printed next to the reported problem in case of errors. The returned
-// value will be false in case the verification fails.
-func (c *C) CheckEqual(obtained interface{}, expected interface{},
- issue ...interface{}) bool {
- summary := "CheckEqual(obtained, expected):"
- return c.internalCheckEqual(obtained, expected, true, summary, issue...)
-}
-
-// Verify if the first value is not equal to the second value. In case
-// they are equal, an error will be logged, the test will be marked as
-// failed, and the test execution will continue. The extra arguments are
-// optional and, if provided, will be assembled together with fmt.Sprint()
-// and printed next to the reported problem in case of errors. The returned
-// value will be false in case the verification fails.
-func (c *C) CheckNotEqual(obtained interface{}, expected interface{},
- issue ...interface{}) bool {
- summary := "CheckNotEqual(obtained, unexpected):"
- return c.internalCheckEqual(obtained, expected, false, summary, issue...)
-}
-
-// Ensure that the first value is equal to the second value. In case
-// they're not equal, an error will be logged, the test will be marked as
-// failed, and the test execution will stop. The extra arguments are
-// optional and, if provided, will be assembled together with fmt.Sprint()
-// and printed next to the reported problem in case of errors.
-func (c *C) AssertEqual(obtained interface{}, expected interface{},
- issue ...interface{}) {
- summary := "AssertEqual(obtained, expected):"
- if !c.internalCheckEqual(obtained, expected, true, summary, issue...) {
- c.stopNow()
- }
-}
-
-// Ensure that the first value is not equal to the second value. In case
-// they are equal, an error will be logged, the test will be marked as
-// failed, and the test execution will stop. The extra arguments are
-// optional and, if provided, will be assembled together with fmt.Sprint()
-// and printed next to the reported problem in case of errors.
-func (c *C) AssertNotEqual(obtained interface{}, expected interface{},
- issue ...interface{}) {
- summary := "AssertNotEqual(obtained, unexpected):"
- if !c.internalCheckEqual(obtained, expected, false, summary, issue...) {
- c.stopNow()
- }
-}
-
-
-var usedDeprecatedChecks = false
-
-func (c *C) internalCheckEqual(a interface{}, b interface{}, equal bool,
- summary string, issue ...interface{}) bool {
- usedDeprecatedChecks = true
- typeA := reflect.Typeof(a)
- typeB := reflect.Typeof(b)
- if (typeA == typeB && checkEqual(a, b)) != equal {
- c.logCaller(2, summary)
- if equal {
- c.logValue("Obtained", a)
- c.logValue("Expected", b)
- } else {
- c.logValue("Both", a)
- }
- if len(issue) != 0 {
- c.logString(fmt.Sprint(issue...))
- }
- c.logNewLine()
- c.Fail()
- return false
- }
- return true
-}
-
-// This will use a fast path to check for equality of normal types,
-// and then fallback to reflect.DeepEqual if things go wrong.
-func checkEqual(a interface{}, b interface{}) (result bool) {
- defer func() {
- if recover() != nil {
- result = reflect.DeepEqual(a, b)
- }
- }()
- return (a == b)
-}
-
-
-// -----------------------------------------------------------------------
-// String matching testing.
-
-// Verify if the value provided matches with the given regular expression.
-// The value must be either a string, or a value which provides the String()
-// method. In case it doesn't match, an error will be logged, the test will
-// be marked as failed, and the test execution will continue. The extra
-// arguments are optional and, if provided, will be assembled together with
-// fmt.Sprint() and printed next to the reported problem in case of errors.
-func (c *C) CheckMatch(value interface{}, expression string,
- issue ...interface{}) bool {
- summary := "CheckMatch(value, expression):"
- return c.internalCheckMatch(value, expression, true, summary, issue...)
-}
-
-// Ensure that the value provided matches with the given regular expression.
-// The value must be either a string, or a value which provides the String()
-// method. In case it doesn't match, an error will be logged, the test will
-// be marked as failed, and the test execution will stop. The extra
-// arguments are optional and, if provided, will be assembled together with
-// fmt.Sprint() and printed next to the reported problem in case of errors.
-func (c *C) AssertMatch(value interface{}, expression string,
- issue ...interface{}) {
- summary := "AssertMatch(value, expression):"
- if !c.internalCheckMatch(value, expression, true, summary, issue...) {
- c.stopNow()
- }
-}
-
-func (c *C) internalCheckMatch(value interface{}, expression string,
- equal bool, summary string,
- issue ...interface{}) bool {
- usedDeprecatedChecks = true
- valueStr, valueIsStr := value.(string)
- if !valueIsStr {
- if valueWithStr, valueHasStr := value.(hasString); valueHasStr {
- valueStr, valueIsStr = valueWithStr.String(), true
- }
- }
- var err os.Error
- var matches bool
- if valueIsStr {
- matches, err = regexp.MatchString("^" + expression + "$", valueStr)
- }
- if !matches || err != nil {
- c.logCaller(2, summary)
- var msg string
- if !matches {
- c.logValue("Value", value)
- msg = fmt.Sprintf("Expected to match expression: %#v", expression)
- } else {
- msg = fmt.Sprintf("Can't compile match expression: %#v", expression)
- }
- c.logString(msg)
- if len(issue) != 0 {
- c.logString(fmt.Sprint(issue...))
- }
- c.logNewLine()
- c.Fail()
- return false
- }
- return true
-}
-
-
-// -----------------------------------------------------------------------
// Generic checks and assertions based on checkers.
// Verify if the first value matches with the expected value. What
diff --git a/helpers_test.go b/helpers_test.go
index dbf86f6..3be97a5 100644
--- a/helpers_test.go
+++ b/helpers_test.go
@@ -325,306 +325,6 @@
// -----------------------------------------------------------------------
-// Old tests for Assert*() and Check*() helpers not based on checkers.
-
-func (s *HelpersS) TestCheckEqualFailing(c *gocheck.C) {
- log := "helpers_test.go:[0-9]+ > helpers_test.go:[0-9]+:\n" +
- "\\.+ CheckEqual\\(obtained, expected\\):\n" +
- "\\.+ Obtained \\(int\\): 10\n" +
- "\\.+ Expected \\(int\\): 20\n\n"
- testHelperFailure(c, "CheckEqual(10, 20)", false, false, log,
- func() interface{} {
- return c.CheckEqual(10, 20)
- })
-}
-
-func (s *HelpersS) TestCheckEqualFailingWithDiffTypes(c *gocheck.C) {
- log := "helpers_test.go:[0-9]+ > helpers_test.go:[0-9]+:\n" +
- "\\.+ CheckEqual\\(obtained, expected\\):\n" +
- "\\.+ Obtained \\(int\\): 10\n" +
- "\\.+ Expected \\(uint\\): 0xa\n\n"
- testHelperFailure(c, "CheckEqual(10, uint(10))", false, false, log,
- func() interface{} {
- return c.CheckEqual(10, uint(10))
- })
-}
-
-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)
- })
-}
-
-func (s *HelpersS) TestCheckEqualWithBugInfo(c *gocheck.C) {
- log := "helpers_test.go:[0-9]+ > helpers_test.go:[0-9]+:\n" +
- "\\.+ CheckEqual\\(obtained, expected\\):\n" +
- "\\.+ Obtained \\(int\\): 10\n" +
- "\\.+ Expected \\(int\\): 20\n" +
- "\\.+ That's clearly WRONG!\n\n"
- testHelperFailure(c, "CheckEqual(10, 20, issue)", false, false, log,
- func() interface{} {
- return c.CheckEqual(10, 20, "That's clearly ", "WRONG!")
- })
-}
-
-func (s *HelpersS) TestCheckNotEqualSucceeding(c *gocheck.C) {
- testHelperSuccess(c, "CheckNotEqual(10, 20)", true, func() interface{} {
- return c.CheckNotEqual(10, 20)
- })
-}
-
-func (s *HelpersS) TestCheckNotEqualSucceedingWithNil(c *gocheck.C) {
- testHelperSuccess(c, "CheckNotEqual(10, nil)", true, func() interface{} {
- return c.CheckNotEqual(10, nil)
- })
-}
-
-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)
- })
-}
-
-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!")
- })
-}
-
-func (s *HelpersS) TestAssertEqualSucceeding(c *gocheck.C) {
- testHelperSuccess(c, "AssertEqual(10, 10)", nil, func() interface{} {
- c.AssertEqual(10, 10)
- return nil
- })
-}
-
-func (s *HelpersS) TestAssertEqualFailing(c *gocheck.C) {
- log := "helpers_test.go:[0-9]+ > helpers_test.go:[0-9]+:\n" +
- "\\.+ AssertEqual\\(obtained, expected\\):\n" +
- "\\.+ Obtained \\(int\\): 10\n" +
- "\\.+ Expected \\(int\\): 20\n\n"
- testHelperFailure(c, "AssertEqual(10, 20)", nil, true, log,
- func() interface{} {
- c.AssertEqual(10, 20)
- return nil
- })
-}
-
-func (s *HelpersS) TestAssertEqualWithMessage(c *gocheck.C) {
- log := "helpers_test.go:[0-9]+ > helpers_test.go:[0-9]+:\n" +
- "\\.+ AssertEqual\\(obtained, expected\\):\n" +
- "\\.+ Obtained \\(int\\): 10\n" +
- "\\.+ Expected \\(int\\): 20\n" +
- "\\.+ That's clearly WRONG!\n\n"
- testHelperFailure(c, "AssertEqual(10, 20, issue)", nil, true, log,
- func() interface{} {
- c.AssertEqual(10, 20, "That's clearly ", "WRONG!")
- return nil
- })
-}
-
-func (s *HelpersS) TestAssertNotEqualSucceeding(c *gocheck.C) {
- testHelperSuccess(c, "AssertNotEqual(10, 20)", nil, func() interface{} {
- c.AssertNotEqual(10, 20)
- return nil
- })
-}
-
-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
- })
-}
-
-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
- })
-}
-
-
-func (s *HelpersS) TestCheckEqualArraySucceeding(c *gocheck.C) {
- testHelperSuccess(c, "CheckEqual([]byte, []byte)", true, func() interface{} {
- return c.CheckEqual([]byte{1,2}, []byte{1,2})
- })
-}
-
-func (s *HelpersS) TestCheckEqualArrayFailing(c *gocheck.C) {
- log := "helpers_test.go:[0-9]+ > helpers_test.go:[0-9]+:\n" +
- "\\.+ CheckEqual\\(obtained, expected\\):\n" +
- "\\.+ Obtained \\(\\[\\]uint8\\): \\[\\]byte{0x1, 0x2}\n" +
- "\\.+ Expected \\(\\[\\]uint8\\): \\[\\]byte{0x1, 0x3}\n\n"
- testHelperFailure(c, "CheckEqual([]byte{2}, []byte{3})", false, false, log,
- func() interface{} {
- return c.CheckEqual([]byte{1,2}, []byte{1,3})
- })
-}
-
-func (s *HelpersS) TestCheckNotEqualArraySucceeding(c *gocheck.C) {
- testHelperSuccess(c, "CheckNotEqual([]byte, []byte)", true,
- func() interface{} {
- return c.CheckNotEqual([]byte{1,2}, []byte{1,3})
- })
-}
-
-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})
- })
-}
-
-
-func (s *HelpersS) TestAssertEqualArraySucceeding(c *gocheck.C) {
- testHelperSuccess(c, "AssertEqual([]byte, []byte)", nil,
- func() interface{} {
- c.AssertEqual([]byte{1,2}, []byte{1,2})
- return nil
- })
-}
-
-func (s *HelpersS) TestAssertEqualArrayFailing(c *gocheck.C) {
- log := "helpers_test.go:[0-9]+ > helpers_test.go:[0-9]+:\n" +
- "\\.+ AssertEqual\\(obtained, expected\\):\n" +
- "\\.+ Obtained \\(\\[\\]uint8\\): \\[\\]byte{0x1, 0x2}\n" +
- "\\.+ Expected \\(\\[\\]uint8\\): \\[\\]byte{0x1, 0x3}\n\n"
- testHelperFailure(c, "AssertEqual([]byte{2}, []byte{3})", nil, true, log,
- func() interface{} {
- c.AssertEqual([]byte{1,2}, []byte{1,3})
- return nil
- })
-}
-
-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
- })
-}
-
-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
- })
-}
-
-func (s *HelpersS) TestCheckMatchSucceeding(c *gocheck.C) {
- testHelperSuccess(c, "CheckErr('foo', 'fo*')", true, func() interface{} {
- return c.CheckMatch("foo", "fo*")
- })
-}
-
-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")
- })
-}
-
-func (s *HelpersS) TestCheckMatchFailingWithMessage(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" +
- "\\.+ Foo bar!\n\n"
- testHelperFailure(c, "CheckMatch('foo', 'bar')", false, false, log,
- func() interface{} {
- return c.CheckMatch("foo", "bar", "Foo", " bar!")
- })
-}
-
-
-func (s *HelpersS) TestAssertMatchSucceeding(c *gocheck.C) {
- testHelperSuccess(c, "AssertMatch(s, exp)", nil, func() interface{} {
- c.AssertMatch("str error", "str.*r")
- return nil
- })
-}
-
-func (s *HelpersS) TestAssertMatchSucceedingWithError(c *gocheck.C) {
- testHelperSuccess(c, "AssertMatch(os.Error, exp)", nil, func() interface{} {
- c.AssertMatch(os.Errno(13), "perm.*denied")
- return nil
- })
-}
-
-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
- })
-}
-
-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
- })
-}
-
-func (s *HelpersS) TestAssertMatchFailingWithMessage(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" +
- "\\.+ That's clearly WRONG!\n\n"
- testHelperFailure(c, "AssertMatch('foobar', 'foobaz')", nil, true, log,
- func() interface{} {
- c.AssertMatch("foobar", "foobaz", "That's clearly ", "WRONG!")
- return nil
- })
-}
-
-
-// -----------------------------------------------------------------------
// MakeDir() tests.
type MkDirHelper struct {
diff --git a/run.go b/run.go
index e4a6e7f..a32c145 100644
--- a/run.go
+++ b/run.go
@@ -36,14 +36,6 @@
func TestingT(testingT *testing.T) {
result := RunAll(&RunConf{Filter: *filterFlag, Verbose: *verboseFlag})
println(result.String())
- if usedDeprecatedChecks {
- println("WARNING: The Check/AssertEqual() and Check/AssertMatch() " +
- "family of functions\n is deprecated, and will be " +
- "removed in the future. Assert() and\n Check() " +
- "are both more comfortable and more powerful. See the\n" +
- " documentation at http://labix.org/gocheck for " +
- "more details.\n")
- }
if !result.Passed() {
testingT.Fail()
}