Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions SCC-OUTPUT-REPORT.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
<tbody><tr>
<th>Go</th>
<th>34</th>
<th>27183</th>
<th>1780</th>
<th>27374</th>
<th>1796</th>
<th>614</th>
<th>24789</th>
<th>1969</th>
<th>553720</th>
<th>8117</th>
<th>24964</th>
<th>2018</th>
<th>558764</th>
<th>8190</th>
</tr><tr>
<td>processor/constants.go</td>
<td></td>
Expand Down Expand Up @@ -60,6 +60,16 @@
<td>167</td>
<td>47400</td>
<td>833</td>
</tr><tr>
<td>main_test.go</td>
<td></td>
<td>890</td>
<td>70</td>
<td>15</td>
<td>805</td>
<td>228</td>
<td>21740</td>
<td>471</td>
</tr><tr>
<td>processor/workers.go</td>
<td></td>
Expand All @@ -80,16 +90,6 @@
<td>89</td>
<td>21834</td>
<td>495</td>
</tr><tr>
<td>main_test.go</td>
<td></td>
<td>699</td>
<td>54</td>
<td>15</td>
<td>630</td>
<td>179</td>
<td>16696</td>
<td>395</td>
</tr><tr>
<td>cmd/badges/main.go</td>
<td></td>
Expand Down Expand Up @@ -364,15 +364,15 @@
<tfoot><tr>
<th>Total</th>
<th>34</th>
<th>27183</th>
<th>1780</th>
<th>27374</th>
<th>1796</th>
<th>614</th>
<th>24789</th>
<th>1969</th>
<th>553720</th>
<th>8117</th>
<th>24964</th>
<th>2018</th>
<th>558764</th>
<th>8190</th>
</tr>
<tr>
<th colspan="9">Estimated Cost to Develop (organic) $786,261<br>Estimated Schedule Effort (organic) 12.55 months<br>Estimated People Required (organic) 5.56<br></th>
<th colspan="9">Estimated Cost to Develop (organic) $792,091<br>Estimated Schedule Effort (organic) 12.59 months<br>Estimated People Required (organic) 5.59<br></th>
</tr></tfoot>
</table></body></html>
193 changes: 192 additions & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"
"regexp"
"slices"
"strconv"
"strings"
"testing"
)
Expand Down Expand Up @@ -315,6 +316,50 @@ func TestLineLength(t *testing.T) {
}
}

func TestFormatHTML(t *testing.T) {
t.Parallel()
output, err := runSCC("--format", "html")
if err != nil {
t.Fatal(err)
}
if !strings.Contains(output, "<title>scc html output</title>") {
t.Fatalf("html format test failed, output:\n%s", output)
}
}

func TestFormatHTMLTable(t *testing.T) {
t.Parallel()
output, err := runSCC("--format", "html-table")
if err != nil {
t.Fatal(err)
}
if !strings.Contains(output, `<table id="scc-table">`) {
t.Fatalf("html-table format test failed, output:\n%s", output)
}
}

func TestFormatSQL(t *testing.T) {
t.Parallel()
output, err := runSCC("--format", "sql")
if err != nil {
t.Fatal(err)
}
if !strings.Contains(output, "create table metadata ( -- github.com/boyter/scc") {
t.Fatalf("sql format test failed, output:\n%s", output)
}
}

func TestFormatSQLInsert(t *testing.T) {
t.Parallel()
output, err := runSCC("--format", "sql-insert")
if err != nil {
t.Fatal(err)
}
if !strings.Contains(output, "begin transaction;\ninsert into t values(") {
t.Fatalf("sql-insert format test failed, output:\n%s", output)
}
}

func TestMultipleFormatStdout(t *testing.T) {
output, err := runSCC("--format-multi", "tabular:stdout,html:stdout,csv:stdout,sql:stdout")
if err != nil {
Expand Down Expand Up @@ -519,7 +564,7 @@ func TestDeterministicOutput(t *testing.T) {
if err != nil {
t.Fatal(err)
}
for range 20 {
for range 10 {
output2, err := runSCC(".")
if err != nil {
t.Fatal(err)
Expand All @@ -530,6 +575,152 @@ func TestDeterministicOutput(t *testing.T) {
}
}

func TestDuplicates(t *testing.T) {
for range 10 {
output, err := runSCC("-f", "json", "-d", "./examples/duplicates/")
if err != nil {
t.Fatal(err)
}
if !strings.Contains(output, `"Count":1`) {
t.Fatalf("duplicates check failed, output:\n%s", output)
}
}
}

func TestCountAs(t *testing.T) {
testCases := []struct {
countAs string
expected []string
}{
{
countAs: "jsp:html",
expected: []string{"HTML"},
},
{
countAs: "JsP:html",
expected: []string{"HTML"},
},
{
countAs: "jsp:j2",
expected: []string{"Jinja"},
},
{
countAs: "jsp:html,new:java",
expected: []string{"HTML", "Java"},
},
{
countAs: "jsp:html,new:C Header",
expected: []string{"HTML", "C Header"},
},
}

for _, tc := range testCases {
output, err := runSCC("-f", "csv", "--count-as", tc.countAs, "./examples/countas/")
if err != nil {
t.Fatal(err)
}
for _, expectedLang := range tc.expected {
if !strings.Contains(output, expectedLang+",") {
t.Errorf("count as failed, count as: %s, output:\n%s", tc.countAs, output)
}
}
}
}

func TestRemapUnknown(t *testing.T) {
t.Parallel()
output, err := runSCC("-f", "csv", "--remap-unknown", "-*- C++ -*-:C Header", "./examples/remap/unknown")
if err != nil {
t.Fatal(err)
}
if !strings.Contains(output, "C Header,") {
t.Fatalf("remap unknown failed, output:\n%s", output)
}
}

func TestRemapAll(t *testing.T) {
t.Parallel()
output, err := runSCC("-f", "csv", "--remap-all", "-*- C++ -*-:C Header", "./examples/remap/java.java")
if err != nil {
t.Fatal(err)
}
if !strings.Contains(output, "C Header,") {
t.Fatalf("remap all failed, output:\n%s", output)
}
}

func TestCocomoProjectType(t *testing.T) {
projectTypes := []string{"organic", "semi-detached", "embedded", "custom,1,1,1,1"}
for _, typ := range projectTypes {
output, err := runSCC("--cocomo-project-type", typ)
if err != nil {
t.Fatal(err)
}
if !strings.Contains(output, fmt.Sprintf("Estimated Cost to Develop (%s)", typ)) ||
!strings.Contains(output, fmt.Sprintf("Estimated Schedule Effort (%s)", typ)) ||
!strings.Contains(output, fmt.Sprintf("Estimated People Required (%s)", typ)) {
t.Errorf("check cocomo project type failed: %s", typ)
}
}
}

func TestCocomoProjectTypeFallback(t *testing.T) {
unknownTypes := []string{"doesnotexist", "custom,1,1,1"}
for _, typ := range unknownTypes {
output, err := runSCC("--cocomo-project-type", typ)
if err != nil {
t.Fatal(err)
}
if !strings.Contains(output, "Estimated Cost to Develop (organic)") ||
!strings.Contains(output, "Estimated Schedule Effort (organic)") ||
!strings.Contains(output, "Estimated People Required (organic)") {
t.Errorf("check cocomo project type fallback failed: %s", typ)
}
}
}

func TestOutputBytes(t *testing.T) {
jsonOutput, err := runSCC("-f", "json")
if err != nil {
t.Fatal(err)
}
if !strings.Contains(jsonOutput, `"Bytes":`) {
t.Errorf("json output does not contain `Bytes` field, output:\n%s", jsonOutput)
}

output, err := runSCC()
if err != nil {
t.Fatal(err)
}
if !strings.Contains(output, "megabytes") {
t.Errorf("output does not contain `megabytes`, output:\n%s", output)
}
}

func TestFileGCCount(t *testing.T) {
const target = "./examples/duplicates"
files, err := os.ReadDir(target)
if err != nil {
t.Fatal(err)
}

output, err := runSCC("--file-gc-count", strconv.Itoa(len(files)-1), "-v", target)
if err != nil {
t.Fatal(err)
}
if !strings.Contains(output, "read file limit exceeded GC re-enabled") {
t.Errorf("test file GC count failed, file count: %d, limit: %d", len(files), len(files)-1)
}

output, err = runSCC("--file-gc-count", strconv.Itoa(len(files)+1), "-v", target)
if err != nil {
t.Fatal(err)
}
if strings.Contains(output, "read file limit exceeded GC re-enabled") {
t.Errorf("test file GC count failed, file count: %d, limit: %d", len(files), len(files)+1)
}
}

func TestLanguageNameTruncate(t *testing.T) {
output, err := runSCC("examples/language")
if err != nil {
Expand Down
Loading
Loading