|
9 | 9 | "io"
|
10 | 10 | "math"
|
11 | 11 | "os"
|
| 12 | + "path/filepath" |
12 | 13 | "reflect"
|
13 | 14 | "regexp"
|
14 | 15 | "runtime"
|
@@ -688,15 +689,31 @@ func TestContainsNotContains(t *testing.T) {
|
688 | 689 | }
|
689 | 690 | }
|
690 | 691 |
|
691 |
| -func TestContainsFailMessage(t *testing.T) { |
692 |
| - |
| 692 | +func TestContainsNotContainsFailMessage(t *testing.T) { |
693 | 693 | mockT := new(mockTestingT)
|
694 | 694 |
|
695 |
| - Contains(mockT, "Hello World", errors.New("Hello")) |
696 |
| - expectedFail := "\"Hello World\" does not contain &errors.errorString{s:\"Hello\"}" |
697 |
| - actualFail := mockT.errorString() |
698 |
| - if !strings.Contains(actualFail, expectedFail) { |
699 |
| - t.Errorf("Contains failure should include %q but was %q", expectedFail, actualFail) |
| 695 | + cases := []struct { |
| 696 | + assertion func(t TestingT, s, contains interface{}, msgAndArgs ...interface{}) bool |
| 697 | + container interface{} |
| 698 | + instance interface{} |
| 699 | + expected string |
| 700 | + }{ |
| 701 | + { |
| 702 | + assertion: Contains, |
| 703 | + container: "Hello World", |
| 704 | + instance: errors.New("Hello"), |
| 705 | + expected: "\"Hello World\" does not contain &errors.errorString{s:\"Hello\"}", |
| 706 | + }, |
| 707 | + } |
| 708 | + for _, c := range cases { |
| 709 | + name := filepath.Base(runtime.FuncForPC(reflect.ValueOf(c.assertion).Pointer()).Name()) |
| 710 | + t.Run(fmt.Sprintf("%v(%T, %T)", name, c.container, c.instance), func(t *testing.T) { |
| 711 | + c.assertion(mockT, "Hello World", errors.New("Hello")) |
| 712 | + actualFail := mockT.errorString() |
| 713 | + if !strings.Contains(actualFail, c.expected) { |
| 714 | + t.Errorf("Contains failure should include %q but was %q", c.expected, actualFail) |
| 715 | + } |
| 716 | + }) |
700 | 717 | }
|
701 | 718 | }
|
702 | 719 |
|
|
0 commit comments