@@ -30,9 +30,9 @@ namespace nanoFramework.TestPlatform.TestAdapter
3030 [ ExtensionUri ( TestsConstants . NanoExecutor ) ]
3131 class Executor : ITestExecutor
3232 {
33- private const string TestPassed = "Test passed: " ;
34- private const string TestFailed = "Test failed: " ;
35- private const string TestSkipped = "Test skipped: " ;
33+ private const string TestPassed = "Test passed" ;
34+ private const string TestFailed = "Test failed" ;
35+ private const string TestSkipped = "Test skipped" ;
3636 private const string Exiting = "Exiting." ;
3737 private const string Done = "Done." ;
3838 private Settings _settings ;
@@ -554,6 +554,12 @@ private List<TestResult> PrepareListResult(List<TestCase> tests)
554554 foreach ( var test in tests )
555555 {
556556 TestResult result = new TestResult ( test ) { Outcome = TestOutcome . None } ;
557+
558+ foreach ( var t in result . Traits )
559+ {
560+ result . Traits . Add ( new Trait ( t . Name , "" ) ) ;
561+ }
562+
557563 results . Add ( result ) ;
558564 }
559565
@@ -731,94 +737,101 @@ private void CheckAllTests(string rawOutput, List<TestResult> results)
731737 StringBuilder testOutput = new StringBuilder ( ) ;
732738
733739 bool readyFound = false ;
740+ string method ;
741+ TestResult testResult = new TestResult ( new TestCase ( ) ) ;
742+ string [ ] resultDataSet = default ;
734743
735744 foreach ( var line in outputStrings )
736745 {
737- if ( line . Contains ( TestPassed ) )
746+ if ( ( line . Contains ( TestPassed )
747+ || ( line . Contains ( TestFailed ) )
748+ || ( line . Contains ( TestSkipped ) ) ) )
738749 {
739- // Format is "Test passed: MethodName, ticks" ;
750+ resultDataSet = line . Split ( ',' ) ;
740751
741- string method = line . Substring ( line . IndexOf ( TestPassed ) + TestPassed . Length ) . Split ( ',' ) [ 0 ] ;
742- string ticks = line . Substring ( line . IndexOf ( TestPassed ) + TestPassed . Length + method . Length + 2 ) ;
752+ // sanity check for enough data
753+ if ( resultDataSet . Length != 3 )
754+ {
755+ // something wrong!
756+ _logger . LogPanicMessage ( $ "*** ERROR: can't parse test result { line } ") ;
743757
744- long ticksNum = 0 ;
745- long . TryParse ( ticks , out ticksNum ) ;
758+ continue ;
759+ }
760+
761+ method = resultDataSet [ 1 ] . Trim ( ) ;
746762
747763 // Find the test
748- var res = results . FirstOrDefault ( m => m . TestCase . DisplayName == method ) ;
749- if ( res != null )
764+ testResult = results . FirstOrDefault ( m => m . TestCase . FullyQualifiedName == method ) ;
765+
766+ if ( testResult is null )
750767 {
751- res . Duration = TimeSpan . FromTicks ( ticksNum ) ;
752- res . Outcome = TestOutcome . Passed ;
753- res . Messages . Add ( new TestResultMessage (
754- TestResultMessage . StandardOutCategory ,
755- testOutput . ToString ( ) ) ) ;
768+ // something wrong!
769+ _logger . LogPanicMessage ( $ "*** ERROR: can't find test result for test { method } ") ;
770+
771+ continue ;
756772 }
773+ }
774+
775+ if ( line . Contains ( TestPassed ) )
776+ {
777+ // Format is "Test passed,MethodName,ticks";
778+
779+ string ticks = resultDataSet [ 2 ] ;
780+ long . TryParse ( ticks , out long ticksNum ) ;
781+
782+ testResult . Duration = TimeSpan . FromTicks ( ticksNum ) ;
783+ testResult . Outcome = TestOutcome . Passed ;
784+ testResult . Messages . Add ( new TestResultMessage (
785+ TestResultMessage . StandardOutCategory ,
786+ testOutput . ToString ( ) ) ) ;
757787
758788 // reset test output
759789 testOutput = new StringBuilder ( ) ;
760790 }
761791 else if ( line . Contains ( TestFailed ) )
762792 {
763- // Format is "Test failed: MethodName, Exception message";
764-
765- string method = line . Substring ( line . IndexOf ( TestFailed ) + TestFailed . Length ) . Split ( ',' ) [ 0 ] ;
793+ // Format is "Test failed,MethodName,Exception message";
766794
767- string exception = line . Substring ( line . IndexOf ( TestFailed ) + TestFailed . Length + method . Length + 2 ) ;
768-
769- // Find the test
770- var res = results . FirstOrDefault ( m => m . TestCase . DisplayName == method ) ;
771- if ( res != null )
772- {
773- res . ErrorMessage = exception ;
774- res . Outcome = TestOutcome . Failed ;
775- res . Messages . Add ( new TestResultMessage (
776- TestResultMessage . StandardErrorCategory ,
777- testOutput . ToString ( ) ) ) ;
778- }
795+ testResult . ErrorMessage = resultDataSet [ 2 ] ;
796+ testResult . Outcome = TestOutcome . Failed ;
797+ testResult . Messages . Add ( new TestResultMessage (
798+ TestResultMessage . StandardErrorCategory ,
799+ testOutput . ToString ( ) ) ) ;
779800
780801 // reset test output
781802 testOutput = new StringBuilder ( ) ;
782803 }
783804 else if ( line . Contains ( TestSkipped ) )
784805 {
785- // Format is "Test failed: MethodName, Exception message";
806+ // Format is "Test failed, MethodName,Exception message";
786807
787- string method = line . Substring ( line . IndexOf ( TestSkipped ) + TestSkipped . Length ) . Split ( ',' ) [ 0 ] ;
808+ testResult . ErrorMessage = resultDataSet [ 2 ] ;
809+ testResult . Outcome = TestOutcome . Skipped ;
810+ testResult . Messages . Add ( new TestResultMessage (
811+ TestResultMessage . StandardErrorCategory ,
812+ testOutput . ToString ( ) ) ) ;
788813
789- string exception = line . Substring ( line . IndexOf ( TestSkipped ) + TestSkipped . Length + method . Length + 2 ) ;
814+ // If this is a Steup Test, set all the other tests from the class to skipped as well
815+ var trait = testResult . TestCase . Traits . FirstOrDefault ( ) ;
790816
791- // Find the test
792- var res = results . FirstOrDefault ( m => m . TestCase . DisplayName == method ) ;
793- if ( res != null )
817+ if ( trait != null )
794818 {
795- res . ErrorMessage = exception ;
796- res . Outcome = TestOutcome . Skipped ;
797- res . Messages . Add ( new TestResultMessage (
798- TestResultMessage . StandardErrorCategory ,
799- testOutput . ToString ( ) ) ) ;
800-
801- // If this is a Steup Test, set all the other tests from the class to skipped as well
802- var trait = res . TestCase . Traits . FirstOrDefault ( ) ;
803- if ( trait != null )
819+ if ( trait . Value == "Setup" && trait . Name == "Type" )
804820 {
805- if ( trait . Value == "Setup" && trait . Name == "Type" )
821+ // A test name is the full qualify name of the metho.methodname, finding the list . index will give all the familly name
822+ var testCasesToSkipName = testResult . TestCase . FullyQualifiedName . Substring ( 0 , testResult . TestCase . FullyQualifiedName . LastIndexOf ( '.' ) ) ;
823+ var allTestToSkip = results . Where ( m => m . TestCase . FullyQualifiedName . Contains ( testCasesToSkipName ) ) ;
824+ foreach ( var testToSkip in allTestToSkip )
806825 {
807- // A test name is the full qualify name of the metho.methodname, finding the list . index will give all the familly name
808- var testCasesToSkipName = res . TestCase . FullyQualifiedName . Substring ( 0 , res . TestCase . FullyQualifiedName . LastIndexOf ( '.' ) ) ;
809- var allTestToSkip = results . Where ( m => m . TestCase . FullyQualifiedName . Contains ( testCasesToSkipName ) ) ;
810- foreach ( var testToSkip in allTestToSkip )
826+ if ( testToSkip . TestCase . FullyQualifiedName == resultDataSet [ 1 ] )
811827 {
812- if ( testToSkip . TestCase . DisplayName == method )
813- {
814- continue ;
815- }
816-
817- testToSkip . Outcome = TestOutcome . Skipped ;
818- res . Messages . Add ( new TestResultMessage (
819- TestResultMessage . StandardErrorCategory ,
820- $ "Setup method '{ method } ' has been skipped.") ) ;
828+ continue ;
821829 }
830+
831+ testToSkip . Outcome = TestOutcome . Skipped ;
832+ testResult . Messages . Add ( new TestResultMessage (
833+ TestResultMessage . StandardErrorCategory ,
834+ $ "Setup method '{ testResult . DisplayName } ' has been skipped.") ) ;
822835 }
823836 }
824837 }
0 commit comments