diff --git a/matchers/have_patterns.go b/matchers/have_patterns.go index cf2bcd13..a879547f 100644 --- a/matchers/have_patterns.go +++ b/matchers/have_patterns.go @@ -21,6 +21,7 @@ type HavePatternsMatcher struct { Elements interface{} missingElements []string foundElements []string + cachedActual string } func HavePatterns(elements interface{}) GossMatcher { @@ -76,8 +77,10 @@ func (m *HavePatternsMatcher) Match(actual interface{}) (success bool, err error scanner := bufio.NewScanner(fh) scanner.Buffer(nil, maxScanTokenSize) var found []patternMatcher + var lines []string for scanner.Scan() { line := scanner.Text() + lines = append(lines, line) i := 0 for _, pat := range notfound { @@ -99,6 +102,7 @@ func (m *HavePatternsMatcher) Match(actual interface{}) (success bool, err error if err := scanner.Err(); err != nil { return false, err } + m.cachedActual = strings.Join(lines, "\n") for _, pat := range notfound { // Didn't find it, but we didn't want to.. so we mark it as found @@ -123,7 +127,7 @@ func (m *HavePatternsMatcher) FailureResult(actual interface{}) MatcherResult { case string, []string: a = actual default: - a = fmt.Sprintf("object: %T", actual) + a = m.cachedActual } return MatcherResult{ Actual: a, @@ -135,9 +139,12 @@ func (m *HavePatternsMatcher) FailureResult(actual interface{}) MatcherResult { } func (m *HavePatternsMatcher) NegatedFailureResult(actual interface{}) MatcherResult { - a, ok := actual.(string) - if !ok { - a = fmt.Sprintf("object: %T", actual) + var a string + switch v := actual.(type) { + case string: + a = v + default: + a = m.cachedActual } return MatcherResult{ Actual: a, diff --git a/testdata/out_matching_basic_failing.1.documentation b/testdata/out_matching_basic_failing.1.documentation index 735d3a63..10958d45 100644 --- a/testdata/out_matching_basic_failing.1.documentation +++ b/testdata/out_matching_basic_failing.1.documentation @@ -31,7 +31,7 @@ to satisfy at least one of these matchers [{"have-len":2}] Matching: basic_reader: matches: Expected - "object: *strings.Reader" + "foo bar\nmoo cow" to have patterns ["fox","/^t.*w$/","!foo","!/^foo/"] the missing elements were @@ -253,7 +253,7 @@ to satisfy at least one of these matchers Matching: basic_reader: matches: Expected - "object: *strings.Reader" + "foo bar\nmoo cow" to have patterns ["fox","/^t.*w$/","!foo","!/^foo/"] the missing elements were diff --git a/testdata/out_matching_basic_failing.1.rspecish b/testdata/out_matching_basic_failing.1.rspecish index 3d6ca262..f8c1475a 100644 --- a/testdata/out_matching_basic_failing.1.rspecish +++ b/testdata/out_matching_basic_failing.1.rspecish @@ -40,7 +40,7 @@ to satisfy at least one of these matchers Matching: basic_reader: matches: Expected - "object: *strings.Reader" + "foo bar\nmoo cow" to have patterns ["fox","/^t.*w$/","!foo","!/^foo/"] the missing elements were diff --git a/testdata/out_matching_basic_failing.1.tap b/testdata/out_matching_basic_failing.1.tap index a60f1f65..e05ba321 100644 --- a/testdata/out_matching_basic_failing.1.tap +++ b/testdata/out_matching_basic_failing.1.tap @@ -4,7 +4,7 @@ not ok 2 - Matching: basic_array_consists_of: matches: Expected ["foo","bar","mo not ok 3 - Matching: basic_array_matchers: matches: Expected ["foo","bar","moo"] to satisfy at least one of these matchers [{"contain-elements":["fox","box"]},{"contain-elements":["fox","bax"]},["fox","bax","mox"],{"consist-of":["fox",{"have-prefix":"t"},"box"]},{"contain-element":{"have-prefix":"x"}},{"contain-element":{"have-suffix":"x"}}] not ok 4 - Matching: basic_int: matches: Expected 42 to be numerically eq 43 not ok 5 - Matching: basic_len: matches: Expected "123" to satisfy at least one of these matchers [{"have-len":2}] -not ok 6 - Matching: basic_reader: matches: Expected "object: *strings.Reader" to have patterns ["fox","/^t.*w$/","!foo","!/^foo/"] the missing elements were ["fox","/^t.*w$/","!foo","!/^foo/"] +not ok 6 - Matching: basic_reader: matches: Expected "foo bar\nmoo cow" to have patterns ["fox","/^t.*w$/","!foo","!/^foo/"] the missing elements were ["fox","/^t.*w$/","!foo","!/^foo/"] not ok 7 - Matching: basic_semver: matches: Expected "1.2.3" to satisfy at least one of these matchers [{"semver-constraint":">=9.9.0"}] not ok 8 - Matching: basic_string: matches: Expected "this is a test" to equal "this is a failing test" not ok 9 - Matching: basic_string_contain_substring: matches: Expected "foo" to contain substring "x"