Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/cmd/deadcode: return an end code. #481

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/deadcode/deadcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,9 @@ func main() {
format = *formatFlag
}
printObjects(format, packages)
if len(packages) > 0 {
os.Exit(1)
}
}

// prettyName is a fork of Function.String designed to reduce
Expand Down
20 changes: 13 additions & 7 deletions cmd/deadcode/deadcode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,23 @@ func Test(t *testing.T) {
cmd.Env = append(os.Environ(), "GOPROXY=", "GO111MODULE=on")
var got string
if err := cmd.Run(); err != nil {
if !tc.wantErr {
t.Fatalf("deadcode failed: %v (stderr=%s)", err, cmd.Stderr)
switch err.(type) {
case *exec.ExitError:
if tc.wantErr {
got = fmt.Sprint(cmd.Stderr)
} else {
// If an unreachable code is detected, exit code 1 is notified
if cmd.ProcessState.ExitCode() != 1 {
t.Fatalf("deadcode failed: %v", err)
}
got = fmt.Sprint(cmd.Stdout)
}
default:
t.Fatalf("deadcode failed: %v", err)
}
got = fmt.Sprint(cmd.Stderr)
} else {
if tc.wantErr {
t.Fatalf("deadcode succeeded unexpectedly (stdout=%s)", cmd.Stdout)
}
got = fmt.Sprint(cmd.Stdout)
}

// Check each want directive.
for str, sense := range tc.want {
ok := true
Expand Down