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


Golang C.Assert方法代码示例

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


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

示例1: TestPanics

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

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

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

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

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

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

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

示例2: testToFloat64

func testToFloat64(c *check.C, val interface{}, expect float64) {
	b, err := ToFloat64(val)
	c.Assert(err, check.IsNil)
	diff := math.Abs(b - expect)
	Epsilon := float64(0.00000001)
	c.Assert(Epsilon, check.Greater, diff)
}
开发者ID:fuxiaohei,项目名称:tidb,代码行数:7,代码来源:convert_test.go

示例3: TestDefaultTypeForValue

func (s *testFieldTypeSuite) TestDefaultTypeForValue(c *check.C) {
	nullType := DefaultTypeForValue(nil)
	di := &DataItem{Type: nullType}
	cases := []struct {
		value interface{}
		tp    byte
	}{
		{nil, mysql.TypeNull},
		{1, mysql.TypeLonglong},
		{uint64(1), mysql.TypeLonglong},
		{"abc", mysql.TypeVarString},
		{1.1, mysql.TypeNewDecimal},
		{[]byte("abc"), mysql.TypeBlob},
		{mysql.Bit{}, mysql.TypeBit},
		{mysql.Hex{}, mysql.TypeVarchar},
		{mysql.Time{Type: mysql.TypeDatetime}, mysql.TypeDatetime},
		{mysql.Duration{}, mysql.TypeDuration},
		{mysql.Decimal{}, mysql.TypeNewDecimal},
		{mysql.Enum{}, mysql.TypeEnum},
		{mysql.Set{}, mysql.TypeSet},
		{di, mysql.TypeNull},
	}
	for _, ca := range cases {
		ft := DefaultTypeForValue(ca.value)
		c.Assert(ft.Tp, check.Equals, ca.tp, check.Commentf("%v %v", ft, ca))
	}
}
开发者ID:yuanfeng0905,项目名称:tidb,代码行数:27,代码来源:field_type_test.go

示例4: TestExpectFailureSucceed

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

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

示例5: TestMinLogger

func (s *BootstrapS) TestMinLogger(c *check.C) {
	var logger minLogger
	logger = log.New(os.Stderr, "", 0)
	logger = c
	logger.Output(0, "Hello there")
	expected := `\[LOG\] [0-9]+:[0-9][0-9]\.[0-9][0-9][0-9] +Hello there\n`
	output := c.GetTestLog()
	c.Assert(output, check.Matches, expected)
}
开发者ID:ninefive,项目名称:tidb,代码行数:9,代码来源:foundation_test.go

示例6: TestAssertSucceedWithoutExpected

func (s *HelpersS) TestAssertSucceedWithoutExpected(c *check.C) {
	checker := &MyChecker{result: true, info: &check.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:ninefive,项目名称:tidb,代码行数:10,代码来源:helpers_test.go

示例7: accept

func accept(c *check.C, tp byte, value interface{}, unsigned bool, expected string) {
	ft := NewFieldType(tp)
	if unsigned {
		ft.Flag |= mysql.UnsignedFlag
	}
	//	casted, err := col.CastValue(nil, value)
	casted, err := Convert(value, ft)
	c.Assert(err, check.IsNil, check.Commentf("%v", ft))
	c.Assert(fmt.Sprintf("%v", casted), check.Equals, expected)
}
开发者ID:fuxiaohei,项目名称:tidb,代码行数:10,代码来源:convert_test.go

示例8: TestAssertSucceedWithExpected

func (s *HelpersS) TestAssertSucceedWithExpected(c *check.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:ninefive,项目名称:tidb,代码行数:10,代码来源:helpers_test.go

示例9: TestAssertFailWithoutExpected

func (s *HelpersS) TestAssertFailWithoutExpected(c *check.C) {
	checker := &MyChecker{result: false, info: &check.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:ninefive,项目名称:tidb,代码行数:11,代码来源:helpers_test.go

示例10: TestAssertWithNilChecker

func (s *HelpersS) TestAssertWithNilChecker(c *check.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:ninefive,项目名称:tidb,代码行数:11,代码来源:helpers_test.go

示例11: TestAssertFailWithExpected

func (s *HelpersS) TestAssertFailWithExpected(c *check.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:ninefive,项目名称:tidb,代码行数:12,代码来源:helpers_test.go

示例12: TestAssertFailWithExpectedAndMessage

func (s *HelpersS) TestAssertFailWithExpectedAndMessage(c *check.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:ninefive,项目名称:tidb,代码行数:13,代码来源:helpers_test.go

示例13: TestAssertWithError

func (s *HelpersS) TestAssertWithError(c *check.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:ninefive,项目名称:tidb,代码行数:13,代码来源:helpers_test.go

示例14: TestErrorMatches

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

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

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

示例15: TestAssertWithMissingExpected

func (s *HelpersS) TestAssertWithMissingExpected(c *check.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:ninefive,项目名称:tidb,代码行数:13,代码来源:helpers_test.go


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