Skip to content

Commit b5954ca

Browse files
authored
Trim whitespace from file contents (#186)
* Trim whitespace from file contents * Update changelog * Innocuous change * Revert innocuous change * Bump counter
1 parent d2d94ca commit b5954ca

6 files changed

Lines changed: 11 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- Add `--workdir` flag to change the wokring directory of commander `test` execution
44
- Add `--config` flag to allow configuration to be set in a separate file
5+
- Fix bug in `file` matcher
56

67
# v2.4.0
78

commander_unix.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ tests:
1616
contains:
1717
- ✓ [local] it should exit with error code
1818
- "- [local] it should skip, was skipped"
19-
line-count: 19
19+
line-count: 20
2020
exit-code: 0
2121

2222
it should assert that commander will fail:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
first line
22
second line
3-
third line
3+
third line
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
a
2+
b

integration/unix/commander_test.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ tests:
6969
stderr:
7070
file: ./integration/unix/_fixtures/big_out.txt
7171

72+
it should handle a trailing newline in the file:
73+
command: cat ./integration/unix/_fixtures/trailing_newline.txt
74+
stdout:
75+
file: ./integration/unix/_fixtures/trailing_newline.txt
76+
7277
it should inherit from parent env:
7378
config:
7479
inherit-env: true

pkg/matcher/matcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func (m FileMatcher) Match(got interface{}, expected interface{}) MatcherResult
269269
if err != nil {
270270
panic(err.Error())
271271
}
272-
expectedString := string(expectedText)
272+
expectedString := strings.TrimSpace(strings.Replace(string(expectedText), "\r\n", "\n", -1))
273273

274274
result := got == expectedString
275275

0 commit comments

Comments
 (0)