当前位置: 首页>>代码示例>>Golang>>正文


Golang C.Assert方法代码示例

本文整理汇总了Golang中github.com/shaunduncan/gocheck.C.Assert方法的典型用法代码示例。如果您正苦于以下问题:Golang C.Assert方法的具体用法?Golang C.Assert怎么用?Golang C.Assert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/shaunduncan/gocheck.C的用法示例。


在下文中一共展示了C.Assert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestPanics

func (s *CheckersS) TestPanics(c *gocheck.C) {
	testInfo(c, gocheck.Panics, "Panics", []string{"function", "expected"})

	// Some errors.
	testCheck(c, gocheck.Panics, false, "Function has not panicked", func() bool { return false }, "BOOM")
	testCheck(c, gocheck.Panics, false, "Function must take zero arguments", 1, "BOOM")

	// Plain strings.
	testCheck(c, gocheck.Panics, true, "", func() { panic("BOOM") }, "BOOM")
	testCheck(c, gocheck.Panics, false, "", func() { panic("KABOOM") }, "BOOM")
	testCheck(c, gocheck.Panics, true, "", func() bool { panic("BOOM") }, "BOOM")

	// Error values.
	testCheck(c, gocheck.Panics, true, "", func() { panic(errors.New("BOOM")) }, errors.New("BOOM"))
	testCheck(c, gocheck.Panics, false, "", func() { panic(errors.New("KABOOM")) }, errors.New("BOOM"))

	type deep struct{ i int }
	// Deep value
	testCheck(c, gocheck.Panics, true, "", func() { panic(&deep{99}) }, &deep{99})

	// Verify params/names mutation
	params, names := testCheck(c, gocheck.Panics, false, "", func() { panic(errors.New("KABOOM")) }, errors.New("BOOM"))
	c.Assert(params[0], gocheck.ErrorMatches, "KABOOM")
	c.Assert(names[0], gocheck.Equals, "panic")

	// Verify a nil panic
	testCheck(c, gocheck.Panics, true, "", func() { panic(nil) }, nil)
	testCheck(c, gocheck.Panics, false, "", func() { panic(nil) }, "NOPE")
}
开发者ID:shaunduncan,项目名称:gocheck,代码行数:29,代码来源:checkers_test.go

示例2: TestExpectFailureSucceed

func (s *FoundationS) TestExpectFailureSucceed(c *gocheck.C) {
	helper := ExpectFailureSucceedHelper{}
	output := String{}
	result := gocheck.Run(&helper, &gocheck.RunConf{Output: &output})

	c.Assert(output.value, gocheck.Equals, "")
	c.Assert(result.ExpectedFailures, gocheck.Equals, 1)
}
开发者ID:shaunduncan,项目名称:gocheck,代码行数:8,代码来源:foundation_test.go

示例3: TestAssertSucceedWithoutExpected

func (s *HelpersS) TestAssertSucceedWithoutExpected(c *gocheck.C) {
	checker := &MyChecker{result: true, info: &gocheck.CheckerInfo{Params: []string{"myvalue"}}}
	testHelperSuccess(c, "Assert(1, checker)", nil, func() interface{} {
		c.Assert(1, checker)
		return nil
	})
	if !reflect.DeepEqual(checker.params, []interface{}{1}) {
		c.Fatalf("Bad params for check: %#v", checker.params)
	}
}
开发者ID:shaunduncan,项目名称:gocheck,代码行数:10,代码来源:helpers_test.go

示例4: TestAssertSucceedWithExpected

func (s *HelpersS) TestAssertSucceedWithExpected(c *gocheck.C) {
	checker := &MyChecker{result: true}
	testHelperSuccess(c, "Assert(1, checker, 2)", nil, func() interface{} {
		c.Assert(1, checker, 2)
		return nil
	})
	if !reflect.DeepEqual(checker.params, []interface{}{1, 2}) {
		c.Fatalf("Bad params for check: %#v", checker.params)
	}
}
开发者ID:shaunduncan,项目名称:gocheck,代码行数:10,代码来源:helpers_test.go

示例5: TestAssertWithNilChecker

func (s *HelpersS) TestAssertWithNilChecker(c *gocheck.C) {
	log := "(?s)helpers_test\\.go:[0-9]+:.*\nhelpers_test\\.go:[0-9]+:\n" +
		"    c\\.Assert\\(1, nil\\)\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
		})
}
开发者ID:shaunduncan,项目名称:gocheck,代码行数:11,代码来源:helpers_test.go

示例6: TestAssertFailWithoutExpected

func (s *HelpersS) TestAssertFailWithoutExpected(c *gocheck.C) {
	checker := &MyChecker{result: false, info: &gocheck.CheckerInfo{Params: []string{"myvalue"}}}
	log := "(?s)helpers_test\\.go:[0-9]+:.*\nhelpers_test\\.go:[0-9]+:\n" +
		"    c\\.Assert\\(1, checker\\)\n" +
		"\\.+ myvalue int = 1\n\n"
	testHelperFailure(c, "Assert(1, checker)", nil, true, log,
		func() interface{} {
			c.Assert(1, checker)
			return nil
		})
}
开发者ID:shaunduncan,项目名称:gocheck,代码行数:11,代码来源:helpers_test.go

示例7: TestAssertFailWithExpected

func (s *HelpersS) TestAssertFailWithExpected(c *gocheck.C) {
	checker := &MyChecker{result: false}
	log := "(?s)helpers_test\\.go:[0-9]+:.*\nhelpers_test\\.go:[0-9]+:\n" +
		"    c\\.Assert\\(1, checker, 2\\)\n" +
		"\\.+ myobtained int = 1\n" +
		"\\.+ myexpected int = 2\n\n"
	testHelperFailure(c, "Assert(1, checker, 2)", nil, true, log,
		func() interface{} {
			c.Assert(1, checker, 2)
			return nil
		})
}
开发者ID:shaunduncan,项目名称:gocheck,代码行数:12,代码来源:helpers_test.go

示例8: TestErrorMatches

func (s *CheckersS) TestErrorMatches(c *gocheck.C) {
	testInfo(c, gocheck.ErrorMatches, "ErrorMatches", []string{"value", "regex"})

	testCheck(c, gocheck.ErrorMatches, false, "Error value is nil", nil, "some error")
	testCheck(c, gocheck.ErrorMatches, false, "Value is not an error", 1, "some error")
	testCheck(c, gocheck.ErrorMatches, true, "", errors.New("some error"), "some error")
	testCheck(c, gocheck.ErrorMatches, true, "", errors.New("some error"), "so.*or")

	// Verify params mutation
	params, names := testCheck(c, gocheck.ErrorMatches, false, "", errors.New("some error"), "other error")
	c.Assert(params[0], gocheck.Equals, "some error")
	c.Assert(names[0], gocheck.Equals, "error")
}
开发者ID:shaunduncan,项目名称:gocheck,代码行数:13,代码来源:checkers_test.go

示例9: TestAssertWithError

func (s *HelpersS) TestAssertWithError(c *gocheck.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" +
		"    c\\.Assert\\(1, checker, 2\\)\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
		})
}
开发者ID:shaunduncan,项目名称:gocheck,代码行数:13,代码来源:helpers_test.go

示例10: TestAssertWithMissingExpected

func (s *HelpersS) TestAssertWithMissingExpected(c *gocheck.C) {
	checker := &MyChecker{result: true}
	log := "(?s)helpers_test\\.go:[0-9]+:.*\nhelpers_test\\.go:[0-9]+:\n" +
		"    c\\.Assert\\(1, checker\\)\n" +
		"\\.+ Assert\\(myobtained, MyChecker, myexpected\\):\n" +
		"\\.+ Wrong number of parameters for MyChecker: " +
		"want 3, got 2\n\n"
	testHelperFailure(c, "Assert(1, checker, !?)", nil, true, log,
		func() interface{} {
			c.Assert(1, checker)
			return nil
		})
}
开发者ID:shaunduncan,项目名称:gocheck,代码行数:13,代码来源:helpers_test.go

示例11: TestAssertFailWithExpectedAndMessage

func (s *HelpersS) TestAssertFailWithExpectedAndMessage(c *gocheck.C) {
	checker := &MyChecker{result: false}
	log := "(?s)helpers_test\\.go:[0-9]+:.*\nhelpers_test\\.go:[0-9]+:\n" +
		"    c\\.Assert\\(1, checker, 2, myComment\\(\"Hello world!\"\\)\\)\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, myComment("Hello world!"))
			return nil
		})
}
开发者ID:shaunduncan,项目名称:gocheck,代码行数:13,代码来源:helpers_test.go

示例12: TestMkDir

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)
}
开发者ID:shaunduncan,项目名称:gocheck,代码行数:14,代码来源:helpers_test.go

示例13: TestExpectFailureSucceedVerbose

func (s *FoundationS) TestExpectFailureSucceedVerbose(c *gocheck.C) {
	helper := ExpectFailureSucceedHelper{}
	output := String{}
	result := gocheck.Run(&helper, &gocheck.RunConf{Output: &output, Verbose: true})

	expected := "" +
		"FAIL EXPECTED: foundation_test\\.go:[0-9]+:" +
		" ExpectFailureSucceedHelper\\.TestSucceed \\(It booms!\\)\t *[.0-9]+s\n"

	matched, err := regexp.MatchString(expected, output.value)
	if err != nil {
		c.Error("Bad expression: ", expected)
	} else if !matched {
		c.Error("ExpectFailure() didn't log properly:\n", output.value)
	}

	c.Assert(result.ExpectedFailures, gocheck.Equals, 1)
}
开发者ID:shaunduncan,项目名称:gocheck,代码行数:18,代码来源:foundation_test.go

示例14: TestExpectFailureFail

func (s *FoundationS) TestExpectFailureFail(c *gocheck.C) {
	helper := ExpectFailureFailHelper{}
	output := String{}
	result := gocheck.Run(&helper, &gocheck.RunConf{Output: &output})

	expected := "" +
		"^\n-+\n" +
		"FAIL: foundation_test\\.go:[0-9]+:" +
		" ExpectFailureFailHelper\\.TestFail\n\n" +
		"\\.\\.\\. Error: Test succeeded, but was expected to fail\n" +
		"\\.\\.\\. Reason: Bug #XYZ\n$"

	matched, err := regexp.MatchString(expected, output.value)
	if err != nil {
		c.Error("Bad expression: ", expected)
	} else if !matched {
		c.Error("ExpectFailure() didn't log properly:\n", output.value)
	}

	c.Assert(result.ExpectedFailures, gocheck.Equals, 0)
}
开发者ID:shaunduncan,项目名称:gocheck,代码行数:21,代码来源:foundation_test.go

示例15: TestPanicMatches

func (s *CheckersS) TestPanicMatches(c *gocheck.C) {
	testInfo(c, gocheck.PanicMatches, "PanicMatches", []string{"function", "expected"})

	// Error matching.
	testCheck(c, gocheck.PanicMatches, true, "", func() { panic(errors.New("BOOM")) }, "BO.M")
	testCheck(c, gocheck.PanicMatches, false, "", func() { panic(errors.New("KABOOM")) }, "BO.M")

	// Some errors.
	testCheck(c, gocheck.PanicMatches, false, "Function has not panicked", func() bool { return false }, "BOOM")
	testCheck(c, gocheck.PanicMatches, false, "Function must take zero arguments", 1, "BOOM")

	// Plain strings.
	testCheck(c, gocheck.PanicMatches, true, "", func() { panic("BOOM") }, "BO.M")
	testCheck(c, gocheck.PanicMatches, false, "", func() { panic("KABOOM") }, "BOOM")
	testCheck(c, gocheck.PanicMatches, true, "", func() bool { panic("BOOM") }, "BO.M")

	// Verify params/names mutation
	params, names := testCheck(c, gocheck.PanicMatches, false, "", func() { panic(errors.New("KABOOM")) }, "BOOM")
	c.Assert(params[0], gocheck.Equals, "KABOOM")
	c.Assert(names[0], gocheck.Equals, "panic")

	// Verify a nil panic
	testCheck(c, gocheck.PanicMatches, false, "Panic value is not a string or an error", func() { panic(nil) }, "")
}
开发者ID:shaunduncan,项目名称:gocheck,代码行数:24,代码来源:checkers_test.go


注:本文中的github.com/shaunduncan/gocheck.C.Assert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。