Skip to content

Commit

Permalink
fix: check error
Browse files Browse the repository at this point in the history
  • Loading branch information
hhatto committed May 4, 2023
1 parent f4f54dc commit de888ca
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 21 deletions.
70 changes: 50 additions & 20 deletions file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ func TestAnalayzeFile4Python(t *testing.T) {
}
defer os.Remove(tmpfile.Name())

tmpfile.Write([]byte(`#!/bin/python
if _, err := tmpfile.Write([]byte(`#!/bin/python
class A:
"""comment1
comment2
comment3
"""
pass
`))
`),
); err != nil {
t.Fatalf("tmpfile.Write() error. err=[%v]", err)
}

language := NewLanguage("Python", []string{"#"}, [][]string{{"\"\"\"", "\"\"\""}})
clocOpts := NewClocOptions()
Expand Down Expand Up @@ -52,14 +55,17 @@ func TestAnalayzeFile4PythonInvalid(t *testing.T) {
}
defer os.Remove(tmpfile.Name())

tmpfile.Write([]byte(`#!/bin/python
if _, err := tmpfile.Write([]byte(`#!/bin/python
class A:
"""comment1
comment2
comment3"""
pass
`))
`),
); err != nil {
t.Fatalf("tmpfile.Write() error. err=[%v]", err)
}

language := NewLanguage("Python", []string{"#"}, [][]string{{"\"\"\"", "\"\"\""}})
clocOpts := NewClocOptions()
Expand Down Expand Up @@ -88,7 +94,7 @@ func TestAnalayzeFile4PythonNoShebang(t *testing.T) {
}
defer os.Remove(tmpfile.Name())

tmpfile.Write([]byte(`a = '''hello
if _, err := tmpfile.Write([]byte(`a = '''hello
world
'''
Expand All @@ -98,7 +104,10 @@ func TestAnalayzeFile4PythonNoShebang(t *testing.T) {
"""
print a, b
`))
`),
); err != nil {
t.Fatalf("tmpfile.Write() error. err=[%v]", err)
}

language := NewLanguage("Python", []string{"#"}, [][]string{{"\"\"\"", "\"\"\""}})
clocOpts := NewClocOptions()
Expand Down Expand Up @@ -127,15 +136,18 @@ func TestAnalayzeFile4Go(t *testing.T) {
}
defer os.Remove(tmpfile.Name())

tmpfile.Write([]byte(`package main
if _, err := tmpfile.Write([]byte(`package main
func main() {
var n string /*
comment
comment
*/
}
`))
`),
); err != nil {
t.Fatalf("tmpfile.Write() error. err=[%v]", err)
}

language := NewLanguage("Go", []string{"//"}, [][]string{{"/*", "*/"}})
clocOpts := NewClocOptions()
Expand Down Expand Up @@ -165,15 +177,18 @@ func TestAnalayzeFile4GoWithOnelineBlockComment(t *testing.T) {
}
defer os.Remove(tmpfile.Name())

tmpfile.Write([]byte(`package main
if _, err := tmpfile.Write([]byte(`package main
func main() {
st := "/*"
a := 1
en := "*/"
/* comment */
}
`))
`),
); err != nil {
t.Fatalf("tmpfile.Write() error. err=[%v]", err)
}

language := NewLanguage("Go", []string{"//"}, [][]string{{"/*", "*/"}})
clocOpts := NewClocOptions()
Expand Down Expand Up @@ -202,14 +217,17 @@ func TestAnalayzeFile4GoWithCommentInnerBlockComment(t *testing.T) {
}
defer os.Remove(tmpfile.Name())

tmpfile.Write([]byte(`package main
if _, err := tmpfile.Write([]byte(`package main
func main() {
// comment /*
a := 1
b := 2
}
`))
`),
); err != nil {
t.Fatalf("tmpfile.Write() error. err=[%v]", err)
}

language := NewLanguage("Go", []string{"//"}, [][]string{{"/*", "*/"}})
clocOpts := NewClocOptions()
Expand Down Expand Up @@ -238,13 +256,16 @@ func TestAnalyzeFile4GoWithNoComment(t *testing.T) {
}
defer os.Remove(tmpfile.Name())

tmpfile.Write([]byte(`package main
if _, err := tmpfile.Write([]byte(`package main
func main() {
a := "/* */"
b := "// "
}
`))
`),
); err != nil {
t.Fatalf("tmpfile.Write() error. err=[%v]", err)
}

language := NewLanguage("Go", []string{"//"}, [][]string{{"/*", "*/"}})
clocOpts := NewClocOptions()
Expand Down Expand Up @@ -273,7 +294,7 @@ func TestAnalyzeFile4ATSWithDoubleMultilineComments(t *testing.T) {
}
defer os.Remove(tmpfile.Name())

tmpfile.Write([]byte(`/* com */
if _, err := tmpfile.Write([]byte(`/* com */
(* co *)
vo (*
Expand All @@ -283,7 +304,10 @@ vo /*
jife */
vo /* ff */
`))
`),
); err != nil {
t.Fatalf("tmpfile.Write() error. err=[%v]", err)
}

language := NewLanguage("ATS", []string{"//"}, [][]string{{"(*", "*)"}, {"/*", "*/"}})
clocOpts := NewClocOptions()
Expand Down Expand Up @@ -312,7 +336,7 @@ func TestAnalyzeFile4JavaWithCommentInCodeLine(t *testing.T) {
}
defer os.Remove(tmpfile.Name())

tmpfile.Write([]byte(`public class Sample {
if _, err := tmpfile.Write([]byte(`public class Sample {
public static void main(String args[]){
int a; /* A takes care of counts */
int b;
Expand All @@ -327,7 +351,10 @@ func TestAnalyzeFile4JavaWithCommentInCodeLine(t *testing.T) {
/*End of Main*/
}
}
`))
`),
); err != nil {
t.Fatalf("tmpfile.Write() error. err=[%v]", err)
}

language := NewLanguage("Java", []string{"//"}, [][]string{{"/*", "*/"}})
clocOpts := NewClocOptions()
Expand Down Expand Up @@ -356,7 +383,7 @@ func TestAnalyzeFile4Makefile(t *testing.T) {
}
defer os.Remove(tmpfile.Name())

tmpfile.Write([]byte(`# This is a simple Makefile with comments
if _, err := tmpfile.Write([]byte(`# This is a simple Makefile with comments
.PHONY: test build
build:
Expand All @@ -373,7 +400,10 @@ func TestAnalyzeFile4Makefile(t *testing.T) {
test:
GO111MODULE=on go test -v
`))
`),
); err != nil {
t.Fatalf("tmpfile.Write() error. err=[%v]", err)
}

language := NewLanguage("Makefile", []string{"#"}, [][]string{{"", ""}})
clocOpts := NewClocOptions()
Expand Down
4 changes: 3 additions & 1 deletion utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ func TestCheckMD5SumIgnore(t *testing.T) {

func TestCheckDefaultIgnore(t *testing.T) {
appFS := afero.NewMemMapFs()
appFS.Mkdir("/test", os.ModeDir)
if err := appFS.Mkdir("/test", os.ModeDir); err != nil {
t.Fatal(err)
}
_, _ = appFS.Create("/test/one.go")

fileInfo, _ := appFS.Stat("/")
Expand Down

0 comments on commit de888ca

Please sign in to comment.