mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-04 12:07:09 +00:00
refactor(runner): extract RenderSummary for snapshot testing
This commit is contained in:
1 parent
f27e66c152
commit
e820cff60d
2 files changed
+22
-14
No files matched your search
@@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -312,6 +313,25 @@ func Run(ctx context.Context, options Options) (Summary, error) {
|
|||||||
return summary, nil
|
return summary, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RenderSummary writes the human-facing run summary: step count, each violation
|
||||||
|
// record, and any unsupported verbs. The wall-clock duration is excluded so the
|
||||||
|
// output is deterministic and snapshot-testable; the CLI prints it separately.
|
||||||
|
func RenderSummary(w io.Writer, summary Summary, platform string) {
|
||||||
|
fmt.Fprintf(w, "\nrun complete: %d steps\n", summary.Steps)
|
||||||
|
if len(summary.Violations) == 0 {
|
||||||
|
fmt.Fprintln(w, "no violations.")
|
||||||
|
} else {
|
||||||
|
fmt.Fprintf(w, "%d violation record(s):\n", len(summary.Violations))
|
||||||
|
for _, violation := range summary.Violations {
|
||||||
|
fmt.Fprintf(w, " step %d: %v\n", violation.StepIndex, violation.Properties)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(summary.UnsupportedVerbs) > 0 {
|
||||||
|
fmt.Fprintf(w, "unsupported on %s: %s\n",
|
||||||
|
platform, strings.Join(summary.UnsupportedVerbs, ", "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func validate(options Options) error {
|
func validate(options Options) error {
|
||||||
if options.Driver == nil {
|
if options.Driver == nil {
|
||||||
return errors.New("runner: Driver is required")
|
return errors.New("runner: Driver is required")
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/priyanshujain/sanderling/internal/android"
|
"github.com/priyanshujain/sanderling/internal/android"
|
||||||
@@ -166,19 +165,8 @@ func Execute(ctx context.Context, options Options, stdout io.Writer) error {
|
|||||||
return fmt.Errorf("runner: %w", err)
|
return fmt.Errorf("runner: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(stdout, "\nrun complete: %d steps in %s\n", summary.Steps, summary.EndTime.Sub(summary.StartTime).Round(time.Millisecond))
|
fmt.Fprintf(stdout, "\nelapsed: %s\n", summary.EndTime.Sub(summary.StartTime).Round(time.Millisecond))
|
||||||
if len(summary.Violations) == 0 {
|
runner.RenderSummary(stdout, summary, options.Platform)
|
||||||
fmt.Fprintln(stdout, "no violations.")
|
|
||||||
} else {
|
|
||||||
fmt.Fprintf(stdout, "%d violation record(s):\n", len(summary.Violations))
|
|
||||||
for _, violation := range summary.Violations {
|
|
||||||
fmt.Fprintf(stdout, " step %d: %v\n", violation.StepIndex, violation.Properties)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(summary.UnsupportedVerbs) > 0 {
|
|
||||||
fmt.Fprintf(stdout, "unsupported on %s: %s\n",
|
|
||||||
options.Platform, strings.Join(summary.UnsupportedVerbs, ", "))
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user