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

rerun failed cases in test result

上级 1c8e7f55
package action
import (
"github.com/easysoft/zentaoatf/src/biz"
"github.com/easysoft/zentaoatf/src/model"
. "github.com/easysoft/zentaoatf/src/utils"
)
func Rerun(resultFile string) {
files, scriptDir, langType, _ := GetFailedFiles(resultFile)
var report = model.TestReport{Path: scriptDir, Env: GetOs(),
Pass: 0, Fail: 0, Total: 0, Cases: make([]model.CaseLog, 0)}
biz.ExeScripts(files, scriptDir, langType, &report)
biz.CheckResults(files, scriptDir, langType, &report)
biz.Print(report, scriptDir)
}
......@@ -14,6 +14,7 @@ func main() {
var independentExpectFile bool
var fromUrl string
var path string
var files strSlice
runSet := flag.NewFlagSet("atf run: \n Run test scripts in specified folder", flag.ContinueOnError)
......@@ -21,6 +22,9 @@ func main() {
runSet.StringVar(&langType, "l", "", "Script Language like python, php etc.")
runSet.Var(&files, "f", "Script files to run, no need langType if specified")
rerunSet := flag.NewFlagSet("atf rerun: \n Rerun failed test scripts in specified result", flag.ContinueOnError)
rerunSet.StringVar(&path, "p", "", "Test result file path")
genSet := flag.NewFlagSet("atf gen: \n Generate test scripts from zentao test cases", flag.ContinueOnError)
genSet.StringVar(&fromUrl, "u", "", "Remote interface for test case export")
genSet.StringVar(&langType, "l", "", "Script Language like python, php etc.")
......@@ -64,6 +68,15 @@ func main() {
action.Run(scriptDir, files, langType)
}
}
case "rerun":
if err := rerunSet.Parse(os.Args[2:]); err == nil {
if path == "" {
rerunSet.Usage()
os.Exit(1)
} else {
action.Rerun(path)
}
}
case "gen":
if err := genSet.Parse(os.Args[2:]); err == nil {
if fromUrl == "" || langType == "" {
......
......@@ -57,5 +57,5 @@ func Print(report model.TestReport, workDir string) {
}
}
utils.WriteFile(workDir+"/logs/report.txt", strings.Join(logs, "\n"))
utils.WriteFile(workDir+"/logs/result-"+utils.DateTimeStrLong(time.Now())+".txt", strings.Join(logs, "\n"))
}
......@@ -33,7 +33,7 @@ func (c ResultStatus) String() string {
case PASS:
return "PASS"
case FAIL:
return "FAILL"
return "FAIL"
case SKIP:
return "SKIP"
}
......
package utils
import (
"time"
)
func DateStr(tm time.Time) string {
return tm.Format("2006-01-02")
}
func TimeStr(tm time.Time) string {
return tm.Format("15:04:05")
}
func DateTimeStr(tm time.Time) string {
return tm.Format("2006-01-02 15:04:05")
}
func DateTimeStrLong(tm time.Time) string {
return tm.Format("20060102150405")
}
......@@ -96,6 +96,37 @@ func GetSpecifiedFiles(dirPth string, fileNames []string) (files []string, err e
return ret, nil
}
func GetFailedFiles(resultFile string) ([]string, string, string, error) {
ret := make([]string, 0)
dir := ""
extName := ""
content := ReadFile(resultFile)
reg := regexp.MustCompile(`\nFAIL\s([^\n]+)\n`)
arr := reg.FindAllStringSubmatch(content, -1)
if len(arr) > 1 {
for _, file := range arr {
if len(file) == 1 {
continue
}
caseFile := RemoveBlankLine(file[1])
ret = append(ret, caseFile)
if dir == "" {
dir = path.Dir(caseFile)
}
if extName == "" {
extName = strings.TrimLeft(path.Ext(caseFile), ".")
}
}
}
return ret, dir, extName, nil
}
func MkDir(dir string) {
if !CheckFileIsExist(dir) {
os.Mkdir(dir, os.ModePerm)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册