diff --git a/demo/t/1_simple.php b/demo/t/1_simple.php index 1e98f4ca0edf2f1254dc9e8d563273aa7042685e..2c4c19c79d5f00853dd27fe33b81f90c75799a16 100755 --- a/demo/t/1_simple.php +++ b/demo/t/1_simple.php @@ -3,7 +3,7 @@ /** title = simple demo -cid=1 +cid=3 pid=1 step1 >> expect 1 diff --git a/demo/t/2.exp b/demo/t/2.exp new file mode 100644 index 0000000000000000000000000000000000000000..4ea5b98bafd971c6ee3224077f3860eea2f74b69 --- /dev/null +++ b/demo/t/2.exp @@ -0,0 +1,7 @@ +期待结果1 +期待结果2.1 +{ + 期待结果2.2-1 + 期待结果2.2-2 +} +期待结果3 \ No newline at end of file diff --git a/demo/t/2.php b/demo/t/2.php new file mode 100755 index 0000000000000000000000000000000000000000..7c01e09e6ecf2a32ca8d4622eac69e4604d84d6a --- /dev/null +++ b/demo/t/2.php @@ -0,0 +1,28 @@ +#!/usr/bin/env php + \ No newline at end of file diff --git a/demo/t/9_new_format.php b/demo/t/9_new_format.php index 6665f2ad4f596ac14314958b65e5d3dc6990a71c..fea3202e6c26442022e6b46dde72ec68923c74a1 100755 --- a/demo/t/9_new_format.php +++ b/demo/t/9_new_format.php @@ -3,12 +3,12 @@ /** -测试用例标题 #2 +测试用例标题 #1 - 步骤1 @期待结果1 - 步骤2 - 子步骤2.1 @{ - 期待结果2.1.1 - 期待结果2.1.2 + 期待结果2.1-1 + 期待结果2.1-2 } - 子步骤2.2 @期待结果2.2 @@ -19,8 +19,8 @@ print("@期待结果1\n"); print("@{\n"); -print("期待结果2.1.1\n"); -print("期待结果2.1.2\n"); +print("期待结果2.1-1\n"); +print("期待结果2.1-2\n"); print("}\n"); print("@期待结果2.2\n"); diff --git a/internal/pkg/helper/script/generator.go b/internal/pkg/helper/script/generator.go index 807ffc44d56b4df87694508b2683d177a9386b82..19199fb98d2c2e81370790b0aaf652d0c757d8c2 100644 --- a/internal/pkg/helper/script/generator.go +++ b/internal/pkg/helper/script/generator.go @@ -49,7 +49,7 @@ func GenerateScript(cs commDomain.ZtfCase, langType string, independentFile bool targetDir string, byModule bool) (scriptPath string, err error) { caseId := cs.Id - productId := cs.Product + //productId := cs.Product moduleId := cs.Module caseTitle := cs.Title @@ -72,9 +72,9 @@ func GenerateScript(cs commDomain.ZtfCase, langType string, independentFile bool i118Utils.Sprintf("find_example", consts.FilePthSep, langType)) info = append(info, fmt.Sprintf("title=%s", caseTitle)) - info = append(info, fmt.Sprintf("timeout=%d", 0)) + //info = append(info, fmt.Sprintf("timeout=%d", 0)) info = append(info, fmt.Sprintf("cid=%d", caseId)) - info = append(info, fmt.Sprintf("pid=%d", productId)) + //info = append(info, fmt.Sprintf("pid=%d", productId)) StepWidth := 20 stepDisplayMaxWidth := 0 @@ -142,7 +142,7 @@ func generateTestStepAndScript(testSteps []commDomain.ZtfStep, steps *[]string, *steps = append(*steps, "") for _, item := range nestedSteps { numbStr := fmt.Sprintf("%d", stepNumb) - stepLines1, expects1 := getCaseContent(item, numbStr, independentFile, false) + stepLines1, expects1 := getCaseStepContent(item, numbStr, independentFile, false) *steps = append(*steps, stepLines1) if independentFile && strings.TrimSpace(item.Expect) != "" { @@ -151,7 +151,7 @@ func generateTestStepAndScript(testSteps []commDomain.ZtfStep, steps *[]string, for childNo, child := range item.Children { numbStr := fmt.Sprintf("%d.%d", stepNumb, childNo+1) - stepLines2, expects2 := getCaseContent(child, numbStr, independentFile, true) + stepLines2, expects2 := getCaseStepContent(child, numbStr, independentFile, true) *steps = append(*steps, stepLines2) if independentFile && strings.TrimSpace(child.Expect) != "" { @@ -179,7 +179,7 @@ func GenSuite(cases []string, targetDir string) { fileUtils.WriteFile(targetDir+"all."+commConsts.ExtNameSuite, str) } -func getCaseContent(stepObj commDomain.ZtfStep, seq string, independentFile bool, isChild bool) ( +func getCaseStepContent(stepObj commDomain.ZtfStep, seq string, independentFile bool, isChild bool) ( stepContent, expectContent string) { step := strings.TrimSpace(stepObj.Desc) @@ -192,8 +192,8 @@ func getCaseContent(stepObj commDomain.ZtfStep, seq string, independentFile bool stepContent = stepStr + expectStr } else { stepContent = stepStr - if stepObj.Children == nil || len(stepObj.Children) == 0 { - stepContent += " >>" + if (stepObj.Children == nil || len(stepObj.Children) == 0) && expectStr != "" { + stepContent += " @" } } @@ -206,7 +206,7 @@ func getCaseContent(stepObj commDomain.ZtfStep, seq string, independentFile bool } func getStepContent(str string, isChild bool) (ret string) { - str = strings.TrimSpace(str) + str = " - " + strings.TrimSpace(str) rpl := "\n" if isChild { @@ -230,7 +230,7 @@ func getExpectContent(str string, isChild bool, independentFile bool) (ret strin if independentFile { ret = str } else { - ret = " >> " + str + ret = " @" + str } } else { // multi-line rpl := "\r\n" @@ -248,15 +248,15 @@ func getExpectContent(str string, isChild bool, independentFile bool) (ret strin // expect 1.2 line 1 // expect 1.2 line 2 //>> - ret = ">>\n" + space + strings.ReplaceAll(str, rpl, rpl+space) + "\n>>" + ret = "{\n" + space + strings.ReplaceAll(str, rpl, rpl+space) + "\n}" } else { - //step 1.2 >> + //step 1.2 @{ // expect 1.2 line 1 // expect 1.2 line 2 - //>> - ret = " >> \n" + spaceBeforeText + + //} + ret = " @{\n" + spaceBeforeText + strings.ReplaceAll(str, rpl, rpl+spaceBeforeText) + - "\n" + spaceBeforeTerminator + ">>" + "\n" + spaceBeforeTerminator + "}" } } diff --git a/internal/pkg/helper/script/parser.go b/internal/pkg/helper/script/parser.go index bd4714117913741ce4aec515f069370e44c8088b..44c89560e159b0b677355ea71f68b1e4759a986a 100644 --- a/internal/pkg/helper/script/parser.go +++ b/internal/pkg/helper/script/parser.go @@ -98,7 +98,10 @@ func getSingleExpect(descAndExpect string) (desc, expect string) { desc = strings.TrimSpace(arr[0]) if len(arr) > 1 { - expect = arr[1] + expect = strings.TrimSpace(arr[1]) + if expect == "" { + expect = "pass" + } } return @@ -185,7 +188,7 @@ func ReadCaseInfoInOldFormat(content, lang string) (info, checkpoints string) { func GetStepAndExpectMapInOldFormat(checkpoints, file string) (steps []commDomain.ZentaoCaseStep) { lines := strings.Split(checkpoints, "\n") - groupArr := getStepNestedArr(lines) + groupArr := getStepNestedArrInOldFormat(lines) _, steps = getSortedTextFromNestedSteps(groupArr) isIndependent, expectIndependentContent := GetDependentExpect(file) @@ -225,7 +228,7 @@ func GetDependentExpect(file string) (bool, string) { return false, "" } -func getStepNestedArr(lines []string) (ret []commDomain.ZtfStep) { +func getStepNestedArrInOldFormat(lines []string) (ret []commDomain.ZtfStep) { parent := commDomain.ZtfStep{} increase := 0 for index := 0; index < len(lines); index++ { @@ -305,7 +308,7 @@ func ReplaceCaseDesc(desc, file string) { content := fileUtils.ReadFile(file) lang := langHelper.GetLangByFile(file) - regStr := fmt.Sprintf(`(?smU)%s((?U:.*pid.*))\n(.*)%s`, + regStr := fmt.Sprintf(`(?smU)%s((?U:.*cid.*))\n(.*)%s`, commConsts.LangCommentsRegxMap[lang][0], commConsts.LangCommentsRegxMap[lang][1]) re, _ := regexp.Compile(regStr) @@ -487,14 +490,14 @@ func GetCaseInfo(file string) (pass bool, caseId, productId int, title string, t func ReadExpectIndependentArr(content string) [][]string { //正常显示6 //E2.16 - //>> + //{ // E2.2 - 16 // E2.2 - 26 - //>> - //>> + //} + //{ // E3 - 16 // E3 - 26 - //>> + //} lines := strings.Split(content, "\n") @@ -506,13 +509,13 @@ func ReadExpectIndependentArr(content string) [][]string { for idx < len(lines) { line := strings.TrimSpace(lines[idx]) - if line == ">>" { // more than one line + if line == "{" { // more than one line currModel = "multi" cpArr = make([]string, 0) - } else if currModel == "multi" { // in >> and >> in multi line mode + } else if currModel == "multi" { // in { and } in multi line mode cpArr = append(cpArr, line) - if idx == len(lines)-1 || strings.Index(lines[idx+1], ">>") > -1 { // end multi line + if idx == len(lines)-1 || strings.TrimSpace(lines[idx+1]) == "}" { // end multi line temp := make([]string, 0) temp = append(temp, strings.Join(cpArr, "\r\n")) @@ -553,13 +556,14 @@ func ReadLogArr(content string) (isSkip bool, ret [][]string) { return } - if line == ">>" { // more than one line + if line == "@{" { // more than one line model = "multi" cpArr = make([]string, 0) - } else if model == "multi" { // in >> and >> in multi line mode + } else if model == "multi" { // between line @{ and } in multi line mode cpArr = append(cpArr, line) - if idx == len(lines)-1 || strings.Index(lines[idx+1], ">>") > -1 { + //if idx == len(lines)-1 || strings.Index(lines[idx+1], "}") > -1 { + if idx == len(lines)-1 || strings.TrimSpace(lines[idx+1]) == "}" { temp := make([]string, 0) temp = append(temp, cpArr...) @@ -573,6 +577,11 @@ func ReadLogArr(content string) (isSkip bool, ret [][]string) { model = "single" line = strings.TrimSpace(line) + if strings.Index(line, "@") != 0 { // ignore the line not started with @ + continue + } + + line = line[1:] cpArr = append(cpArr, line) ret = append(ret, cpArr) diff --git a/internal/pkg/helper/zentao/case.go b/internal/pkg/helper/zentao/case.go index 646c6f8fcbeb4499840d0ed71f7b113f02741052..63ed16d5d252e80fca306c58bbeed0fab9e5db2f 100644 --- a/internal/pkg/helper/zentao/case.go +++ b/internal/pkg/helper/zentao/case.go @@ -301,6 +301,7 @@ func LoadTestCasesDetailByCaseIds(caseIds []int, func GetTestCaseDetail(caseId int, config commDomain.WorkspaceConf) (cs commDomain.ZtfCase, err error) { csWithSteps, err := GetCaseById(config.Url, caseId) + stepArr := genCaseSteps(csWithSteps) cs = commDomain.ZtfCase{Id: caseId, Product: csWithSteps.Product, Module: csWithSteps.Module, Title: csWithSteps.Title, Steps: stepArr}