t:=&testing.T{}err1:=fmt.Errorf("failure1")err2:=fmt.Errorf("failure2: %w",err1)err3:=fmt.Errorf("failure3: %w",err2)err:=fmt.Errorf("failure4: %w",err3)ok:=td.Cmp(t,err,td.ErrorIs(err))fmt.Println("error is itself:",ok)ok=td.Cmp(t,err,td.ErrorIs(err1))fmt.Println("error is also err1:",ok)ok=td.Cmp(t,err1,td.ErrorIs(err))fmt.Println("err1 is err:",ok)// Output:// error is itself: true// error is also err1: true// err1 is err: false
args… are optional and allow to name the test. This name is
used in case of failure to qualify the test. If len(args) > 1 and
the first item of args is a string and contains a ‘%’ rune then
fmt.Fprintf is used to compose the name, else args are passed to
fmt.Fprint. Do not forget it is the name of the test, not the
reason of a potential failure.
t:=&testing.T{}err1:=fmt.Errorf("failure1")err2:=fmt.Errorf("failure2: %w",err1)err3:=fmt.Errorf("failure3: %w",err2)err:=fmt.Errorf("failure4: %w",err3)ok:=td.CmpErrorIs(t,err,err)fmt.Println("error is itself:",ok)ok=td.CmpErrorIs(t,err,err1)fmt.Println("error is also err1:",ok)ok=td.CmpErrorIs(t,err1,err)fmt.Println("err1 is err:",ok)// Output:// error is itself: true// error is also err1: true// err1 is err: false
Returns true if the test is OK, false if it fails.
args… are optional and allow to name the test. This name is
used in case of failure to qualify the test. If len(args) > 1 and
the first item of args is a string and contains a ‘%’ rune then
fmt.Fprintf is used to compose the name, else args are passed to
fmt.Fprint. Do not forget it is the name of the test, not the
reason of a potential failure.
t:=td.NewT(&testing.T{})err1:=fmt.Errorf("failure1")err2:=fmt.Errorf("failure2: %w",err1)err3:=fmt.Errorf("failure3: %w",err2)err:=fmt.Errorf("failure4: %w",err3)ok:=t.CmpErrorIs(err,err)fmt.Println("error is itself:",ok)ok=t.CmpErrorIs(err,err1)fmt.Println("error is also err1:",ok)ok=t.CmpErrorIs(err1,err)fmt.Println("err1 is err:",ok)// Output:// error is itself: true// error is also err1: true// err1 is err: false