diff --git a/executors/exec/executor.go b/executors/exec/executor.go index 446b45c7..67ad2848 100644 --- a/executors/exec/executor.go +++ b/executors/exec/executor.go @@ -91,15 +91,15 @@ func (Executor) Run(testCaseContext venom.TestCaseContext, l venom.Logger, step // Create a tmp file tmpscript, errt := ioutil.TempFile(os.TempDir(), "venom-") if errt != nil { - return nil, fmt.Errorf("Cannot create tmp file: %s\n", errt) + return nil, fmt.Errorf("cannot create tmp file: %s\n", errt) } // Put script in file - l.Debugf("work with tmp file %s", tmpscript) + l.Debugf("work with tmp file %s", tmpscript.Name()) n, errw := tmpscript.Write([]byte(scriptContent)) if errw != nil || n != len(scriptContent) { if errw != nil { - return nil, fmt.Errorf("Cannot write script: %s\n", errw) + return nil, fmt.Errorf("cannot write script: %s\n", errw) } return nil, fmt.Errorf("cannot write all script: %d/%d\n", n, len(scriptContent)) } @@ -113,7 +113,7 @@ func (Executor) Run(testCaseContext venom.TestCaseContext, l venom.Logger, step //and add .PS1 extension newPath = newPath + ".PS1" if err := os.Rename(oldPath, newPath); err != nil { - return nil, fmt.Errorf("cannot rename script to add powershell Extension, aborting\n") + return nil, fmt.Errorf("cannot rename script to add powershell extension, aborting\n") } //This aims to stop a the very first error and return the right exit code psCommand := fmt.Sprintf("& { $ErrorActionPreference='Stop'; & %s ;exit $LastExitCode}", newPath) diff --git a/process.go b/process.go index 08a84151..d08add7b 100644 --- a/process.go +++ b/process.go @@ -44,8 +44,7 @@ func (v *Venom) Parse(path []string, exclude []string) error { extractedVars := []string{} for i := range v.testsuites { ts := &v.testsuites[i] - log.Info("Parsing testsuite", ts.Package) - + log.Info("Parsing testsuite ", ts.Package) tvars, textractedVars, err := v.parseTestSuite(ts) if err != nil { return err diff --git a/process_testsuite.go b/process_testsuite.go index 6b0d9ca8..df021ff2 100644 --- a/process_testsuite.go +++ b/process_testsuite.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "runtime/pprof" + "strings" "time" "github.com/fatih/color" @@ -42,6 +43,21 @@ func (v *Venom) runTestSuite(ts *TestSuite) { ts.Templater.Add("", map[string]string{"venom.testsuite": ts.ShortName}) ts.Templater.Add("", map[string]string{"venom.testsuite.filename": ts.Filename}) + // we apply templater on current vars only + for index := 0; index < 10; index++ { + var toApply bool + for k, v := range ts.Templater.Values { + if strings.Contains(v, "{{") { + toApply = true + _, s := ts.Templater.apply([]byte(v)) + ts.Templater.Values[k] = string(s) + } + } + if !toApply { + break + } + } + totalSteps := 0 for _, tc := range ts.TestCases { totalSteps += len(tc.TestSteps) diff --git a/tests/MyTestSuiteWithVenomBuiltinVar.yml b/tests/MyTestSuiteWithVenomBuiltinVar.yml index 16ebbccb..fea25f99 100644 --- a/tests/MyTestSuiteWithVenomBuiltinVar.yml +++ b/tests/MyTestSuiteWithVenomBuiltinVar.yml @@ -1,11 +1,15 @@ name: MyTestSuite +vars: + short: "a short" + long: "{{.short}} and a long" testcases: - name: testA steps: - type: exec - script: echo '{{.venom.testsuite}} {{.venom.testsuite.filename}} {{.venom.testcase}} {{.venom.teststep.number}} {{.venom.datetime}} {{.venom.timestamp}}' + script: echo '{{.venom.testsuite}} {{.venom.testsuite.filename}} {{.venom.testcase}} {{.venom.teststep.number}} {{.venom.datetime}} {{.venom.timestamp}} {{.short}} {{.long}}' assertions: - result.code ShouldEqual 0 - result.systemout ShouldContainSubstring MyTestSuite - result.systemout ShouldContainSubstring testA + - result.systemout ShouldContainSubstring "a short a short and a long" - result.systemout ShouldContainSubstring 0