Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit 9139a33

Browse files
committed
dep: Add more harness tests for wildcard ignores
This also adds `dep hash-inputs` output to both of the harness tests, so that it's easier for developers to keep track of the expected output in these cases.
1 parent cd42cef commit 9139a33

File tree

14 files changed

+106
-10
lines changed

14 files changed

+106
-10
lines changed

cmd/dep/integration_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,12 @@ func testIntegration(name, relPath, wd string, run integration.RunFunc) func(t *
123123
// Check error raised in final command
124124
testCase.CompareError(err, testProj.GetStderr())
125125

126-
// Check output
127-
testCase.CompareOutput(testProj.GetStdout())
126+
if *test.UpdateGolden {
127+
testCase.UpdateOutput(testProj.GetStdout())
128+
} else {
129+
// Check output
130+
testCase.CompareOutput(testProj.GetStdout())
131+
}
128132

129133
// Check vendor paths
130134
testProj.CompareImportPaths()

cmd/dep/testdata/harness_tests/ensure/pkg-ignored/wildcard-ignore/final/Gopkg.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-CONSTRAINTS-
2+
github.com/sdboyer/deptest
3+
b-master
4+
-IMPORTS/REQS-
5+
github.com/sdboyer/deptest
6+
-IGNORES-
7+
-OVERRIDES-
8+
-ANALYZER-
9+
dep
10+
1
11+

cmd/dep/testdata/harness_tests/ensure/pkg-ignored/wildcard-ignore/testcase.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"commands": [
3-
["ensure"]
3+
["ensure"],
4+
["hash-inputs"]
45
],
56
"error-expected": "",
67
"vendor-final": [

cmd/dep/testdata/harness_tests/ensure/pkg-ignored/wildcard-other-root/final/Gopkg.lock

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ignored = ["github.com/sdboyer/deptest*", "github.com/golang/notexist/samples*"]

cmd/dep/testdata/harness_tests/ensure/pkg-ignored/wildcard-other-root/initial/Gopkg.lock

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ignored = ["github.com/sdboyer/deptest*", "github.com/golang/notexist/samples*"]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2017 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import (
8+
_ "github.com/sdboyer/deptest"
9+
)
10+
11+
func main() {
12+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2017 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package samples
6+
7+
import _ "github.com/sdboyer/deptestdos"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2017 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package subsamples
6+
7+
import _ "github.com/sdboyer/dep-test"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-CONSTRAINTS-
2+
-IMPORTS/REQS-
3+
-IGNORES-
4+
github.com/sdboyer/deptest*
5+
-OVERRIDES-
6+
-ANALYZER-
7+
dep
8+
1
9+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"commands": [
3+
["ensure"],
4+
["hash-inputs"]
5+
],
6+
"error-expected": "",
7+
"vendor-final": []
8+
}

internal/test/integration/testcase.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,38 @@ func (tc *TestCase) CompareFile(goldenPath, working string) {
8383

8484
gotExists, got, err := getFile(working)
8585
if err != nil {
86-
tc.t.Fatalf("Error reading project file %s: %s", goldenPath, err)
86+
tc.t.Fatalf("Error reading project file %q: %s", goldenPath, err)
8787
}
8888
wantExists, want, err := getFile(golden)
8989
if err != nil {
90-
tc.t.Fatalf("Error reading testcase file %s: %s", goldenPath, err)
90+
tc.t.Fatalf("Error reading testcase file %q: %s", goldenPath, err)
9191
}
9292

9393
if wantExists && gotExists {
9494
if want != got {
95-
tc.t.Errorf("expected %s, got %s", want, got)
95+
tc.t.Errorf("%s was not as expected\n(WNT):\n%s\n(GOT):\n%s", filepath.Base(goldenPath), want, got)
9696
}
9797
} else if !wantExists && gotExists {
98-
tc.t.Errorf("%s created where none was expected", goldenPath)
98+
tc.t.Errorf("%q created where none was expected", goldenPath)
9999
} else if wantExists && !gotExists {
100-
tc.t.Errorf("%s not created where one was expected", goldenPath)
100+
tc.t.Errorf("%q not created where one was expected", goldenPath)
101+
}
102+
}
103+
104+
// UpdateFile updates the golden file with the working result.
105+
func (tc *TestCase) UpdateOutput(stdout string) {
106+
stdoutPath := filepath.Join(tc.rootPath, "stdout.txt")
107+
_, err := os.Stat(stdoutPath)
108+
if err != nil {
109+
if os.IsNotExist(err) {
110+
// Don't update the stdout.txt file if it doesn't exist.
111+
return
112+
}
113+
panic(err)
114+
}
115+
116+
if err := tc.WriteFile(stdoutPath, stdout); err != nil {
117+
tc.t.Fatal(err)
101118
}
102119
}
103120

@@ -116,7 +133,7 @@ func (tc *TestCase) CompareOutput(stdout string) {
116133
stdout = normalizeLines(stdout)
117134

118135
if expStr != stdout {
119-
tc.t.Errorf("(WNT):\n%s\n(GOT):\n%s\n", expStr, stdout)
136+
tc.t.Errorf("stdout was not as expected\n(WNT):\n%s\n(GOT):\n%s\n", expStr, stdout)
120137
}
121138
}
122139

0 commit comments

Comments
 (0)