-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
96a849a
commit 325c4fb
Showing
6 changed files
with
149 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,62 @@ | ||
package gofmt | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/qiniu/x/xlog" | ||
"github.com/qiniu/reviewbot/internal/linters" | ||
) | ||
|
||
func TestFormatGofmt(t *testing.T) { | ||
content, err := os.ReadFile("../../../../testdata/gofmt_test.txt") | ||
func TestGofmtOutput(t *testing.T) { | ||
content, err := os.ReadFile("./testdata/gofmt_test.txt") | ||
if err != nil { | ||
fmt.Println("无法读取文件:", err) | ||
t.Errorf("open file failed ,the err is : %v", err) | ||
return | ||
} | ||
result, _ := formatGofmtOutput(&xlog.Logger{}, content) | ||
for key, value := range result { | ||
fmt.Printf("filename : %s \n ", key) | ||
for _, v := range value { | ||
fmt.Println("message: \n", v) | ||
tc := []struct { | ||
input []byte | ||
expected []linters.LinterOutput | ||
}{ | ||
{ | ||
content, | ||
[]linters.LinterOutput{ | ||
{ | ||
File: "testfile/staticcheck.go", | ||
Line: 7, | ||
Column: 1, | ||
Message: "", | ||
}, | ||
{ | ||
File: "testfile/test.go", | ||
Line: 9, | ||
Column: 4, | ||
Message: "", | ||
StartLine: 6, | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, c := range tc { | ||
outputMap, err := formatGofmtOutput([]byte(c.input)) | ||
for _, outputs := range outputMap { | ||
for i, output := range outputs { | ||
|
||
if err != nil { | ||
t.Errorf("unexpected error: %v", err) | ||
} | ||
|
||
if output.StartLine != 0 { | ||
if output.File != c.expected[1].File || output.StartLine != c.expected[1].StartLine || output.Line != c.expected[1].Line || output.Column != c.expected[1].Column { | ||
t.Errorf("expected: %v, got: %v", c.expected[i], output) | ||
} | ||
} else { | ||
if output.File != c.expected[0].File || output.Line != c.expected[0].Line || output.Column != c.expected[0].Column { | ||
t.Errorf("expected: %v, got: %v", c.expected[0], output) | ||
} | ||
} | ||
|
||
} | ||
|
||
} | ||
} | ||
fmt.Println(result) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
diff testfile/staticcheck.go.orig testfile/staticcheck.go | ||
--- testfile/staticcheck.go.orig | ||
+++ testfile/staticcheck.go | ||
@@ -4,5 +4,5 @@ | ||
|
||
func testunnuser() { | ||
fmt.Println("unused") | ||
- // wrong format | ||
+ // wrong format | ||
} | ||
diff testfile/test.go.orig testfile/test.go | ||
--- testfile/test.go.orig | ||
+++ testfile/test.go | ||
@@ -3,10 +3,10 @@ | ||
import "fmt" | ||
|
||
func test2() { | ||
- //testerr 33333 | ||
- | ||
- // 222222222 | ||
- //testerr 33333 | ||
+ //testerr 33333 | ||
+ | ||
+ // 222222222 | ||
+ //testerr 33333 | ||
|
||
// rrrrrrrrr | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.