提交 8186f1fe 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

fix a bug of showing color string in log file

上级 cd223e10
......@@ -14,6 +14,7 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/tools v0.0.0-20190716221150-e98af2309876 h1:XskQVJACjxHVCFlm4GsSEh6ZLclQPLobzuvB4DQYHtw=
golang.org/x/tools v0.0.0-20190716221150-e98af2309876/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI=
......
......@@ -3,18 +3,18 @@ package action
import (
"github.com/easysoft/zentaoatf/src/biz"
"github.com/easysoft/zentaoatf/src/model"
. "github.com/easysoft/zentaoatf/src/utils"
"github.com/easysoft/zentaoatf/src/utils"
)
func Run(scriptDir string, fileNames []string, langType string) {
var files []string
if fileNames != nil && len(fileNames) > 0 {
files, _ = GetSpecifiedFiles(scriptDir, fileNames)
files, _ = utils.GetSpecifiedFiles(scriptDir, fileNames)
} else {
files, _ = GetAllFiles(scriptDir, langType)
files, _ = utils.GetAllFiles(scriptDir, langType)
}
var report = model.TestReport{Path: scriptDir, Env: GetOs(),
var report = model.TestReport{Path: scriptDir, Env: utils.GetOs(),
Pass: 0, Fail: 0, Total: 0, Cases: make([]model.CaseLog, 0)}
biz.ExeScripts(files, scriptDir, langType, &report)
......
......@@ -9,7 +9,10 @@ import (
)
func CheckResults(files []string, dir string, langType string, report *model.TestReport) {
fmt.Printf(color.BlueString("\n=== Begin to analyse test result ===\n\n"))
fmt.Println()
msg := "Begin to analyse test result"
utils.PrintWholeLine(msg, "=", color.FgBlue)
fmt.Println("\n")
for _, scriptFile := range files {
logFile := utils.ScriptToLogName(dir, scriptFile)
......@@ -99,3 +102,8 @@ func PrintAndLog(logs *[]string, str string) {
*logs = append(*logs, str)
fmt.Println(str)
}
func PrintAndLogColorLn(logs *[]string, str string, attr color.Attribute) {
*logs = append(*logs, str)
color.New(attr).Printf(str + "\n")
}
......@@ -11,7 +11,7 @@ import (
)
func ExeScripts(files []string, dir string, langType string, report *model.TestReport) {
msg := "Begin to run test scripts"
msg := "Begin to run"
utils.PrintWholeLine(msg, "=", color.FgBlue)
startTime := time.Now().Unix()
......@@ -21,7 +21,8 @@ func ExeScripts(files []string, dir string, langType string, report *model.TestR
ExeScript(file, langType, dir)
}
fmt.Println(color.BlueString("=== End to run test scripts ==="))
msg = "End to run"
utils.PrintWholeLine(msg, "=", color.FgBlue)
endTime := time.Now().Unix()
secs := endTime - startTime
......@@ -44,12 +45,22 @@ func ExeScript(file string, langType string, dir string) {
}
startTime := time.Now()
fmt.Printf(color.CyanString("\n--- Start %s %s"), file, startTime.Format("2006-01-02 15:04:05")+"\n")
fmt.Println("")
msg := fmt.Sprintf("Start %s at %s", file, startTime.Format("2006-01-02 15:04:05"))
utils.PrintWholeLine(msg, "-", color.FgCyan)
fmt.Println("")
output := utils.ExecCommand(command)
utils.WriteFile(logFile, strings.Join(output, ""))
entTime := time.Now()
secs := int64(entTime.Sub(startTime) / time.Second)
fmt.Printf(color.CyanString("--- End %s %dsec %s"), file, secs, "\n")
msg = fmt.Sprintf("End %s at %s, %d secs", file, startTime.Format("2006-01-02 15:04:05"), secs)
utils.PrintWholeLine(msg, "-", color.FgCyan)
fmt.Println("")
}
......@@ -21,14 +21,18 @@ func Print(report model.TestReport, workDir string) {
PrintAndLog(&logs, fmt.Sprintf("From %s to %s, duration %d sec",
startSec.Format("2006-01-02 15:04:05"), endSec.Format("2006-01-02 15:04:05"), report.Duration))
PrintAndLog(&logs, fmt.Sprintf("Total: %d \n %s\n %s\n %s",
report.Total,
color.GreenString("Pass: %d", report.Pass),
color.RedString("Fail: %d", report.Fail),
color.BlueString("Skip: %d", report.Skip)))
PrintAndLog(&logs, fmt.Sprintf("Total: %d", report.Total))
PrintAndLogColorLn(&logs, fmt.Sprintf("Pass: %d", report.Pass), color.FgGreen)
PrintAndLogColorLn(&logs, fmt.Sprintf("Fail: %d", report.Fail), color.FgRed)
PrintAndLogColorLn(&logs, fmt.Sprintf("Skip: %d", report.Skip), color.FgYellow)
for _, cs := range report.Cases {
PrintAndLog(&logs, fmt.Sprintf("\n%s %s", colorStatus(cs.Status.String()), cs.Path))
str := "\n%s %s"
status := cs.Status.String()
statusColor := colorStatus(status)
logs = append(logs, fmt.Sprintf(str, status, cs.Path))
fmt.Printf(str, statusColor, cs.Path)
if len(cs.Steps) > 0 {
count := 0
......@@ -37,8 +41,12 @@ func Print(report model.TestReport, workDir string) {
PrintAndLog(&logs, "")
}
PrintAndLog(&logs, fmt.Sprintf(" Step %d %s: %s", step.Numb, step.Name,
colorStatus(utils.BoolToPass(step.Status))))
str := " Step %d %s: %s"
status := utils.BoolToPass(step.Status)
statusColor := colorStatus(status)
logs = append(logs, fmt.Sprintf(str, step.Numb, step.Name, status))
fmt.Printf(str, step.Numb, step.Name, statusColor+"\n")
count1 := 0
for _, cp := range step.CheckPoints {
......
......@@ -28,7 +28,7 @@ func InitConfig() {
InitI118(Conf.Language)
color.Blue(I118Prt.Sprintf("current_config", ""))
// print config
// print config object
val := reflect.ValueOf(Conf)
typeOfS := val.Type()
for i := 0; i < reflect.ValueOf(Conf).NumField(); i++ {
......
package utils
import (
"fmt"
"github.com/fatih/color"
"os"
"os/exec"
"regexp"
"strconv"
"strings"
"unicode/utf8"
)
func InitScreenSize() {
......@@ -42,13 +42,11 @@ func InitScreenSize() {
}
func PrintWholeLine(msg string, char string, attr color.Attribute) {
fixLen := (Conf.Width - len(msg)) / 2
fixLen := (Conf.Width - utf8.RuneCountInString(msg)) / 2
if fixLen < 0 { // debug mode
fixLen = 6
fixLen = 10
}
fmt.Println(fixLen)
fixStr := strings.Repeat(char, fixLen)
clr := color.New(attr)
......
GO_ENABLED=0 GOOS=linux GOARCH=amd64 go build src/atf.go
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build src/atf.go
go-bindata -o=res/res.go -pkg=res res/
\ No newline at end of file
go-bindata -o=res/res.go -pkg=res res/
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册