...
Source file
src/errors/errors_test.go
Documentation: errors
1
2
3
4
5 package errors_test
6
7 import (
8 "errors"
9 "fmt"
10 "testing"
11 )
12
13 func TestNewEqual(t *testing.T) {
14
15 if errors.New("abc") == errors.New("abc") {
16 t.Errorf(`New("abc") == New("abc")`)
17 }
18 if errors.New("abc") == errors.New("xyz") {
19 t.Errorf(`New("abc") == New("xyz")`)
20 }
21
22
23 err := errors.New("jkl")
24 if err != err {
25 t.Errorf(`err != err`)
26 }
27 }
28
29 func TestErrorMethod(t *testing.T) {
30 err := errors.New("abc")
31 if err.Error() != "abc" {
32 t.Errorf(`New("abc").Error() = %q, want %q`, err.Error(), "abc")
33 }
34 }
35
36 func ExampleNew() {
37 err := errors.New("emit macho dwarf: elf header corrupted")
38 if err != nil {
39 fmt.Print(err)
40 }
41
42 }
43
44
45
46 func ExampleNew_errorf() {
47 const name, id = "bimmler", 17
48 err := fmt.Errorf("user %q (id %d) not found", name, id)
49 if err != nil {
50 fmt.Print(err)
51 }
52
53 }
54
View as plain text