66 "log"
77 "os"
88 run "runtime"
9+ "sort"
910 "time"
1011
1112 "github.com/SimonBaeumer/commander/pkg/runtime"
@@ -18,13 +19,16 @@ var au aurora.Aurora
1819type OutputWriter struct {
1920 out io.Writer
2021 color bool
22+ isDir bool
23+ order bool
2124}
2225
2326// NewCliOutput creates a new OutputWriter with a stdout writer
24- func NewCliOutput (color bool ) OutputWriter {
27+ func NewCliOutput (color bool , order bool ) OutputWriter {
2528 return OutputWriter {
2629 out : os .Stdout ,
2730 color : color ,
31+ order : order ,
2832 }
2933}
3034
@@ -35,44 +39,49 @@ func (w *OutputWriter) Start(results <-chan runtime.TestResult) bool {
3539 au = aurora .NewAurora (false )
3640 }
3741
38- fileErrors := make ([]error , 0 )
39- failed := 0
42+ fileErrors := []string {}
4043 testResults := []runtime.TestResult {}
44+
4145 start := time .Now ()
4246 for r := range results {
4347 if r .FileError != nil {
44- fileErrors = append (fileErrors , r .FileError )
48+ str := fmt .Sprintf ("[%s] %s!" , r .FileName , r .FileError .Error ())
49+ fileErrors = append (fileErrors , str )
4550 continue
4651 }
47-
4852 testResults = append (testResults , r )
53+ }
54+ duration := time .Since (start )
55+
56+ if w .order { //maintain file order
57+ sort .SliceStable (testResults , func (i , j int ) bool {
58+ return testResults [i ].FileName < testResults [j ].FileName
59+ })
60+ }
61+
62+ failed := 0
63+ //Actually print the results
64+ for _ , r := range testResults {
4965 if r .ValidationResult .Success {
50- str := fmt .Sprintf ("✓ [%s] %s" , r .Node , r .TestCase .Title )
66+ str := fmt .Sprintf ("✓ [%s] [%s] %s" , r . FileName , r .Node , r .TestCase .Title )
5167 s := w .addTries (str , r )
5268 w .fprintf (s )
5369 continue
5470 }
5571
5672 if ! r .ValidationResult .Success {
5773 failed ++
58- str := fmt .Sprintf ("✗ [%s] %s" , r .Node , r .TestCase .Title )
74+ str := fmt .Sprintf ("✗ [%s] [%s] %s" , r . FileName , r .Node , r .TestCase .Title )
5975 s := w .addTries (str , r )
6076 w .fprintf (au .Red (s ))
6177 continue
6278 }
6379 }
6480
65- duration := time .Since (start )
66-
6781 if failed > 0 {
6882 w .printFailures (testResults )
6983 }
7084
71- w .fprintf ("" )
72- for _ , e := range fileErrors {
73- fmt .Println (e )
74- }
75-
7685 w .fprintf ("" )
7786 w .fprintf (fmt .Sprintf ("Duration: %.3fs" , duration .Seconds ()))
7887 summary := fmt .Sprintf ("Count: %d, Failed: %d" , len (testResults ), failed )
@@ -82,6 +91,10 @@ func (w *OutputWriter) Start(results <-chan runtime.TestResult) bool {
8291 w .fprintf (au .Green (summary ))
8392 }
8493
94+ w .fprintf ("" )
95+ for _ , e := range fileErrors {
96+ w .fprintf (e )
97+ }
8598 return failed == 0
8699}
87100
@@ -99,14 +112,14 @@ func (w *OutputWriter) printFailures(results []runtime.TestResult) {
99112
100113 for _ , r := range results {
101114 if r .TestCase .Result .Error != nil {
102- str := fmt .Sprintf ("✗ [%s] '%s' could not be executed with error message:" , r .Node , r .TestCase .Title )
115+ str := fmt .Sprintf ("✗ [%s][%s] '%s' could not be executed with error message:" , r . FileName , r .Node , r .TestCase .Title )
103116 w .fprintf (au .Bold (au .Red (str )))
104117 w .fprintf (r .TestCase .Result .Error .Error ())
105118 continue
106119 }
107120
108121 if ! r .ValidationResult .Success {
109- str := fmt .Sprintf ("✗ [%s] '%s', on property '%s'" , r .Node , r .TestCase .Title , r .FailedProperty )
122+ str := fmt .Sprintf ("✗ [%s][%s] '%s', on property '%s'" , r . FileName , r .Node , r .TestCase .Title , r .FailedProperty )
110123 w .fprintf (au .Bold (au .Red (str )))
111124 w .fprintf (r .ValidationResult .Diff )
112125 }
0 commit comments