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

skip a test case when scripts print a line like "SKIP/skip"

上级 2808484a
......@@ -2,10 +2,9 @@ package biz
import (
"fmt"
"github.com/easysoft/zentaoatf/src/misc"
"github.com/easysoft/zentaoatf/src/model"
"github.com/easysoft/zentaoatf/src/utils"
"strings"
"time"
)
func CheckResults(dir string, langType string, report *model.TestReport) {
......@@ -18,42 +17,50 @@ func CheckResults(dir string, langType string, report *model.TestReport) {
stepArr := utils.ReadCheckpointSteps(scriptFile)
expectArr := utils.ReadExpect(scriptFile)
logArr := utils.ReadLog(logFile)
skip, logArr := utils.ReadLog(logFile)
ValidateTestCase(scriptFile, langType, stepArr, expectArr, logArr, report)
ValidateTestCase(scriptFile, langType, stepArr, expectArr, skip, logArr, report)
}
}
func ValidateTestCase(scriptFile string, langType string,
stepArr []string, expectArr [][]string, actualArr [][]string, report *model.TestReport) {
stepArr []string, expectArr [][]string, skip bool, actualArr [][]string, report *model.TestReport) {
stepLogs := make([]model.StepLog, 0)
caseResult := misc.PASS
caseResult := true
indx := 0
for _, step := range stepArr {
var expectLines []string
if len(expectArr) > indx {
expectLines = expectArr[indx]
}
if skip {
caseResult = misc.SKIP
} else {
indx := 0
for _, step := range stepArr {
var expectLines []string
if len(expectArr) > indx {
expectLines = expectArr[indx]
}
var actualLines []string
if len(actualArr) > indx {
actualLines = actualArr[indx]
}
var actualLines []string
if len(actualArr) > indx {
actualLines = actualArr[indx]
}
stepResult, checkpointLogs := ValidateStep(langType, expectLines, actualLines)
step := model.StepLog{Numb: indx + 1, Name: step, Status: stepResult, CheckPoints: checkpointLogs}
stepLogs = append(stepLogs, step)
stepResult, checkpointLogs := ValidateStep(langType, expectLines, actualLines)
step := model.StepLog{Numb: indx + 1, Name: step, Status: stepResult, CheckPoints: checkpointLogs}
stepLogs = append(stepLogs, step)
if !stepResult {
caseResult = misc.FAIL
}
indx++
indx++
}
}
if !caseResult {
if caseResult == misc.FAIL {
report.Fail = report.Fail + 1
} else {
} else if caseResult == misc.PASS {
report.Pass = report.Pass + 1
} else if caseResult == misc.SKIP {
report.Skip = report.Skip + 1
}
report.Total = report.Total + 1
......@@ -89,56 +96,6 @@ func ValidateStep(langType string, expectLines []string, actualLines []string) (
}
func Print(report model.TestReport, workDir string) {
startSec := time.Unix(report.StartTime, 0)
endSec := time.Unix(report.EndTime, 0)
logs := make([]string, 0)
PrintAndLog(&logs, fmt.Sprintf("Run scripts in folder \"%s\" on %s OS\n",
report.Path, report.Env))
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, Fail: %d, Pass: %d",
report.Total, report.Pass, report.Fail))
for _, cs := range report.Cases {
PrintAndLog(&logs, fmt.Sprintf("\n%s: %t", cs.Path, cs.Status))
if len(cs.Steps) > 0 {
count := 0
for _, step := range cs.Steps {
if count > 0 { // 空行
PrintAndLog(&logs, "")
}
PrintAndLog(&logs, fmt.Sprintf(" Step %d %s: %t", step.Numb, step.Name, step.Status))
count1 := 0
for _, cp := range step.CheckPoints {
if count1 > 0 { // 空行
PrintAndLog(&logs, "")
}
PrintAndLog(&logs, fmt.Sprintf(" Checkpoint %d: %t", cp.Numb, cp.Status))
PrintAndLog(&logs, fmt.Sprintf(" Expect %s", cp.Expect))
PrintAndLog(&logs, fmt.Sprintf(" Actual %s", cp.Actual))
count1++
}
count++
}
} else {
PrintAndLog(&logs, " No check points")
}
}
utils.WriteFile(workDir+"/logs/report.txt", strings.Join(logs, "\n"))
}
func PrintAndLog(logs *[]string, str string) {
*logs = append(*logs, str)
fmt.Println(str)
......
package biz
import (
"fmt"
"github.com/easysoft/zentaoatf/src/model"
"github.com/easysoft/zentaoatf/src/utils"
"strings"
"time"
)
func Print(report model.TestReport, workDir string) {
startSec := time.Unix(report.StartTime, 0)
endSec := time.Unix(report.EndTime, 0)
logs := make([]string, 0)
PrintAndLog(&logs, fmt.Sprintf("Run scripts in folder \"%s\" on %s OS\n",
report.Path, report.Env))
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, Fail: %d, Pass: %d, Skip: %d",
report.Total, report.Pass, report.Fail, report.Skip))
for _, cs := range report.Cases {
PrintAndLog(&logs, fmt.Sprintf("\n%s %s", cs.Status.String(), cs.Path))
if len(cs.Steps) > 0 {
count := 0
for _, step := range cs.Steps {
if count > 0 { // 空行
PrintAndLog(&logs, "")
}
PrintAndLog(&logs, fmt.Sprintf(" Step %d %s: %s", step.Numb, step.Name,
utils.BoolToPass(step.Status)))
count1 := 0
for _, cp := range step.CheckPoints {
if count1 > 0 { // 空行
PrintAndLog(&logs, "")
}
PrintAndLog(&logs, fmt.Sprintf(" Checkpoint %d: %s", cp.Numb,
utils.BoolToPass(cp.Status)))
PrintAndLog(&logs, fmt.Sprintf(" Expect %s", cp.Expect))
PrintAndLog(&logs, fmt.Sprintf(" Actual %s", cp.Actual))
count1++
}
count++
}
} else {
PrintAndLog(&logs, " No check points")
}
}
utils.WriteFile(workDir+"/logs/report.txt", strings.Join(logs, "\n"))
}
......@@ -6,7 +6,6 @@ const (
PHP LangType = iota
PYTHON
GO
UNKNOWN
)
func (c LangType) String() string {
......@@ -20,3 +19,23 @@ func (c LangType) String() string {
}
return "unknown"
}
type ResultStatus int
const (
PASS ResultStatus = iota
FAIL
SKIP
)
func (c ResultStatus) String() string {
switch c {
case PASS:
return "PASS"
case FAIL:
return "FAILL"
case SKIP:
return "SKIP"
}
return "UNKNOWN"
}
package model
import "github.com/easysoft/zentaoatf/src/misc"
type Response struct {
Code int
Cases []TestCase
......@@ -25,6 +27,7 @@ type TestReport struct {
Pass int
Fail int
Skip int
Total int
StartTime int64
EndTime int64
......@@ -35,7 +38,7 @@ type TestReport struct {
type CaseLog struct {
Numb int
Path string
Status bool
Status misc.ResultStatus
Steps []StepLog
}
......
......@@ -126,11 +126,11 @@ func ReadExpect(file string) [][]string {
return ret
}
func ReadLog(logFile string) [][]string {
func ReadLog(logFile string) (bool, [][]string) {
str := ReadFile(logFile)
ret := GenLogArr(str)
return ret
skip, ret := GenLogArr(str)
return skip, ret
}
func GenCheckpointStepArr(str string) []string {
......@@ -147,17 +147,23 @@ func GenCheckpointStepArr(str string) []string {
}
func GenExpectArr(str string) [][]string {
return GenArr(str)
_, arr := GenArr(str, false)
return arr
}
func GenLogArr(str string) [][]string {
return GenArr(str)
func GenLogArr(str string) (bool, [][]string) {
skip, arr := GenArr(str, true)
return skip, arr
}
func GenArr(str string) [][]string {
func GenArr(str string, checkSkip bool) (bool, [][]string) {
ret := make([][]string, 0)
indx := -1
for _, line := range strings.Split(str, "\n") {
line := strings.TrimSpace(line)
if checkSkip && strings.ToLower(line) == "skip" {
return true, nil
}
if line == "#" {
ret = append(ret, make([]string, 0))
indx++
......@@ -168,5 +174,5 @@ func GenArr(str string) [][]string {
}
}
return ret
return false, ret
}
package utils
import (
"github.com/easysoft/zentaoatf/src/misc"
"os"
"path"
"regexp"
......@@ -37,6 +38,14 @@ func ScriptToExpectName(file string) string {
return expectName
}
func BoolToPass(b bool) string {
if b {
return misc.PASS.String()
} else {
return misc.FAIL.String()
}
}
func GetOs() string {
osName := runtime.GOOS
......
......@@ -14,7 +14,7 @@ readme:
TC;
/* 此处编写操作步骤代码 */
echo("SKIP\n");
?>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册