Skip to content

Commit aaea0a5

Browse files
committed
Better diff for contains and not-contains
1 parent 34c15d3 commit aaea0a5

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Add `not-contains` assertion on `stdout` and `stderr`
44
- Add validation for invalid data types in `stdout` and `stderr` assertions
55
- More logging for `--verbose` option on the `test` command
6+
- Add better diff format for `contains` and `not-contains` assertions on `stdout` and `stderr`
67

78
# v1.0.1
89

pkg/matcher/matcher.go

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,20 @@ func (m ContainsMatcher) Match(got interface{}, expected interface{}) MatcherRes
8181
result = false
8282
}
8383

84-
diff := difflib.UnifiedDiff{
85-
A: difflib.SplitLines(fmt.Sprintf("%s", got.(string))),
86-
B: difflib.SplitLines(fmt.Sprintf("%s", expected.(string))),
87-
FromFile: "Got",
88-
ToFile: "Expected",
89-
Context: 3,
90-
}
91-
diffText, _ := difflib.GetUnifiedDiffString(diff)
84+
diff := `
85+
Expected
86+
87+
%s
88+
89+
to contain
90+
91+
%s
92+
`
93+
diff = fmt.Sprintf(diff, got, expected)
9294

9395
return MatcherResult{
9496
Success: result,
95-
Diff: diffText,
97+
Diff: diff,
9698
}
9799
}
98100

@@ -132,8 +134,19 @@ func (m NotContainsMatcher) Match(got interface{}, expected interface{}) Matcher
132134
result = false
133135
}
134136

137+
diff := `
138+
Expected
139+
140+
%s
141+
142+
to not contain
143+
144+
%s
145+
`
146+
diff = fmt.Sprintf(diff, got, expected)
147+
135148
return MatcherResult{
136149
Success: result,
137-
Diff: "",
150+
Diff: diff,
138151
}
139152
}

0 commit comments

Comments
 (0)