Skip to content

Commit

Permalink
fix: fix top file fail tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Sep 18, 2020
1 parent 1f30752 commit 34a6380
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
18 changes: 10 additions & 8 deletions cmd/cloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,20 @@ var clocCmd = &cobra.Command{
Long: fmt.Sprintf("Sloc, Cloc and Code. Count lines of code in a directory with complexity estimation.\nVersion %s\nBen Boyter <ben@boyter.org> + Contributors", processor.Version),
Version: processor.Version,
Run: func(cmd *cobra.Command, args []string) {
if clocConfig.ByDirectory {
if clocConfig.TopFile {
_ = cloc_app.CreateClocDir()
processByDirectory(args[0])
processTopFile(args[0])
return
} else if clocConfig.TopFile {
}

if clocConfig.ByDirectory {
_ = cloc_app.CreateClocDir()
processTopFile(args[0])
processByDirectory(args[0])
return
} else {
processor.DirFilePaths = args
}

processor.DirFilePaths = args

if processor.ConfigureLimits != nil {
processor.ConfigureLimits()
}
Expand Down Expand Up @@ -75,7 +77,7 @@ func processTopFile(dir string) {

if len(languageSummaries) <= 3 {
for _, summary := range languageSummaries {
fmt.Fprintln(output, "Language: " + summary.Name)
fmt.Fprintln(output, "Language: "+summary.Name)
table := cmd_util.NewOutput(output)
table.SetHeader([]string{"Length", "File", "Complexity", "WeightedComplexity"})
sizes := len(summary.Files)
Expand All @@ -84,7 +86,7 @@ func processTopFile(dir string) {
}

for _, file := range summary.Files[:sizes] {
table.Append([]string{strconv.Itoa(int(file.Code)), file.Language, strconv.Itoa(int(file.Complexity)),strconv.Itoa(int(file.WeightedComplexity)) })
table.Append([]string{strconv.Itoa(int(file.Code)), file.Language, strconv.Itoa(int(file.Complexity)), strconv.Itoa(int(file.WeightedComplexity))})
}
table.Render()
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/cloc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func TestShouldByFileSize(t *testing.T) {

tests := []testcase.CmdTestCase{{
Name: "cloc",
Cmd: "cloc " + abs + " --top-file --top-size=10",
Cmd: "cloc " + abs + " --top-size=10 --top-file",
Golden: "testdata/top_file.txt",
}}
RunTestCmd(t, tests)
}
}
4 changes: 0 additions & 4 deletions cmd/testdata/top_file.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,3 @@ Language: Java
| 19 | Java | 0 | 0 |
| 13 | Java | 0 | 0 |
| 4 | Java | 0 | 0 |
Language: JSON
| LENGTH | FILE | COMPLEXITY | WEIGHTEDCOMPLEXITY |
|--------|------|------------|--------------------|
| 810 | JSON | 0 | 0 |

0 comments on commit 34a6380

Please sign in to comment.