@@ -30,9 +30,9 @@ namespace nanoFramework.TestPlatform.TestAdapter
30
30
[ ExtensionUri ( TestsConstants . NanoExecutor ) ]
31
31
class Executor : ITestExecutor
32
32
{
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" ;
36
36
private const string Exiting = "Exiting." ;
37
37
private const string Done = "Done." ;
38
38
private Settings _settings ;
@@ -554,6 +554,12 @@ private List<TestResult> PrepareListResult(List<TestCase> tests)
554
554
foreach ( var test in tests )
555
555
{
556
556
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
+
557
563
results . Add ( result ) ;
558
564
}
559
565
@@ -731,94 +737,101 @@ private void CheckAllTests(string rawOutput, List<TestResult> results)
731
737
StringBuilder testOutput = new StringBuilder ( ) ;
732
738
733
739
bool readyFound = false ;
740
+ string method ;
741
+ TestResult testResult = new TestResult ( new TestCase ( ) ) ;
742
+ string [ ] resultDataSet = default ;
734
743
735
744
foreach ( var line in outputStrings )
736
745
{
737
- if ( line . Contains ( TestPassed ) )
746
+ if ( ( line . Contains ( TestPassed )
747
+ || ( line . Contains ( TestFailed ) )
748
+ || ( line . Contains ( TestSkipped ) ) ) )
738
749
{
739
- // Format is "Test passed: MethodName, ticks" ;
750
+ resultDataSet = line . Split ( ',' ) ;
740
751
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 } ") ;
743
757
744
- long ticksNum = 0 ;
745
- long . TryParse ( ticks , out ticksNum ) ;
758
+ continue ;
759
+ }
760
+
761
+ method = resultDataSet [ 1 ] . Trim ( ) ;
746
762
747
763
// 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 )
750
767
{
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 ;
756
772
}
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 ( ) ) ) ;
757
787
758
788
// reset test output
759
789
testOutput = new StringBuilder ( ) ;
760
790
}
761
791
else if ( line . Contains ( TestFailed ) )
762
792
{
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";
766
794
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 ( ) ) ) ;
779
800
780
801
// reset test output
781
802
testOutput = new StringBuilder ( ) ;
782
803
}
783
804
else if ( line . Contains ( TestSkipped ) )
784
805
{
785
- // Format is "Test failed: MethodName, Exception message";
806
+ // Format is "Test failed, MethodName,Exception message";
786
807
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 ( ) ) ) ;
788
813
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 ( ) ;
790
816
791
- // Find the test
792
- var res = results . FirstOrDefault ( m => m . TestCase . DisplayName == method ) ;
793
- if ( res != null )
817
+ if ( trait != null )
794
818
{
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" )
804
820
{
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 )
806
825
{
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 ] )
811
827
{
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 ;
821
829
}
830
+
831
+ testToSkip . Outcome = TestOutcome . Skipped ;
832
+ testResult . Messages . Add ( new TestResultMessage (
833
+ TestResultMessage . StandardErrorCategory ,
834
+ $ "Setup method '{ testResult . DisplayName } ' has been skipped.") ) ;
822
835
}
823
836
}
824
837
}
0 commit comments