Skip to content

Commit

Permalink
fix: script to count the number of converted tests (#189)
Browse files Browse the repository at this point in the history
* fix: script to count the number of converted tests

Signed-off-by: Meenal Trivedi <meenaltrivedi6102@gmail.com>

* fix

Signed-off-by: Meenal Trivedi <meenaltrivedi6102@gmail.com>
  • Loading branch information
meenal06 authored Aug 10, 2021
1 parent fca2bda commit 5ae7105
Showing 1 changed file with 32 additions and 17 deletions.
49 changes: 32 additions & 17 deletions cmd/sytest-coverage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"go/parser"
"go/token"
"io/fs"
"io/ioutil"
"os"
"regexp"
Expand Down Expand Up @@ -49,24 +50,14 @@ func main() {
panic(err)
}
convertedTests := make(map[string]bool)
for _, file := range files {
fset := token.NewFileSet()
astFile, err := parser.ParseFile(fset, "./tests/"+file.Name(), nil, parser.ParseComments)
if err != nil {
panic(err)
}
for _, cmt := range astFile.Comments {
comment := strings.TrimSpace(cmt.Text())
lines := strings.Split(comment, "\n")
for _, line := range lines {
_, ok := testNameToFilename[line]
if !ok {
continue
}
convertedTests[line] = true
}
}

countConvertedTests(files, convertedTests, testNameToFilename, "./tests/")
files, err = ioutil.ReadDir("./tests/csapi")
if err != nil {
panic(err)
}
countConvertedTests(files, convertedTests, testNameToFilename, "./tests/csapi/")

numComplementTests := len(convertedTests)
for _, fname := range sorted(filenameToTestName) {
testNames := filenameToTestName[fname]
Expand All @@ -93,6 +84,30 @@ func main() {
fmt.Printf("\nTOTAL: %d/%d tests converted\n", numComplementTests, total)
}

func countConvertedTests(files []fs.FileInfo, convertedTests map[string]bool, testNameToFilename map[string]string, path string) {
for _, file := range files {
fset := token.NewFileSet()
if file.Name() == "csapi" {
continue
}
astFile, err := parser.ParseFile(fset, path+file.Name(), nil, parser.ParseComments)
if err != nil {
panic(err)
}
for _, cmt := range astFile.Comments {
comment := strings.TrimSpace(cmt.Text())
lines := strings.Split(comment, "\n")
for _, line := range lines {
_, ok := testNameToFilename[line]
if !ok {
continue
}
convertedTests[line] = true
}
}
}
}

func sorted(in map[string][]string) []string {
out := make([]string, len(in))
i := 0
Expand Down

0 comments on commit 5ae7105

Please sign in to comment.