本文整理汇总了Golang中testing.Errorf函数的典型用法代码示例。如果您正苦于以下问题:Golang Errorf函数的具体用法?Golang Errorf怎么用?Golang Errorf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Errorf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestDecoder_errors
func TestDecoder_errors(t *testing.T) {
tests := []struct {
data string
want error
}{
{"a=1\n=bar", &SyntaxError{Msg: "unexpected '='", Line: 2, Pos: 1}},
{"a=1\n\"k\"=bar", &SyntaxError{Msg: "unexpected '\"'", Line: 2, Pos: 1}},
{"a=1\nk\"ey=bar", &SyntaxError{Msg: "unexpected '\"'", Line: 2, Pos: 2}},
{"a=1\nk=b\"ar", &SyntaxError{Msg: "unexpected '\"'", Line: 2, Pos: 4}},
{"a=1\nk=b =ar", &SyntaxError{Msg: "unexpected '='", Line: 2, Pos: 5}},
{"a==", &SyntaxError{Msg: "unexpected '='", Line: 1, Pos: 3}},
{"a=1\nk=b=ar", &SyntaxError{Msg: "unexpected '='", Line: 2, Pos: 4}},
{"a=\"1", &SyntaxError{Msg: "unterminated quoted value", Line: 1, Pos: 5}},
{"a=\"1\\", &SyntaxError{Msg: "unterminated quoted value", Line: 1, Pos: 6}},
{"a=\"\\t1", &SyntaxError{Msg: "unterminated quoted value", Line: 1, Pos: 7}},
{"a=\"\\u1\"", &SyntaxError{Msg: "invalid quoted value", Line: 1, Pos: 8}},
}
for _, test := range tests {
dec := NewDecoder(strings.NewReader(test.data))
for dec.ScanRecord() {
for dec.ScanKeyval() {
}
}
if got, want := dec.Err(), test.want; !reflect.DeepEqual(got, want) {
t.Errorf("got: %v, want: %v", got, want)
}
}
}
示例2: TestGlobPatternPrefix
func TestGlobPatternPrefix(t *testing.T) {
var globberTests = []struct {
glob string
prefix string
}{
{"foo.bar", "foo.bar"},
{"foo.*.*.bar", "foo."},
{"foo?", "foo"},
{"foo]bar", "foo"},
{"foo[bar", "foo"},
{"trailing\\", "trailing\\"},
{"escaped.\\*.star", "escaped.\\*.star"},
}
for _, tt := range globberTests {
// Build a query
out := GlobPatternPrefix(tt.glob)
if out != tt.prefix {
t.Errorf("Expected '%v' to have prefix '%v', got '%v'.", tt.glob, tt.prefix, out)
}
}
}
示例3: TestSplit
func TestSplit(t *testing.T) {
s := split("a,b,", ',')
if len(s) != 3 || "a" != s[0] || "b" != s[1] || "" != s[2] {
t.Errorf("%v\n", s)
}
s = split(",", ',')
if len(s) != 2 || "" != s[0] || "" != s[1] {
t.Errorf("%v\n", s)
}
s = split("", ',')
if len(s) != 1 || s[0] != "" {
t.Errorf("%v\n", s)
}
s = split("a", ',')
if len(s) != 1 || s[0] != "a" {
t.Errorf("%v\n", s)
}
s = split("a\\\\,b,:,", ',')
if len(s) != 4 || "a\\\\" != s[0] || "b" != s[1] || ":" != s[2] || "" != s[3] {
t.Errorf("%v\n", s)
}
示例4: TestExportControl
func TestExportControl(t *testing.T) {
for _, example := range exportControlTests {
dir, err := ioutil.TempDir("", "example")
if err != nil {
log.Fatal(err)
}
defer os.RemoveAll(dir)
openControlData, errs := models.LoadData(example.opencontrolDir, example.certificationPath)
if len(errs) > 0 {
log.Fatal("Should have loaded the opencontrol data.")
}
openControl := OpenControlGitBook{
openControlData,
"",
dir,
fs.OSUtil{},
}
control := openControl.Standards.Get(example.standardKey).Controls[example.controlKey]
actualPath, actualText := openControl.exportControl(&ControlGitbook{&control, dir, example.standardKey, example.controlKey})
expectedPath := filepath.Join(dir, example.expectedPath)
// Verify the expected export path is the same as the actual export path
if expectedPath != actualPath {
t.Errorf("Expected %s, Actual: %s", example.expectedPath, actualPath)
}
// Verify the expected text is the same as the actual text
if example.expectedText != strings.Replace(actualText, "\\", "/", -1) {
t.Errorf("Expected %s, Actual: %s", example.expectedText, actualText)
}
}
示例5: Test_vm01
func Test_vm01(tst *testing.T) {
//verbose()
chk.PrintTitle("vm01")
// allocate driver
ndim, pstress := 2, false
simfnk, modelname := "test", "vm"
var drv Driver
err := drv.Init(simfnk, modelname, ndim, pstress, []*fun.Prm{
&fun.Prm{N: "K", V: 1.5},
&fun.Prm{N: "G", V: 1},
&fun.Prm{N: "qy0", V: 2},
&fun.Prm{N: "H", V: 0.5},
})
drv.CheckD = true
if err != nil {
tst.Errorf("test failed: %v\n", err)
return
}
// vm model
vm := drv.model.(*VonMises)
// path
p0 := 0.0
Δp := 3.0
Δq := vm.qy0
ϵ := 1e-3
DP := []float64{Δp + ϵ, 3, 2, 1, 0}
示例6: TestBuildGitbook
func TestBuildGitbook(t *testing.T) {
for _, example := range buildGitbookTests {
tempDir, _ := ioutil.TempDir("", "example")
defer os.RemoveAll(tempDir)
config := Config{
OpencontrolDir: example.inputDir,
Certification: example.certificationPath,
ExportPath: tempDir,
MarkdownPath: example.markdownPath,
}
config.BuildGitbook()
// Loop through the expected output to verify it matches the actual output
matches, _ := filepath.Glob(filepath.Join(example.expectedOutputDir, "*", "*"))
for _, expectedfilePath := range matches {
actualFilePath := strings.Replace(expectedfilePath, example.expectedOutputDir, tempDir, -1)
expectedData, _ := ioutil.ReadFile(expectedfilePath)
actualData, _ := ioutil.ReadFile(actualFilePath)
actualDataString := strings.Replace(string(actualData), "\\", "/", -1)
// Verify the expected text is the same as the actual text
if string(expectedData) != actualDataString {
t.Errorf("Expected (%s):\n`%s`\nActual:\n`%s`", expectedfilePath, string(expectedData), string(actualData))
}
}
}
}
示例7: TestBaseDirectory
func TestBaseDirectory(t *testing.T) {
mustStr := "Hello from template_tests/base_dir_test/"
fs := pongo2.MustNewLocalFileSystemLoader("")
s := pongo2.NewSet("test set with base directory", fs)
s.Globals["base_directory"] = "template_tests/base_dir_test/"
if err := fs.SetBaseDir(s.Globals["base_directory"].(string)); err != nil {
t.Fatal(err)
}
matches, err := filepath.Glob("./template_tests/base_dir_test/subdir/*")
if err != nil {
t.Fatal(err)
}
for _, match := range matches {
if "windows" == runtime.GOOS {
match = strings.Replace(match, "template_tests\\base_dir_test\\", "", -1)
} else {
match = strings.Replace(match, "template_tests/base_dir_test/", "", -1)
}
tpl, err := s.FromFile(match)
if err != nil {
t.Fatal(err)
}
out, err := tpl.Execute(nil)
if err != nil {
t.Fatal(err)
}
if out != mustStr {
t.Errorf("%s: out ('%s') != mustStr ('%s')", match, out, mustStr)
}
}
}
示例8: TestEmitLabelSet
func TestEmitLabelSet(t *testing.T) {
v := NewMetric("test", "prog", Gauge, "foo", "bar", "quux")
c := make(chan *LabelSet)
quit := make(chan bool)
ts := time.Now()
for _, tc := range labelSetTests {
d, _ := v.GetDatum(tc.values...)
d.Set(37, ts)
}
go v.EmitLabelSets(c, quit)
expected_datum := &Datum{37, ts}
for _, tc := range labelSetTests {
select {
case l := <-c:
if !reflect.DeepEqual(expected_datum, l.datum) {
t.Errorf("Datum no match: expected %v, received %v\n", expected_datum, l.datum)
}
if !reflect.DeepEqual(tc.expected_labels, l.labels) {
t.Errorf("Labels don't match: expected %v, received %v\n", tc.expected_labels, l.labels)
}
case <-quit:
goto out
}
}
out:
}
示例9: TestParseLinkDestination
func TestParseLinkDestination(t *testing.T) {
type testCase struct {
in string
title string
endpos int
ok bool
}
testCases := []testCase{
{"<\\>>", ">", 4, true},
{"http://goo gle.com", "http://goo", 10, true},
{"http://google.com", "http://google.com", 17, true},
{"http://google.com/search?query=(1)", "http://google.com/search?query=(1)", 34, true},
{"http://google.com/search?query=)1(", "http://google.com/search?query=", 31, true},
{"http://google.com/search?query=((1))", "http://google.com/search?query=(", 32, true},
{`http://google.com/search?query=a\ b\ c`, `http://google.com/search?query=a\ b\ c`, 38, true},
{"http://goo\x00gle.com", "http://goo", 10, true},
{"<link>", "link", 6, true},
{"<", "", 0, false},
{"<\\>", "", 0, false},
{"<\\", "", 0, false},
{"", "", 0, false},
{"<>", "", 2, true},
{"<link", "", 0, false},
{"<\n", "", 0, false},
}
for _, tc := range testCases {
title, endpos, ok := parseLinkDestination(tc.in, 0, len(tc.in))
if title != tc.title || endpos != tc.endpos || ok != tc.ok {
t.Errorf("parseLinkDestination(%q) = (%q, %d, %v), want (%q, %d, %v)", tc.in, title, endpos, ok, tc.title, tc.endpos, tc.ok)
}
}
}
示例10: TestExpandKey
// Test key expansion against FIPS 197 examples.
func TestExpandKey(t *testing.T) {
L:
for i, tt := range keyTests {
enc := make([]uint32, len(tt.enc))
var dec []uint32
if tt.dec != nil {
dec = make([]uint32, len(tt.dec))
}
// This test could only test Go version of expandKey because asm
// version might use different memory layout for expanded keys
// This is OK because we don't expose expanded keys to the outside
expandKeyGo(tt.key, enc, dec)
for j, v := range enc {
if v != tt.enc[j] {
t.Errorf("key %d: enc[%d] = %#x, want %#x", i, j, v, tt.enc[j])
continue L
}
}
if dec != nil {
for j, v := range dec {
if v != tt.dec[j] {
t.Errorf("key %d: dec[%d] = %#x, want %#x", i, j, v, tt.dec[j])
continue L
}
}
}
}
}
示例11: Test_dp01
func Test_dp01(tst *testing.T) {
//verbose()
chk.PrintTitle("dp01")
// allocate driver
ndim, pstress := 2, false
simfnk, modelname := "test", "dp"
var drv Driver
err := drv.Init(simfnk, modelname, ndim, pstress, []*fun.Prm{
&fun.Prm{N: "K", V: 1.5},
&fun.Prm{N: "G", V: 1},
&fun.Prm{N: "M", V: 0},
&fun.Prm{N: "Mb", V: 0},
&fun.Prm{N: "qy0", V: 2},
&fun.Prm{N: "H", V: 0.5},
})
drv.CheckD = true
drv.VerD = false // verbose
if err != nil {
tst.Errorf("test failed: %v\n", err)
return
}
// dp model
dp := drv.model.(*DruckerPrager)
// path
p0 := 0.0
Δp := 3.0
Δq := dp.qy0 + dp.M*Δp
ϵ := 1e-3
DP := []float64{Δp + ϵ, 3, 2, 1, 0}
示例12: TestToTomlValue
func TestToTomlValue(t *testing.T) {
for idx, item := range []struct {
Value interface{}
Expect string
}{
{int(1), "1"},
{int8(2), "2"},
{int16(3), "3"},
{int32(4), "4"},
{int64(12345), "12345"},
{uint(10), "10"},
{uint8(20), "20"},
{uint16(30), "30"},
{uint32(40), "40"},
{uint64(50), "50"},
{float32(12.456), "12.456"},
{float64(123.45), "123.45"},
{bool(true), "true"},
{"hello world", "\"hello world\""},
{"\b\t\n\f\r\"\\", "\"\\b\\t\\n\\f\\r\\\"\\\\\""},
{"\x05", "\"\\u0005\""},
{time.Date(1979, time.May, 27, 7, 32, 0, 0, time.UTC),
"1979-05-27T07:32:00Z"},
{[]interface{}{"gamma", "delta"},
"[\n \"gamma\",\n \"delta\",\n]"},
{nil, ""},
} {
result := toTomlValue(item.Value, 0)
if result != item.Expect {
t.Errorf("Test %d - got '%s', expected '%s'", idx, result, item.Expect)
}
}
}
示例13: TestStringMatchBackSlash
func TestStringMatchBackSlash(t *testing.T) {
pat, str := "\\*\\?\\[\\]\\\\", "*?[]\\"
if !StringMatch(pat, str) {
t.Errorf("StringMatch should have matched pattern %q with string %q", pat, str)
}
}
示例14: TestExtractRx
func TestExtractRx(t *testing.T) {
tests := []struct {
in, out string
}{
{"", ""},
{"/foo", ""},
{"foo", "foo"},
{"foo/bar", "foo"},
{"foo\\/bar", "foo\\/bar"},
{"foo\\/bar/", "foo\\/bar"},
{"foo\\\\/bar", "foo\\\\"},
{"foo\\\\\\/bar", "foo\\\\\\/bar"},
{"foo\\", "foo\\"},
{"foo\\\\", "foo\\\\"},
{"\\/", "\\/"},
{"\\//", "\\/"},
{"\\\\/", "\\\\"},
{"\\\\//", "\\\\"},
{"\\/foo", "\\/foo"},
}
for i, test := range tests {
l := &util.Lexer{Input: test.in}
if o := extractRx(l, '/'); o != test.out {
t.Errorf("extractRx(%d) '%s': exp '%s' got '%s'",
i, test.in, test.out, o)
}
}
}
示例15: TestLex
func TestLex(t *testing.T) {
for i, tt := range lexTests {
ret := lexcollect(lex("test", tt.input))
if !reflect.DeepEqual(ret, tt.expected) {
t.Errorf("%d %q - expected\n%v\ngot\n%v", i, tt.input, tt.expected, ret)
}
}
}