moq
moq copied to clipboard
Fix stderr not printing in TestGoGenerateVendoredPackages
Before this commit, the TestGoGenerateVendoredPackages test failed to print stderr to the terminal as expected. Stderr was not printed because the test expected ExitError.Stderr to be populated. Per documentation ExitError.Stderr is only populated by the Cmd.Output method, which the test does not use. With this commit, the test uses a buffer to record stderr and include it in the failed test message as previously intended.
This issue was discovered because the TestGoGenerateVendoredPackages test expects moq to be available in the PATH. That means that running tests (go test ./...) in this project without first installing moq (go install) results in the TestGoGenerateVendoredPackages test to fail.
Before this commit, the error message looked as follows:
--- FAIL: TestGoGenerateVendoredPackages (0.03s)
moq_test.go:635: Wait: exit status 1
This error message does not include the output from stderr, making it difficult to know why the test is failing.
With this commit, the error message looks as follows:
--- FAIL: TestGoGenerateVendoredPackages (0.03s)
moq_test.go:641: Wait: exit status 1 user/user.go:5: running
"moq": exec: "moq": executable file not found in $PATH
While the changes in this pull request fix the intended behavior (as described in the commit message), I do wonder what the goal of the TestGoGenerateVendoredPackages
test is. From what I could see, it is the only test that expects moq
to be available in the PATH
. Could we not change TestGoGenerateVendoredPackages
such that go install
is not a prerequisite to running go test ./...
?