@@ -3,6 +3,7 @@ package main
33import (
44 "bytes"
55 "fmt"
6+ "github.com/google/go-cmp/cmp"
67 "os"
78 "path/filepath"
89 "regexp"
@@ -80,6 +81,21 @@ func normalizeFilePaths(output string) string {
8081 return strings .ReplaceAll (strings .ReplaceAll (output , "\\ \\ " , "/" ), "\\ " , "/" )
8182}
8283
84+ func expectAreEqual (t * testing.T , subject , actual , expect string ) {
85+ t .Helper ()
86+
87+ actual = dedent (t , actual )
88+ expect = dedent (t , expect )
89+
90+ if ! areEqual (t , actual , expect ) {
91+ if os .Getenv ("TEST_NO_DIFF" ) == "true" {
92+ t .Errorf ("\n actual %s does not match expected:\n got:\n %s\n \n want:\n %s" , subject , actual , expect )
93+ } else {
94+ t .Errorf ("\n actual %s does not match expected:\n %s" , subject , cmp .Diff (expect , actual ))
95+ }
96+ }
97+ }
98+
8399func testCli (t * testing.T , tc cliTestCase ) {
84100 t .Helper ()
85101
@@ -95,13 +111,8 @@ func testCli(t *testing.T, tc cliTestCase) {
95111 t .Errorf ("cli exited with code %d, not %d" , ec , tc .wantExitCode )
96112 }
97113
98- if ! areEqual (t , dedent (t , stdout ), dedent (t , tc .wantStdout )) {
99- t .Errorf ("stdout\n got:\n %s\n \n want:\n %s" , dedent (t , stdout ), dedent (t , tc .wantStdout ))
100- }
101-
102- if ! areEqual (t , dedent (t , stderr ), dedent (t , tc .wantStderr )) {
103- t .Errorf ("stderr\n got:\n %s\n \n want:\n %s" , dedent (t , stderr ), dedent (t , tc .wantStderr ))
104- }
114+ expectAreEqual (t , "stdout output" , stdout , tc .wantStdout )
115+ expectAreEqual (t , "stderr output" , stderr , tc .wantStderr )
105116}
106117
107118func TestRun (t * testing.T ) {
0 commit comments