Skip to content

Commit

Permalink
Show diff when matching command output in tests for easier debugging.
Browse files Browse the repository at this point in the history
  • Loading branch information
bilus committed Oct 26, 2021
1 parent 16c60c1 commit 4fd9f27
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/Masterminds/goutils v1.1.0 // indirect
github.com/Masterminds/semver v1.4.2 // indirect
github.com/Masterminds/sprig v2.18.0+incompatible
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883
github.com/blang/semver v3.5.1+incompatible
github.com/c-bata/go-prompt v0.2.4-0.20200321140817-d043be076398
github.com/cucumber/godog v0.12.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBb
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
Expand Down
6 changes: 4 additions & 2 deletions oya_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"runtime"
"strings"

"github.com/andreyvit/diff"
"github.com/cucumber/godog"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -281,7 +282,8 @@ func (c *SuiteContext) theCommandFailsWithErrorMatching(errMsg *gherkin.DocStrin
func (c *SuiteContext) theCommandOutputs(expected *gherkin.DocString) error {
actual := c.stdout.String()
if actual != expected.Content {
return fmt.Errorf("unexpected %v; expected: %q", actual, expected.Content)
return fmt.Errorf("unexpected %v; expected: %v; diff: %v",
actual, expected.Content, diff.LineDiff(actual, expected.Content))
}
return nil
}
Expand All @@ -290,7 +292,7 @@ func (c *SuiteContext) theCommandOutputsTextMatching(expected *gherkin.DocString
actual := c.stdout.String()
rx := regexp.MustCompile(expected.Content)
if !rx.MatchString(actual) {
return fmt.Errorf("unexpected %v; expected to match: %q", actual, expected.Content)
return fmt.Errorf("unexpected %v; expected to match: %v", actual, expected.Content)
}
return nil
}
Expand Down

0 comments on commit 4fd9f27

Please sign in to comment.