-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain_test.go
More file actions
36 lines (29 loc) · 739 Bytes
/
Copy pathmain_test.go
File metadata and controls
36 lines (29 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"bytes"
"os"
"strings"
"testing"
)
func TestLintPackage(t *testing.T) {
// buffer to send output to
buf := &bytes.Buffer{}
// exit code to capture
exitCode := -1
exitFunc := func(code int) {
exitCode = code
}
stderr = buf
exit = exitFunc
os.Args = []string{"", "./testdata/foo"}
main()
expectedOutput := `testdata/foo/foo.go:7:2: implicit time.Duration means nanoseconds in "time.Sleep(60)"`
actualOutput := strings.TrimSpace(buf.String())
if actualOutput != expectedOutput {
t.Errorf("Expected output to be %q but got %q", expectedOutput, actualOutput)
}
expectedCode := 1
if exitCode != expectedCode {
t.Errorf("Expected exit code to be %v but got %v", expectedCode, exitCode)
}
}