Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1f30752

Browse files
committed
feat: add test for top fie
1 parented69884 commit1f30752

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

‎cmd/cloc.go‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ import (
1313
"log"
1414
"os"
1515
"path/filepath"
16+
"strconv"
1617
"strings"
1718
)
1819

1920
type CocaClocConfig struct {
2021
ByDirectorybool
2122
TopFilebool
23+
TopSizesint
2224
}
2325

2426
var (
@@ -71,6 +73,23 @@ func processTopFile(dir string) {
7173

7274
cloc_app.SortLangeByCode(languageSummaries)
7375

76+
iflen(languageSummaries) <=3 {
77+
for _, summary := range languageSummaries {
78+
fmt.Fprintln(output,"Language:" + summary.Name)
79+
table := cmd_util.NewOutput(output)
80+
table.SetHeader([]string{"Length","File","Complexity","WeightedComplexity"})
81+
sizes :=len(summary.Files)
82+
if sizes >= clocConfig.TopSizes {
83+
sizes = clocConfig.TopSizes
84+
}
85+
86+
for _, file := range summary.Files[:sizes] {
87+
table.Append([]string{strconv.Itoa(int(file.Code)), file.Language, strconv.Itoa(int(file.Complexity)),strconv.Itoa(int(file.WeightedComplexity)) })
88+
}
89+
table.Render()
90+
}
91+
}
92+
7493
sortContent, _ := json.MarshalIndent(languageSummaries,"","\t")
7594
cmd_util.WriteToCocaFile("sort_cloc.json",string(sortContent))
7695
}
@@ -155,6 +174,7 @@ func addClocConfigs() {
155174

156175
flags.BoolVar(&clocConfig.ByDirectory,"by-directory",false,"list directory and out csv")
157176
flags.BoolVar(&clocConfig.TopFile,"top-file",false,"list top change file")
177+
flags.IntVar(&clocConfig.TopSizes,"top-size",30,"top file sizes")
158178

159179
flags.Int64Var(&processor.AverageWage,"avg-wage",56286,"average wage value used for basic COCOMO calculation")
160180
flags.BoolVar(&processor.DisableCheckBinary,"binary",false,"disable binary file detection")

‎cmd/cloc_test.go‎

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ func TestCloc(t *testing.T) {
2424
funcTestClocByDirectory(t*testing.T) {
2525
abs:="../_fixtures/cloc/normal"
2626

27-
analysis:= []testcase.CmdTestCase{{
28-
Name:"analysis",
29-
Cmd:"analysis -p "+abs,
30-
Golden:"",
31-
}}
32-
RunTestCmd(t,analysis)
33-
3427
tests:= []testcase.CmdTestCase{{
3528
Name:"cloc",
3629
Cmd:"cloc "+abs+" --by-directory --include-ext=java,kt",
@@ -42,13 +35,6 @@ func TestClocByDirectory(t *testing.T) {
4235
funcTestShouldReturnNullWhenIgnoreDir(t*testing.T) {
4336
abs:="../_fixtures/cloc/someignore"
4437

45-
analysis:= []testcase.CmdTestCase{{
46-
Name:"analysis",
47-
Cmd:"analysis -p "+abs,
48-
Golden:"",
49-
}}
50-
RunTestCmd(t,analysis)
51-
5238
tests:= []testcase.CmdTestCase{{
5339
Name:"cloc",
5440
Cmd:"cloc "+abs+" --by-directory",
@@ -58,19 +44,12 @@ func TestShouldReturnNullWhenIgnoreDir(t *testing.T) {
5844
}
5945

6046
funcTestShouldByFileSize(t*testing.T) {
61-
abs:="../_fixtures"
62-
63-
analysis:= []testcase.CmdTestCase{{
64-
Name:"analysis",
65-
Cmd:"analysis -p "+abs,
66-
Golden:"",
67-
}}
68-
RunTestCmd(t,analysis)
47+
abs:="../_fixtures/suggest"
6948

7049
tests:= []testcase.CmdTestCase{{
7150
Name:"cloc",
72-
Cmd:"cloc "+abs+" --top-file",
73-
Golden:"",
51+
Cmd:"cloc "+abs+" --top-file --top-size=10",
52+
Golden:"testdata/top_file.txt",
7453
}}
7554
RunTestCmd(t,tests)
7655
}

‎cmd/testdata/top_file.txt‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Language: Java
2+
| LENGTH | FILE | COMPLEXITY | WEIGHTEDCOMPLEXITY |
3+
|--------|------|------------|--------------------|
4+
| 40 | Java | 0 | 0 |
5+
| 19 | Java | 0 | 0 |
6+
| 13 | Java | 0 | 0 |
7+
| 4 | Java | 0 | 0 |
8+
Language: JSON
9+
| LENGTH | FILE | COMPLEXITY | WEIGHTEDCOMPLEXITY |
10+
|--------|------|------------|--------------------|
11+
| 810 | JSON | 0 | 0 |

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp