@@ -27,14 +27,15 @@ public class ValidateUnitTestsCommand : CommandTarget
2727 {
2828 public string ResultsDirectory { get ; set ; }
2929
30+ public bool PrettyPrint { get ; set ; }
3031
3132 public override void Run ( )
3233 {
3334 Log < ValidateUnitTestsCommand > . G ( ) . LogInformation ( $ "Validating unit tests in { ResultsDirectory } ") ;
3435
3536 string [ ] results = Directory . GetFiles ( ResultsDirectory , "test_report_*" , SearchOption . AllDirectories ) ;
3637
37- List < UnitTestResult > failures = new List < UnitTestResult > ( ) ;
38+ List < UnitTestResult > unitTestResults = new List < UnitTestResult > ( ) ;
3839
3940 foreach ( string result in results )
4041 {
@@ -44,75 +45,92 @@ public override void Run()
4445 List < UnitTestResult > items = JsonConvert . DeserializeObject < List < UnitTestResult > > ( json ) ;
4546
4647 foreach ( var item in items )
47- {
48- if ( item . pass == false )
49- {
50- failures . Add ( item ) ;
51- }
48+ {
49+ unitTestResults . Add ( item ) ;
5250 }
5351 }
5452 }
5553
56- if ( failures . Count > 0 )
57- {
58- Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "One or more unit tests failed. Details below:") ;
59- Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "---------------------------------------------") ;
6054
61- int totalCases = failures . Count ;
62- int currentCase = 0 ;
55+ int totalCases = unitTestResults . Count ;
56+ int currentCase = 0 ;
6357
58+ foreach ( var item in unitTestResults )
59+ {
60+ currentCase ++ ;
6461
65- foreach ( var item in failures )
62+ if ( item . pass )
6663 {
67- currentCase ++ ;
68-
69- if ( item . failureStage == "RESULT" )
64+ if ( PrettyPrint )
65+ {
66+ Console . WriteLine ( $ " ✅ [PASS] ({ currentCase } of { totalCases } ) { item . test } ") ;
67+ }
68+ else
7069 {
7170 Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "+----------------------------------------------+") ;
7271 Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "| TEST CASE ({ currentCase } of { totalCases } ) : { Path . GetFileName ( item . test ) } ") ;
7372 Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "+----------------------------------------------+") ;
74- Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "| STATUS : FAILED ") ;
75- Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "| FAILURE TYPE : RESULT") ;
73+ Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "| STATUS : PASSED ") ;
7674 Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "+----------------------------------------------+") ;
77- Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "| TEST DIFFERENCES |") ;
78- Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "+----------------------------------------------+") ;
79- Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "| FULL PATH : { item . test } ") ;
75+ }
76+ }
77+ else
78+ {
79+ if ( PrettyPrint )
80+ {
81+ Console . WriteLine ( $ "❌ [FAIL] ({ currentCase } of { totalCases } ) { item . test } ") ;
82+ }
83+ else
84+ {
85+ if ( item . failureStage == "RESULT" )
86+ {
87+ Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "+----------------------------------------------+") ;
88+ Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "| TEST CASE ({ currentCase } of { totalCases } ) : { Path . GetFileName ( item . test ) } ") ;
89+ Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "+----------------------------------------------+") ;
90+ Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "| STATUS : FAILED ") ;
91+ Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "| FAILURE TYPE : RESULT") ;
92+ Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "+----------------------------------------------+") ;
93+ Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "| TEST DIFFERENCES |") ;
94+ Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "+----------------------------------------------+") ;
95+ Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "| FULL PATH : { item . test } ") ;
8096
8197
82- foreach ( var diff in item . diff )
83- {
84- Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "| { diff } ") ;
85- }
86- Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "+----------------------------------------------+") ;
98+ foreach ( var diff in item . diff )
99+ {
100+ Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "| { diff } ") ;
101+ }
102+ Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "+----------------------------------------------+") ;
87103
88- Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "\n \n \n \n ") ;
104+ Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "\n \n \n \n ") ;
89105
90- }
91- else
92- {
93- Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "+----------------------------------------------+") ;
94- Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "| TEST CASE ({ currentCase } of { totalCases } ) : { Path . GetFileName ( item . test ) } ") ;
95- Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "+----------------------------------------------+") ;
96- Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "| STATUS : FAILED ") ;
97- Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "| FAILURE TYPE : { item . failureStage } ") ;
98- Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "+----------------------------------------------+") ;
99- Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "| FAILURE DESCRIPTION |") ;
100- Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "+----------------------------------------------+") ;
101- Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "| FULL PATH : { item . test } ") ;
102- Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "| { item . failureDescription } ") ;
106+ }
107+ else
108+ {
109+ Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "+----------------------------------------------+") ;
110+ Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "| TEST CASE ({ currentCase } of { totalCases } ) : { Path . GetFileName ( item . test ) } ") ;
111+ Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "+----------------------------------------------+") ;
112+ Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "| STATUS : FAILED ") ;
113+ Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "| FAILURE TYPE : { item . failureStage } ") ;
114+ Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "+----------------------------------------------+") ;
115+ Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "| FAILURE DESCRIPTION |") ;
116+ Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "+----------------------------------------------+") ;
117+ Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "| FULL PATH : { item . test } ") ;
118+ Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "| { item . failureDescription } ") ;
103119
104120
105- Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "+----------------------------------------------+") ;
121+ Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "+----------------------------------------------+") ;
106122
107- Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "\n \n \n \n ") ;
123+ Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "\n \n \n \n ") ;
108124
125+ }
109126 }
110127 }
111- Log < ValidateUnitTestsCommand > . G ( ) . LogError ( $ "--------------------END OF RESULTS-------------------------" ) ;
128+ }
112129
130+ if ( unitTestResults . Select ( x => x . pass == false ) . Count ( ) > 0 )
131+ {
113132 DieWithError ( "One or more failures during run unit tests." ) ;
114133 }
115-
116- }
134+ }
117135 }
118136}
0 commit comments