提交 8367defc 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

run test script/suite and show results

上级 d239da51
package biz package biz
import ( import (
"fmt"
"github.com/easysoft/zentaoatf/src/misc" "github.com/easysoft/zentaoatf/src/misc"
"github.com/easysoft/zentaoatf/src/model" "github.com/easysoft/zentaoatf/src/model"
"github.com/easysoft/zentaoatf/src/utils" "github.com/easysoft/zentaoatf/src/utils"
...@@ -10,8 +9,8 @@ import ( ...@@ -10,8 +9,8 @@ import (
) )
func CheckResults(files []string, dir string, langType string, report *model.TestReport) { func CheckResults(files []string, dir string, langType string, report *model.TestReport) {
fmt.Println("\n") Printt("\n")
PrintWholeLine(utils.I118Prt.Sprintf("begin_analyse"), "=", color.FgBlue) PrintWholeLine(utils.I118Prt.Sprintf("begin_analyse"), "=", color.FgCyan)
for _, scriptFile := range files { for _, scriptFile := range files {
logFile := utils.ScriptToLogName(dir, scriptFile) logFile := utils.ScriptToLogName(dir, scriptFile)
...@@ -73,7 +72,6 @@ func ValidateTestCase(scriptFile string, langType string, ...@@ -73,7 +72,6 @@ func ValidateTestCase(scriptFile string, langType string,
} }
func ValidateStep(langType string, expectLines []string, actualLines []string) (bool, []model.CheckPointLog) { func ValidateStep(langType string, expectLines []string, actualLines []string) (bool, []model.CheckPointLog) {
stepResult := true stepResult := true
checkpointLogs := make([]model.CheckPointLog, 0) checkpointLogs := make([]model.CheckPointLog, 0)
......
package biz package biz
import ( import (
"fmt"
"github.com/easysoft/zentaoatf/src/misc" "github.com/easysoft/zentaoatf/src/misc"
"github.com/easysoft/zentaoatf/src/model" "github.com/easysoft/zentaoatf/src/model"
"github.com/easysoft/zentaoatf/src/utils" "github.com/easysoft/zentaoatf/src/utils"
...@@ -11,7 +10,7 @@ import ( ...@@ -11,7 +10,7 @@ import (
) )
func ExeScripts(files []string, dir string, langType string, report *model.TestReport) { func ExeScripts(files []string, dir string, langType string, report *model.TestReport) {
PrintWholeLine(utils.I118Prt.Sprintf("start_execution", ""), "=", color.FgBlue) PrintWholeLine(utils.I118Prt.Sprintf("start_execution", ""), "=", color.FgCyan)
startTime := time.Now().Unix() startTime := time.Now().Unix()
report.StartTime = startTime report.StartTime = startTime
...@@ -20,7 +19,7 @@ func ExeScripts(files []string, dir string, langType string, report *model.TestR ...@@ -20,7 +19,7 @@ func ExeScripts(files []string, dir string, langType string, report *model.TestR
ExeScript(file, langType, dir) ExeScript(file, langType, dir)
} }
PrintWholeLine(utils.I118Prt.Sprintf("end_execution", ""), "=", color.FgBlue) PrintWholeLine(utils.I118Prt.Sprintf("end_execution", ""), "=", color.FgCyan)
endTime := time.Now().Unix() endTime := time.Now().Unix()
secs := endTime - startTime secs := endTime - startTime
...@@ -44,22 +43,18 @@ func ExeScript(file string, langType string, dir string) { ...@@ -44,22 +43,18 @@ func ExeScript(file string, langType string, dir string) {
startTime := time.Now() startTime := time.Now()
fmt.Println("")
msg := utils.I118Prt.Sprintf("start_case", file, startTime.Format("2006-01-02 15:04:05")) msg := utils.I118Prt.Sprintf("start_case", file, startTime.Format("2006-01-02 15:04:05"))
PrintWholeLine(msg, "-", color.FgCyan) PrintWholeLine(msg, "-", color.FgCyan)
//fmt.Println("")
output := utils.ExecCommand(command) output := utils.ExecCommand(command)
utils.WriteFile(logFile, strings.Join(output, "")) utils.WriteFile(logFile, strings.Join(output, ""))
Printt(strings.Join(output, "")) if utils.RunFromCui {
Printt(strings.Join(output, ""))
}
entTime := time.Now() entTime := time.Now()
secs := int64(entTime.Sub(startTime) / time.Second) secs := int64(entTime.Sub(startTime) / time.Second)
msg = utils.I118Prt.Sprintf("end_case", file, entTime.Format("2006-01-02 15:04:05"), secs) msg = utils.I118Prt.Sprintf("end_case", file, entTime.Format("2006-01-02 15:04:05"), secs)
PrintWholeLine(msg, "-", color.FgCyan) PrintWholeLine(msg, "-", color.FgCyan)
//fmt.Println("")
} }
...@@ -14,7 +14,7 @@ func PrintWholeLine(msg string, char string, attr color.Attribute) { ...@@ -14,7 +14,7 @@ func PrintWholeLine(msg string, char string, attr color.Attribute) {
var postfixLen int var postfixLen int
if utils.RunFromCui { if utils.RunFromCui {
maxX, _ := utils.Cui.Size() maxX, _ := utils.Cui.Size()
postfixLen = maxX - utils.LeftWidth - utf8.RuneCountInString(msg) - 8 postfixLen = maxX - utils.LeftWidth - utf8.RuneCountInString(msg) - 9
} else { } else {
postfixLen = utils.Prefer.Width - utf8.RuneCountInString(msg) - 6 postfixLen = utils.Prefer.Width - utf8.RuneCountInString(msg) - 6
if postfixLen < 0 { // no width in debug mode if postfixLen < 0 { // no width in debug mode
...@@ -71,7 +71,7 @@ func Printt(str string) { ...@@ -71,7 +71,7 @@ func Printt(str string) {
output = color.Output output = color.Output
} }
fmt.Fprintf(output, str+"\n") fmt.Fprintf(output, str)
} }
func coloredStatus(status string) string { func coloredStatus(status string) string {
......
...@@ -26,7 +26,7 @@ func Print(report model.TestReport, workDir string) { ...@@ -26,7 +26,7 @@ func Print(report model.TestReport, workDir string) {
PrintAndLogColorLn(&logs, fmt.Sprintf(" %s: %d", utils.I118Prt.Sprintf("skip"), report.Skip), color.FgYellow) PrintAndLogColorLn(&logs, fmt.Sprintf(" %s: %d", utils.I118Prt.Sprintf("skip"), report.Skip), color.FgYellow)
for _, cs := range report.Cases { for _, cs := range report.Cases {
str := "\n %s %s " str := "\n %s %s \n"
status := cs.Status.String() status := cs.Status.String()
statusColor := coloredStatus(status) statusColor := coloredStatus(status)
...@@ -55,9 +55,9 @@ func Print(report model.TestReport, workDir string) { ...@@ -55,9 +55,9 @@ func Print(report model.TestReport, workDir string) {
cpStatus := utils.BoolToPass(step.Status) cpStatus := utils.BoolToPass(step.Status)
cpStatusColored := coloredStatus(cpStatus) cpStatusColored := coloredStatus(cpStatus)
logs = append(logs, fmt.Sprintf(" %s%d: %s", utils.I118Prt.Sprintf("checkpoint"), cp.Numb, logs = append(logs, fmt.Sprintf(" %s%d: %s\n", utils.I118Prt.Sprintf("checkpoint"), cp.Numb,
utils.BoolToPass(cp.Status))) utils.BoolToPass(cp.Status)))
Printt(fmt.Sprintf(" %s%d: %s", utils.I118Prt.Sprintf("checkpoint"), cp.Numb, cpStatusColored)) Printt(fmt.Sprintf(" %s%d: %s\n", utils.I118Prt.Sprintf("checkpoint"), cp.Numb, cpStatusColored))
PrintAndLog(&logs, fmt.Sprintf(" %s %s", utils.I118Prt.Sprintf("expect_result"), cp.Expect)) PrintAndLog(&logs, fmt.Sprintf(" %s %s", utils.I118Prt.Sprintf("expect_result"), cp.Expect))
PrintAndLog(&logs, fmt.Sprintf(" %s %s", utils.I118Prt.Sprintf("actual_result"), cp.Actual)) PrintAndLog(&logs, fmt.Sprintf(" %s %s", utils.I118Prt.Sprintf("actual_result"), cp.Actual))
......
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
func Summary(file string) { func Summary(file string) {
content := utils.ReadFile(file) content := utils.ReadFile(file)
myExp := regexp.MustCompile(`<<<TC[\S\s]*caseId:([^\n]*)\n+title:([^\n]*)\n`) myExp := regexp.MustCompile(`<<TC[\S\s]*caseId:([^\n]*)\n+title:([^\n]*)\n`)
arr := myExp.FindStringSubmatch(content) arr := myExp.FindStringSubmatch(content)
if len(arr) > 2 { if len(arr) > 2 {
...@@ -25,7 +25,7 @@ func Detail(file string) { ...@@ -25,7 +25,7 @@ func Detail(file string) {
content := utils.ReadFile(file) content := utils.ReadFile(file)
myExp := regexp.MustCompile( myExp := regexp.MustCompile(
`<<<TC[\S\s]*caseId:([^\n]*)\n+title:([^\n]*)\n+steps:([\S\s]*)\n+expects:([\S\s]*?)\n+(readme:|TC;)`) `<<TC[\S\s]*caseId:([^\n]*)\n+title:([^\n]*)\n+steps:([\S\s]*)\n+expects:([\S\s]*?)\n+(readme:|TC;)`)
arr := myExp.FindStringSubmatch(content) arr := myExp.FindStringSubmatch(content)
if len(arr) > 2 { if len(arr) > 2 {
......
...@@ -174,7 +174,7 @@ func MkDirIfNeeded(dir string) { ...@@ -174,7 +174,7 @@ func MkDirIfNeeded(dir string) {
func ReadCheckpointSteps(file string) []string { func ReadCheckpointSteps(file string) []string {
content := ReadFile(file) content := ReadFile(file)
myExp := regexp.MustCompile(`<<<TC[\S\s]*steps:[^\n]*\n*([\S\s]*)\n+expects:`) myExp := regexp.MustCompile(`<<TC[\S\s]*steps:[^\n]*\n*([\S\s]*)\n+expects:`)
arr := myExp.FindStringSubmatch(content) arr := myExp.FindStringSubmatch(content)
str := "" str := ""
...@@ -191,7 +191,7 @@ func ReadCheckpointSteps(file string) []string { ...@@ -191,7 +191,7 @@ func ReadCheckpointSteps(file string) []string {
func ReadExpect(file string) [][]string { func ReadExpect(file string) [][]string {
content := ReadFile(file) content := ReadFile(file)
myExp := regexp.MustCompile(`<<<TC[\S\s]*expects:[^\n]*\n*([\S\s]*?)(readme:|TC;)`) myExp := regexp.MustCompile(`<<TC[\S\s]*expects:[^\n]*\n+([\S\s]*?)(readme:|TC;)`)
arr := myExp.FindStringSubmatch(content) arr := myExp.FindStringSubmatch(content)
str := "" str := ""
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册