Skip to content

Commit

Permalink
feat: improve output with range (#588)
Browse files Browse the repository at this point in the history
* feat: improve output with range

Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
  • Loading branch information
yesnault authored Sep 12, 2022
1 parent 842caff commit 5090be8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
20 changes: 12 additions & 8 deletions process_testcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ func (v *Venom) runTestSteps(ctx context.Context, tc *TestCase, tsIn *TestStepRe

tsResult.Number = stepNumber
tsResult.RangedIndex = rangedIndex
tsResult.RangedEnable = ranged.Enabled
tsResult.InputVars = vars

tc.testSteps = append(tc.testSteps, step)
Expand Down Expand Up @@ -299,7 +300,7 @@ func (v *Venom) runTestSteps(ctx context.Context, tc *TestCase, tsIn *TestStepRe
}

printStepName := v.Verbose >= 1 && !fromUserExecutor
v.setTestStepName(tsResult, e, step, &ranged, &rangedData, printStepName)
v.setTestStepName(tsResult, e, step, &ranged, &rangedData, rangedIndex, printStepName)

tsResult.Start = time.Now()

Expand Down Expand Up @@ -332,13 +333,13 @@ func (v *Venom) runTestSteps(ctx context.Context, tc *TestCase, tsIn *TestStepRe
if isRequired {
failure := newFailure(ctx, *tc, stepNumber, rangedIndex, "", fmt.Errorf("At least one required assertion failed, skipping remaining steps"))
tsResult.appendFailure(*failure)
v.printTestStepResult(tc, tsResult, tsIn, stepNumber, true)
v.printTestStepResult(tc, tsResult, tsIn, ranged, stepNumber, true)
return
}
v.printTestStepResult(tc, tsResult, tsIn, stepNumber, false)
v.printTestStepResult(tc, tsResult, tsIn, ranged, stepNumber, false)
continue
}
v.printTestStepResult(tc, tsResult, tsIn, stepNumber, false)
v.printTestStepResult(tc, tsResult, tsIn, ranged, stepNumber, false)

allVars := tc.Vars.Clone()
allVars.AddAll(tc.computedVars.Clone())
Expand All @@ -358,7 +359,7 @@ func (v *Venom) runTestSteps(ctx context.Context, tc *TestCase, tsIn *TestStepRe
}

// Set test step name (defaults to executor name, excepted if it got a "name" attribute. in range, also print key)
func (v *Venom) setTestStepName(ts *TestStepResult, e ExecutorRunner, step TestStep, ranged *Range, rangedData *RangeData, print bool) {
func (v *Venom) setTestStepName(ts *TestStepResult, e ExecutorRunner, step TestStep, ranged *Range, rangedData *RangeData, rangedIndex int, print bool) {
name := e.Name()
if value, ok := step["name"]; ok {
switch value := value.(type) {
Expand All @@ -367,22 +368,25 @@ func (v *Venom) setTestStepName(ts *TestStepResult, e ExecutorRunner, step TestS
}
}
if ranged.Enabled {
if rangedIndex == 0 {
v.Print("\n")
}
name = fmt.Sprintf("%s (range=%s)", name, rangedData.Key)
}
ts.Name = name

if print {
if print || ranged.Enabled {
v.Print(" \t\t• %s", ts.Name)
}
}

// Print a single step result (if verbosity is enabled)
func (v *Venom) printTestStepResult(tc *TestCase, ts *TestStepResult, tsIn *TestStepResult, stepNumber int, mustAssertionFailed bool) {
func (v *Venom) printTestStepResult(tc *TestCase, ts *TestStepResult, tsIn *TestStepResult, ranged Range, stepNumber int, mustAssertionFailed bool) {
fromUserExecutor := tsIn != nil
if fromUserExecutor {
tsIn.appendFailure(ts.Errors...)
}
if v.Verbose >= 1 {
if ranged.Enabled || v.Verbose >= 1 {
if !fromUserExecutor { //Else print step status
if len(ts.Errors) > 0 {
v.Println(" %s", Red(StatusFail))
Expand Down
15 changes: 10 additions & 5 deletions process_testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,8 @@ func (v *Venom) runTestCases(ctx context.Context, ts *TestSuite) {
tc := &ts.TestCases[i]
tc.IsEvaluated = true
v.Print(" \t• %s", tc.Name)
if verboseReport {
v.Print("\n")
}
var hasFailure bool
var hasRanged bool
var hasSkipped = len(tc.Skipped) > 0
if !hasSkipped {
start := time.Now()
Expand All @@ -120,11 +118,18 @@ func (v *Venom) runTestCases(ctx context.Context, ts *TestSuite) {
}

for _, testStepResult := range tc.TestStepResults {
if testStepResult.RangedEnable {
hasRanged = true
}
if testStepResult.Status == StatusFail {
hasFailure = true
}
}

if verboseReport || hasRanged {
v.Print("\n")
}

if hasFailure {
tc.Status = StatusFail
} else if tc.Status != StatusSkip {
Expand All @@ -133,7 +138,7 @@ func (v *Venom) runTestCases(ctx context.Context, ts *TestSuite) {

// Verbose mode already reported tests status, so just print them when non-verbose
indent := ""
if verboseReport {
if hasRanged || verboseReport {
indent = "\t "
} else {
if hasFailure {
Expand All @@ -155,7 +160,7 @@ func (v *Venom) runTestCases(ctx context.Context, ts *TestSuite) {
}

// Verbose mode already reported failures, so just print them when non-verbose
if !verboseReport && hasFailure {
if !hasRanged && !verboseReport && hasFailure {
for _, testStepResult := range tc.TestStepResults {
for _, f := range testStepResult.Errors {
v.Println("%s", Yellow(f.Value))
Expand Down
6 changes: 3 additions & 3 deletions tests/verbose_output.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ testcases:
- result.systemout {{.value.op}}ContainSubstring 'step1 PASS'
- result.systemout {{.value.op}}ContainSubstring 'step2 FAIL'
# ranged steps
- result.systemout {{.value.op}}ContainSubstring 'exec (range=0) PASS'
- result.systemout {{.value.op}}ContainSubstring 'exec (range=1) FAIL'
- result.systemout {{.value.op}}ContainSubstring 'exec (range=2) PASS'
- result.systemout ShouldContainSubstring 'exec (range=0) PASS'
- result.systemout ShouldContainSubstring 'exec (range=1) FAIL'
- result.systemout ShouldContainSubstring 'exec (range=2) PASS'
# must assertions
- result.systemout {{.value.op}}ContainSubstring 'must1 FAIL'
- result.systemout ShouldContainSubstring 'At least one required assertion failed, skipping remaining steps'
Expand Down
1 change: 1 addition & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ type TestStepResult struct {
Interpolated interface{} `json:"interpolated" yaml:"interpolated"`
Number int `json:"number" yaml:"number"`
RangedIndex int `json:"rangedIndex" yaml:"rangedIndex"`
RangedEnable bool `json:"rangedEnable" yaml:"rangedEnable"`
InputVars map[string]string `json:"inputVars" yaml:"-"`
ComputedVars H `json:"computedVars" yaml:"-"`
ComputedInfo []string `json:"computedInfos" yaml:"-"`
Expand Down

0 comments on commit 5090be8

Please sign in to comment.