-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegration_test.go
More file actions
60 lines (52 loc) · 1.62 KB
/
integration_test.go
File metadata and controls
60 lines (52 loc) · 1.62 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package integration_test
import (
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
)
func TestSyntaxErrorDetection(t *testing.T) {
cmd := exec.Command("go", "run", "./cmd/gocheck/", "testdata/syntax/invalid.py")
out, err := cmd.CombinedOutput()
if err == nil {
t.Error("expected non-zero exit for syntax errors")
}
if !strings.Contains(string(out), "invalid.py") {
t.Errorf("output should reference file: %s", out)
}
}
func TestLintDiffMode(t *testing.T) {
cmd := exec.Command("go", "run", "./cmd/gocheck/", "testdata/lint/trailing.py")
out, err := cmd.CombinedOutput()
if err == nil {
t.Error("expected non-zero exit for lint issues")
}
if !strings.Contains(string(out), "trailing-whitespace") {
t.Errorf("expected trailing-whitespace in output: %s", out)
}
}
func TestLintFixMode(t *testing.T) {
src, _ := os.ReadFile("testdata/lint/trailing.py")
tmp := filepath.Join(t.TempDir(), "test.py")
os.WriteFile(tmp, src, 0644)
cmd := exec.Command("go", "run", "./cmd/gocheck/", "--fix", tmp)
output, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("fix mode failed: %v\noutput: %s", err, output)
}
result, _ := os.ReadFile(tmp)
expected, _ := os.ReadFile("testdata/lint/trailing.py.fixed")
if string(result) != string(expected) {
t.Errorf("fixed output doesn't match expected:\ngot:\n%q\nwant:\n%q", result, expected)
}
}
func TestCleanFileExitZero(t *testing.T) {
tmp := filepath.Join(t.TempDir(), "clean.py")
os.WriteFile(tmp, []byte("x = 1\n"), 0644)
cmd := exec.Command("go", "run", "./cmd/gocheck/", tmp)
err := cmd.Run()
if err != nil {
t.Errorf("expected exit 0 for clean file, got: %v", err)
}
}