Skip to content

Commit

Permalink
Merge c4d35f6 into 01d041d
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed May 30, 2024
2 parents 01d041d + c4d35f6 commit 29b1421
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 23 deletions.
52 changes: 35 additions & 17 deletions cmdout.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ func (d *cmdOut) CaptureResultByStep(trs Trails, result *RunResult) {
if !d.verbose {
return
}
if result.included {
return
}
d.verboseOutResult(result, 0)
}

Expand Down Expand Up @@ -82,59 +85,74 @@ func (d *cmdOut) Errs() error {
}

func (d *cmdOut) verboseOutResult(r *RunResult, nest int) {
// verbose
indent := strings.Repeat(" ", nest)
idx := len(r.StepResults) - 1
for i, sr := range r.StepResults {
if sr == nil {
idx = i - 1
break
if nest == 0 {
idx := len(r.StepResults) - 1
for i, sr := range r.StepResults {
if sr == nil {
idx = i - 1
break
}
}
if idx < 0 {
return
}
sr := r.StepResults[idx]
d.verboseOutResultForStep(idx, sr, r.Path, nest)
} else {
for idx, sr := range r.StepResults {
if sr == nil {
continue
}
d.verboseOutResultForStep(idx, sr, r.Path, nest)
}
}
if idx < 0 {
return
}
sr := r.StepResults[idx]
}

func (d *cmdOut) verboseOutResultForStep(idx int, sr *StepResult, path string, nest int) {
indent := strings.Repeat(" ", nest)
desc := ""
if sr.Desc != "" {
desc = fmt.Sprintf("%s ", sr.Desc)
}
switch {
case sr.Err != nil:
// fail
lineformat := indent + " %s\n"
_, _ = fmt.Fprintf(d.out, "%s --- %s(%s) ... %s\n%s", indent, desc, sr.Key, red("fail"), red(SprintMultilinef(lineformat, "Failure/Error: %s", strings.TrimRight(sr.Err.Error(), "\n"))))
if sr.IncludedRunResult != nil {
_, _ = fmt.Fprintf(d.out, "%s === %s (%s)\n", indent, sr.IncludedRunResult.Desc, sr.IncludedRunResult.Path)
sr.IncludedRunResult.included = false
d.verboseOutResult(sr.IncludedRunResult, nest+1)
return
}
lineformat := indent + " %s\n"
_, _ = fmt.Fprintf(d.out, "%s --- %s(%s) ... %s\n%s", indent, desc, sr.Key, red("fail"), red(SprintMultilinef(lineformat, "Failure/Error: %s", strings.TrimRight(sr.Err.Error(), "\n"))))
b, err := readFile(r.Path)
b, err := readFile(path)
if err != nil {
return
}
picked, err := pickStepYAML(string(b), idx)
if err != nil {
return
}
_, _ = fmt.Fprintf(d.out, "%s Failure step (%s):\n", indent, r.Path)
_, _ = fmt.Fprintf(d.out, "%s Failure step (%s):\n", indent, path)
_, _ = fmt.Fprint(d.out, SprintMultilinef(lineformat, "%v", picked))
_, _ = fmt.Fprintln(d.out, "")
case sr.Skipped:
// skip
_, _ = fmt.Fprintf(d.out, "%s --- %s(%s) ... %s\n", indent, desc, sr.Key, yellow("skip"))
if sr.IncludedRunResult != nil {
_, _ = fmt.Fprintf(d.out, "%s === %s (%s)\n", indent, sr.IncludedRunResult.Desc, sr.IncludedRunResult.Path)
sr.IncludedRunResult.included = false
d.verboseOutResult(sr.IncludedRunResult, nest+1)
return
}
_, _ = fmt.Fprintf(d.out, "%s --- %s(%s) ... %s\n", indent, desc, sr.Key, yellow("skip"))
default:
// ok
_, _ = fmt.Fprintf(d.out, "%s --- %s(%s) ... %s\n", indent, desc, sr.Key, green("ok"))
if sr.IncludedRunResult != nil {
_, _ = fmt.Fprintf(d.out, "%s === %s (%s)\n", indent, sr.IncludedRunResult.Desc, sr.IncludedRunResult.Path)
sr.IncludedRunResult.included = false
d.verboseOutResult(sr.IncludedRunResult, nest+1)
return
}
_, _ = fmt.Fprintf(d.out, "%s --- %s(%s) ... %s\n", indent, desc, sr.Key, green("ok"))
}
}
5 changes: 5 additions & 0 deletions cmdout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestCmdOutCaptureResult(t *testing.T) {
Path: "testdata/book/runn_included_0_fail.yml",
Err: ErrDummy,
StepResults: []*StepResult{{Key: "0", Err: ErrDummy}},
included: true,
}}},
},
false,
Expand All @@ -39,6 +40,7 @@ func TestCmdOutCaptureResult(t *testing.T) {
Path: "testdata/book/runn_included_0_fail.yml",
Err: ErrDummy,
StepResults: []*StepResult{{Key: "0", Err: ErrDummy}},
included: true,
}}},
},
true,
Expand Down Expand Up @@ -78,6 +80,7 @@ func TestCmdOutCaptureResultByStep(t *testing.T) {
Path: "testdata/book/runn_included_0_fail.yml",
Err: ErrDummy,
StepResults: []*StepResult{{Key: "0", Err: ErrDummy}},
included: true,
}}},
},
false,
Expand All @@ -92,6 +95,7 @@ func TestCmdOutCaptureResultByStep(t *testing.T) {
Path: "testdata/book/runn_included_0_fail.yml",
Err: ErrDummy,
StepResults: []*StepResult{{Key: "0", Err: ErrDummy}},
included: true,
}}},
},
true,
Expand All @@ -110,6 +114,7 @@ func TestCmdOutCaptureResultByStep(t *testing.T) {
Path: "testdata/book/runn_included_0_success.yml",
Err: nil,
StepResults: []*StepResult{{Key: "0", Err: nil}},
included: true,
},
},
{
Expand Down
4 changes: 2 additions & 2 deletions operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ func New(opts ...Option) (*operator, error) {
afterFuncs: bk.afterFuncs,
sw: stopw.New(),
capturers: bk.capturers,
runResult: newRunResult(bk.desc, bk.labels, bk.path),
runResult: newRunResult(bk.desc, bk.labels, bk.path, bk.included),
dbg: newDBG(bk.attach),
}

Expand Down Expand Up @@ -873,7 +873,7 @@ func (o *operator) Result() *RunResult {
}

func (o *operator) clearResult() {
o.runResult = newRunResult(o.desc, o.labels, o.bookPathOrID())
o.runResult = newRunResult(o.desc, o.labels, o.bookPathOrID(), o.included)
o.runResult.ID = o.runbookID()
for _, s := range o.steps {
s.clearResult()
Expand Down
1 change: 1 addition & 0 deletions operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ func TestShard(t *testing.T) {
cmpopts.IgnoreFields(cdpRunner{}, "ctx", "cancel", "opts", "mu"),
cmpopts.IgnoreFields(sshRunner{}, "client", "sess", "stdin", "stdout", "stderr"),
cmpopts.IgnoreFields(grpcRunner{}, "mu"),
cmpopts.IgnoreFields(RunResult{}, "included"),
cmpopts.IgnoreFields(http.Client{}, "Transport"),
}
if diff := cmp.Diff(got, want, dopts...); diff != "" {
Expand Down
10 changes: 6 additions & 4 deletions result.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type RunResult struct {
StepResults []*StepResult
Store map[string]any
Elapsed time.Duration
included bool
}

// StepResult is the result of a step run.
Expand Down Expand Up @@ -80,11 +81,12 @@ type stepResultSimplified struct {
Elapsed time.Duration `json:"elapsed,omitempty"`
}

func newRunResult(desc string, labels []string, path string) *RunResult {
func newRunResult(desc string, labels []string, path string, included bool) *RunResult {
return &RunResult{
Desc: desc,
Labels: labels,
Path: path,
Desc: desc,
Labels: labels,
Path: path,
included: included,
}
}

Expand Down
3 changes: 3 additions & 0 deletions testdata/book/include_a.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ vars:
filename: include_a.yml
steps:
t:
desc: test
test: 'vars.filename == "include_a.yml"'
e:
desc: exec
exec:
command: |
echo 'hello a'
a:
desc: bind
bind:
filenames:
- vars.filename
3 changes: 3 additions & 0 deletions testdata/book/include_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ vars:
filename: include_main.yml
steps:
a:
desc: include include_a.yml
include:
path: include_a.yml
test:
steps.a.steps.e.stdout == "hello a\n"
b:
desc: include include_b.yml
include:
path: include_b.yml
vars:
filename_main: '{{ vars.filename }}'
filename: '{{ steps.a.filenames[0] }}'
b_loop:
loop: 3
desc: include include_b.yml loop 3
include:
path: include_b.yml
vars:
Expand Down
2 changes: 2 additions & 0 deletions testdata/runn_cmdout_by_step1.golden
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
--- (0) ... fail
Failure/Error: dummy
=== (testdata/book/runn_included_0_fail.yml)
--- (0) ... fail
Failure/Error: dummy

0 comments on commit 29b1421

Please sign in to comment.