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

Commit 070b761

Browse files
authored
Merge pull request #535 from jmank88/status_table
buffer status output - fixes #532
2 parents 30cce2a + 05893d5 commit 070b761

26 files changed

+186
-22
lines changed

cmd/dep/integration_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ func testIntegration(name, wd string, externalProc bool, run test.RunFunc) func(
116116
// Check error raised in final command
117117
testCase.CompareError(err, testProj.GetStderr())
118118

119+
// Check output
120+
testCase.CompareOutput(testProj.GetStdout())
121+
119122
// Check final manifest and lock
120123
testCase.CompareFile(dep.ManifestName, testProj.ProjPath(dep.ManifestName))
121124
testCase.CompareFile(dep.LockName, testProj.ProjPath(dep.LockName))

cmd/dep/status.go

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"flag"
1111
"fmt"
1212
"io"
13-
"log"
1413
"sort"
1514
"text/tabwriter"
1615

@@ -194,41 +193,33 @@ func (cmd *statusCommand) Run(ctx *dep.Ctx, loggers *Loggers, args []string) err
194193
sm.UseDefaultSignalHandling()
195194
defer sm.Release()
196195

196+
var buf bytes.Buffer
197197
var out outputter
198198
switch {
199199
case cmd.detailed:
200200
return errors.Errorf("not implemented")
201201
case cmd.json:
202202
out = &jsonOutput{
203-
w: &logWriter{Logger: loggers.Out},
203+
w: &buf,
204204
}
205205
case cmd.dot:
206206
out = &dotOutput{
207207
p: p,
208208
o: cmd.output,
209-
w: &logWriter{Logger: loggers.Out},
209+
w: &buf,
210210
}
211211
default:
212212
out = &tableOutput{
213-
w: tabwriter.NewWriter(&logWriter{Logger: loggers.Out}, 0, 4, 2, ' ', 0),
213+
w: tabwriter.NewWriter(&buf, 0, 4, 2, ' ', 0),
214214
}
215215
}
216-
return runStatusAll(loggers, out, p, sm)
217-
}
218-
219-
// A logWriter adapts a log.Logger to the io.Writer interface.
220-
type logWriter struct {
221-
*log.Logger
222-
}
223216

224-
func (l *logWriter) Write(b []byte) (n int, err error) {
225-
str := string(b)
226-
if len(str) == 0 {
227-
return 0, nil
217+
if err := runStatusAll(loggers, out, p, sm); err != nil {
218+
return err
228219
}
229220

230-
l.Print(str)
231-
return len(b), err
221+
loggers.Out.Print(buf.String())
222+
return nil
232223
}
233224

234225
// BasicStatus contains all the information reported about a single dependency

cmd/dep/testdata/harness_tests/README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The directory structure is as follows:
1212
subcategory1/
1313
case1/
1414
testcase.json
15+
stdout.txt
1516
initial/
1617
file1.go
1718
Gopkg.toml
@@ -36,7 +37,8 @@ will be included automatically.
3637
The json file needs to be accompanied by `initial` and `final` directories. The
3738
`initial` is copied verbatim into the test project before the `dep` commands are
3839
run, are the `manifest` and `lock` files in `final`, if present, are used to
39-
compare against the test project results after the commands.
40+
compare against the test project results after the commands. The `stdout.txt` file
41+
is optional, and if present will be compared with command output.
4042

4143
The `testcase.json` file has the following format:
4244

@@ -74,9 +76,10 @@ The test procedure is as follows:
7476
5. Fetch the repos and versions in `vendor-initial` to the project's `vendor` directory
7577
6. Run `commands` on the project, in declaration order
7678
7. Ensure that, if any errors are raised, it is only by the final command and their string output matches `error-expected`
77-
8. Check the resulting files against those in the `final` input directory
78-
9. Check the `vendor` directory for the projects listed under `vendor-final`
79-
10. Check that there were no changes to `src` listings
80-
11. Clean up
79+
8. Ensure that, if a stdout.txt file is present, the command's output matches (excluding trailing whitespace).
80+
9. Check the resulting files against those in the `final` input directory
81+
10. Check the `vendor` directory for the projects listed under `vendor-final`
82+
11. Check that there were no changes to `src` listings
83+
12. Clean up
8184

8285
Note that for the remote fetches, only git repos are currently supported.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
digraph {
2+
node [shape=box];
3+
388407825 [label="github.com/golang/notexist"];
4+
2304687900 [label="github.com/sdboyer/deptest\nv0.8.0"];
5+
2659405890 [label="github.com/sdboyer/deptestdos\nv2.0.0"];
6+
388407825 -> 2304687900;
7+
388407825 -> 2659405890;
8+
2659405890 -> 2304687900;
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"commands": [
3+
["ensure"],
4+
["status","-dot"]
5+
],
6+
"vendor-final": [
7+
"github.com/sdboyer/deptest",
8+
"github.com/sdboyer/deptestdos"
9+
]
10+
}

cmd/dep/testdata/harness_tests/status/case1/json/final/Gopkg.lock

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[[dependencies]]
2+
name = "github.com/sdboyer/deptest"
3+
version = "^0.8.0"

cmd/dep/testdata/harness_tests/status/case1/json/initial/Gopkg.lock

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[[dependencies]]
2+
name = "github.com/sdboyer/deptest"
3+
version = "^0.8.0"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 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+
"github.com/sdboyer/deptestdos"
10+
)
11+
12+
func main() {
13+
err := nil
14+
if err != nil {
15+
deptest.Map["yo yo!"]
16+
}
17+
deptestdos.diMeLo("whatev")
18+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"ProjectRoot":"github.com/sdboyer/deptest","Children":null,"Constraint":{},"Version":{},"Revision":"ff2948a2ac8f538c4ecd55962e919d1e13e74baf","Latest":"3f4c3bea144e112a69bbe5d8d01c1b09a544253f","PackageCount":1},{"ProjectRoot":"github.com/sdboyer/deptestdos","Children":null,"Constraint":{},"Version":{},"Revision":"5c607206be5decd28e6263ffffdcee067266015e","Latest":"5c607206be5decd28e6263ffffdcee067266015e","PackageCount":1}]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"commands": [
3+
["ensure"],
4+
["status","-json"]
5+
],
6+
"vendor-final": [
7+
"github.com/sdboyer/deptest",
8+
"github.com/sdboyer/deptestdos"
9+
]
10+
}

cmd/dep/testdata/harness_tests/status/case1/table/final/Gopkg.lock

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[[dependencies]]
2+
name = "github.com/sdboyer/deptest"
3+
version = "^0.8.0"

cmd/dep/testdata/harness_tests/status/case1/table/initial/Gopkg.lock

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[[dependencies]]
2+
name = "github.com/sdboyer/deptest"
3+
version = "^0.8.0"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 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+
"github.com/sdboyer/deptestdos"
10+
)
11+
12+
func main() {
13+
err := nil
14+
if err != nil {
15+
deptest.Map["yo yo!"]
16+
}
17+
deptestdos.diMeLo("whatev")
18+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
PROJECT CONSTRAINT VERSION REVISION LATEST PKGS USED
2+
github.com/sdboyer/deptest >=0.8.0, <1.0.0 v0.8.0 ff2948a 3f4c3be 1
3+
github.com/sdboyer/deptestdos * v2.0.0 5c60720 5c60720 1

internal/test/integration_testcase.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"regexp"
1515
"strings"
1616
"testing"
17+
"unicode"
1718
)
1819

1920
var (
@@ -128,6 +129,34 @@ func (tc *IntegrationTestCase) CompareFile(goldenPath, working string) {
128129
}
129130
}
130131

132+
// CompareError compares expected and actual stdout output
133+
func (tc *IntegrationTestCase) CompareOutput(stdout string) {
134+
expected, err := ioutil.ReadFile(filepath.Join(tc.rootPath, "stdout.txt"))
135+
if err != nil {
136+
if os.IsNotExist(err) {
137+
// Nothing to verify
138+
return
139+
}
140+
panic(err)
141+
}
142+
143+
expStr := normalizeLines(string(expected))
144+
stdout = normalizeLines(stdout)
145+
146+
if expStr != stdout {
147+
tc.t.Errorf("expected: %q but got: %q", expStr, stdout)
148+
}
149+
}
150+
151+
// normalizeLines returns a version with trailing whitespace stripped from each line.
152+
func normalizeLines(s string) string {
153+
lines := strings.Split(s, "\n")
154+
for i := range lines {
155+
lines[i] = strings.TrimRightFunc(lines[i], unicode.IsSpace)
156+
}
157+
return strings.Join(lines, "\n")
158+
}
159+
131160
// CompareError compares exected and actual error
132161
func (tc *IntegrationTestCase) CompareError(err error, stderr string) {
133162
wantExists, want := tc.ErrorExpected != "", tc.ErrorExpected

internal/test/integration_testproj.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ func (p *IntegrationTestProject) RunGit(dir string, args ...string) {
143143
}
144144
}
145145

146+
// GetStdout gets the Stdout output from test run
147+
func (p *IntegrationTestProject) GetStdout() string {
148+
return p.stdout.String()
149+
}
150+
146151
// GetStderr gets the Stderr output from test run
147152
func (p *IntegrationTestProject) GetStderr() string {
148153
return p.stderr.String()

0 commit comments

Comments
 (0)