diff --git a/src/biz/check.go b/src/biz/check.go index a0ed2ff12e7379125908e0dfc0c3571238014cf7..706cc7fcd4a46bd802f5a31f3414c62e167df2c0 100644 --- a/src/biz/check.go +++ b/src/biz/check.go @@ -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) diff --git a/src/biz/report.go b/src/biz/report.go new file mode 100644 index 0000000000000000000000000000000000000000..c2615686b8070e452b2813ec21541de6a1dc1e22 --- /dev/null +++ b/src/biz/report.go @@ -0,0 +1,61 @@ +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")) +} diff --git a/src/misc/enum.go b/src/misc/enum.go index c529f97356e1fff18bc41a3f3165a2a52009cdb1..32d5d99ef239f9ee7295fc30e2c9255a90d54d86 100644 --- a/src/misc/enum.go +++ b/src/misc/enum.go @@ -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" +} diff --git a/src/model/test-model.go b/src/model/test-model.go index 546f99b701a982b3f3493bc3e85474ee3ecdf39f..b12aba2cdfe1680544549ac1ff73ad7d5550be5f 100644 --- a/src/model/test-model.go +++ b/src/model/test-model.go @@ -1,5 +1,7 @@ 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 } diff --git a/src/utils/file-utils.go b/src/utils/file-utils.go index 12bb6b39d972435b0201195aa678019676934649..959288c0d39b7a2758767f9953d42099bab14964 100644 --- a/src/utils/file-utils.go +++ b/src/utils/file-utils.go @@ -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 } diff --git a/src/utils/utils.go b/src/utils/utils.go index f707c5251ca40b7618f23f316a5408d8966362b8..0048af859545dcbc2bb16254dcdc8e56042f6188 100644 --- a/src/utils/utils.go +++ b/src/utils/utils.go @@ -1,6 +1,7 @@ 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 diff --git a/xdoc/scripts/tc-300.php b/xdoc/scripts/tc-300.php index a2db5242f0f2a0e6555876dd2e5fc80897ea5e4a..c765c304e55d258f92e6b4b5800c210036f78b87 100644 --- a/xdoc/scripts/tc-300.php +++ b/xdoc/scripts/tc-300.php @@ -14,7 +14,7 @@ readme: TC; -/* 此处编写操作步骤代码 */ +echo("SKIP\n"); ?>