提交 0df77d7d 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

add prefix space before case id when printing case result line

上级 d1c934d3
此差异已折叠。
......@@ -13,6 +13,7 @@ import (
logUtils "github.com/easysoft/zentaoatf/src/utils/log"
stringUtils "github.com/easysoft/zentaoatf/src/utils/string"
"github.com/easysoft/zentaoatf/src/utils/vari"
zentaoUtils "github.com/easysoft/zentaoatf/src/utils/zentao"
"github.com/mattn/go-runewidth"
"path"
"strconv"
......@@ -141,14 +142,21 @@ func runCases(files []string) {
Pass: 0, Fail: 0, Total: 0, Cases: make([]model.CaseLog, 0)}
pathMaxWidth := 0
numbMaxWidth := 0
for _, file := range casesToRun {
lent := runewidth.StringWidth(file)
if lent > pathMaxWidth {
pathMaxWidth = lent
}
content := fileUtils.ReadFile(file)
caseId := zentaoUtils.ReadCaseId(content)
if len(caseId) > numbMaxWidth {
numbMaxWidth = len(caseId)
}
}
testingService.ExeScripts(casesToRun, &report, pathMaxWidth)
testingService.ExeScripts(casesToRun, &report, pathMaxWidth, numbMaxWidth)
testingService.Report(report, pathMaxWidth)
}
......
......@@ -16,7 +16,7 @@ import (
"strings"
)
func CheckCaseResult(file string, logs string, report *model.TestReport, idx int, total int, secs string, pathMaxWidth int) {
func CheckCaseResult(file string, logs string, report *model.TestReport, idx int, total int, secs string, pathMaxWidth int, numbMaxWidth int) {
_, _, expectMap := scriptUtils.GetStepAndExpectMap(file)
isIndependent, expectIndependentContent := zentaoUtils.GetDependentExpect(file)
if isIndependent {
......@@ -26,12 +26,12 @@ func CheckCaseResult(file string, logs string, report *model.TestReport, idx int
skip, actualArr := zentaoUtils.ReadLogArr(logs)
language := langUtils.GetLangByFile(file)
ValidateCaseResult(file, language, expectMap, skip, actualArr, report, idx, total, secs, pathMaxWidth)
ValidateCaseResult(file, language, expectMap, skip, actualArr, report, idx, total, secs, pathMaxWidth, numbMaxWidth)
}
func ValidateCaseResult(scriptFile string, langType string,
expectMap maps.Map, skip bool, actualArr [][]string, report *model.TestReport,
idx int, total int, secs string, pathMaxWidth int) {
idx int, total int, secs string, pathMaxWidth int, numbMaxWidth int) {
_, caseId, productId, title := zentaoUtils.GetCaseInfo(scriptFile)
......@@ -85,6 +85,7 @@ func ValidateCaseResult(scriptFile string, langType string,
// print case result to console
statusColor := logUtils.ColoredStatus(cs.Status)
width := strconv.Itoa(len(strconv.Itoa(total)))
numbWidth := strconv.Itoa(numbMaxWidth)
path := cs.Path
lent := runewidth.StringWidth(path)
......@@ -94,7 +95,7 @@ func ValidateCaseResult(scriptFile string, langType string,
path += postFix
}
format := "(%" + width + "d/%d) %s [%s] %d.%s (%ss)"
format := "(%" + width + "d/%d) %s [%s] [%" + numbWidth + "d. %s] (%ss)"
logUtils.Screen(fmt.Sprintf(format, idx+1, total, statusColor, path, cs.Id, cs.Title, secs))
logUtils.Result(fmt.Sprintf(format, idx+1, total, i118Utils.I118Prt.Sprintf(cs.Status), path, cs.Id, cs.Title, secs))
}
......
......@@ -10,7 +10,7 @@ import (
"time"
)
func ExeScripts(casesToRun []string, report *model.TestReport, pathMaxWidth int) {
func ExeScripts(casesToRun []string, report *model.TestReport, pathMaxWidth int, numbMaxWidth int) {
now := time.Now()
startTime := now.Unix()
report.StartTime = startTime
......@@ -19,7 +19,7 @@ func ExeScripts(casesToRun []string, report *model.TestReport, pathMaxWidth int)
i118Utils.I118Prt.Sprintf("found_scripts", len(casesToRun)) + "\n")
for idx, file := range casesToRun {
ExeScript(file, report, idx, len(casesToRun), pathMaxWidth)
ExeScript(file, report, idx, len(casesToRun), pathMaxWidth, numbMaxWidth)
}
endTime := time.Now().Unix()
......@@ -29,7 +29,7 @@ func ExeScripts(casesToRun []string, report *model.TestReport, pathMaxWidth int)
report.Duration = secs
}
func ExeScript(file string, report *model.TestReport, idx int, total int, pathMaxWidth int) {
func ExeScript(file string, report *model.TestReport, idx int, total int, pathMaxWidth int, numbMaxWidth int) {
startTime := time.Now()
logUtils.Log("===start " + file + " at " + startTime.Format("2006-01-02 15:04:05"))
......@@ -48,7 +48,7 @@ func ExeScript(file string, report *model.TestReport, idx int, total int, pathMa
logUtils.Log("===end " + file + " at " + entTime.Format("2006-01-02 15:04:05"))
CheckCaseResult(file, logs, report, idx, total, secs, pathMaxWidth)
CheckCaseResult(file, logs, report, idx, total, secs, pathMaxWidth, numbMaxWidth)
if idx < total-1 {
logUtils.Log("")
......
......@@ -102,16 +102,16 @@ func GetCaseInfo(file string) (bool, int, int, string) {
return pass, caseId, productId, title
}
func ReadScriptCheckpoints(file string) ([]string, [][]string) {
_, expectIndependentContent := GetDependentExpect(file)
content := fileUtils.ReadFile(file)
_, checkpoints := ReadCaseInfo(content)
cpStepArr, expectArr := getCheckpointStepArr(checkpoints, expectIndependentContent)
return cpStepArr, expectArr
}
//func ReadScriptCheckpoints(file string) ([]string, [][]string) {
// _, expectIndependentContent := GetDependentExpect(file)
//
// content := fileUtils.ReadFile(file)
// _, checkpoints := ReadCaseInfo(content)
//
// cpStepArr, expectArr := getCheckpointStepArr(checkpoints, expectIndependentContent)
//
// return cpStepArr, expectArr
//}
func getCheckpointStepArr(content string, expectIndependentContent string) ([]string, [][]string) {
cpStepArr := make([]string, 0)
expectArr := make([][]string, 0)
......@@ -272,6 +272,17 @@ func ReadCaseInfo(content string) (string, string) {
return "", ""
}
func ReadCaseId(content string) string {
myExp := regexp.MustCompile(`(?s)\[case\].*\ncid=((?U:.*))\n.*\[esac\]`)
arr := myExp.FindStringSubmatch(content)
if len(arr) > 1 {
id := strings.TrimSpace(arr[1])
return id
}
return ""
}
func GetDependentExpect(file string) (bool, string) {
expectIndependentFile := strings.Replace(file, path.Ext(file), ".exp", -1)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册