@@ -1011,3 +1011,67 @@ func assertResultBasic(t *testing.T, key string, expected, actual reports.TestRe
10111011 assert .Equal (t , expected .Skipped , actual .Skipped , "Skipped flag mismatch for %s" , key )
10121012 assert .InDelta (t , expected .PassRatio , actual .PassRatio , 0.001 , "PassRatio mismatch for %s" , key )
10131013}
1014+
1015+ // TestParseFiles_WithTransformationScenarios verifies the interaction between the parser and the transformer.
1016+ func TestParseFiles_IgnoreParentFailures (t * testing.T ) {
1017+ t .Parallel ()
1018+ pkg := "github.com/test/transformpkg"
1019+
1020+ testCases := []struct {
1021+ name string
1022+ inputFile string
1023+ expectedResults map [string ]reports.TestResult
1024+ }{
1025+ {
1026+ name : "Parent only fails due to subtest" ,
1027+ inputFile : buildOutput (
1028+ jsonLine ("run" , pkg , "TestParentTransform" , "" , 0 ),
1029+ jsonLine ("output" , pkg , "TestParentTransform" , "parent setup output" , 0 ), // Regular output
1030+ jsonLine ("run" , pkg , "TestParentTransform/SubFail" , "" , 0 ),
1031+ jsonLine ("output" , pkg , "TestParentTransform/SubFail" , "sub fail output" , 0 ),
1032+ jsonLine ("output" , pkg , "TestParentTransform/SubFail" , "--- FAIL: TestParentTransform/SubFail (0.1s)" , 0 ), // Subtest fail marker
1033+ jsonLine ("fail" , pkg , "TestParentTransform/SubFail" , "" , 0.1 ),
1034+ jsonLine ("output" , pkg , "TestParentTransform" , "--- FAIL: TestParentTransform (0.2s)" , 0 ), // Parent fail marker (due to subtest)
1035+ jsonLine ("fail" , pkg , "TestParentTransform" , "" , 0.2 ),
1036+ ),
1037+ expectedResults : map [string ]reports.TestResult {
1038+ fmt .Sprintf ("%s/TestParentTransform" , pkg ): {TestName : "TestParentTransform" , TestPackage : pkg , Runs : 1 , Successes : 1 , Failures : 0 , PassRatio : 1.0 },
1039+ fmt .Sprintf ("%s/TestParentTransform/SubFail" , pkg ): {TestName : "TestParentTransform/SubFail" , TestPackage : pkg , Runs : 1 , Successes : 0 , Failures : 1 , PassRatio : 0.0 },
1040+ },
1041+ },
1042+ }
1043+
1044+ for _ , tc := range testCases {
1045+ tc := tc
1046+ t .Run (tc .name , func (t * testing.T ) {
1047+ t .Parallel ()
1048+ parser := NewParser ()
1049+ tempDir := t .TempDir ()
1050+ fpath := filepath .Join (tempDir , "run1.json" )
1051+ err := os .WriteFile (fpath , []byte (tc .inputFile ), 0644 )
1052+ require .NoError (t , err )
1053+
1054+ cfg := Config {IgnoreParentFailuresOnSubtests : true , OmitOutputsOnSuccess : false }
1055+ actualResults , _ , err := parser .ParseFiles ([]string {fpath }, "run" , 1 , cfg )
1056+ require .NoError (t , err )
1057+
1058+ require .Equal (t , len (tc .expectedResults ), len (actualResults ), "Unexpected number of results" )
1059+ actualResultsMap := resultsToMap (actualResults )
1060+ for key , expected := range tc .expectedResults {
1061+ actual , ok := actualResultsMap [key ]
1062+ require .True (t , ok , "Expected result for key '%s' not found" , key )
1063+ assertResultBasic (t , key , expected , actual )
1064+ if expected .TestName == "TestParentTransform" {
1065+ require .Contains (t , actual .PassedOutputs , "run1" , "PassedOutputs missing run1 for transformed parent" )
1066+ assert .Contains (t , actual .PassedOutputs ["run1" ], "parent setup output" , "Parent original output missing" )
1067+ assert .Contains (t , actual .PassedOutputs ["run1" ], "--- PASS: TestParentTransform (0.2s)" , "Parent output marker not transformed to PASS" )
1068+ }
1069+ if expected .TestName == "TestParentTransform/SubFail" {
1070+ require .Contains (t , actual .FailedOutputs , "run1" , "FailedOutputs missing run1 for failing subtest %s" , key )
1071+ assert .Contains (t , actual .FailedOutputs ["run1" ], "sub fail output" , "Subtest fail output missing for %s" , key )
1072+ assert .Contains (t , actual .FailedOutputs ["run1" ], "--- FAIL: TestParentTransform/SubFail (0.1s)" , "Subtest fail marker missing for %s" , key )
1073+ }
1074+ }
1075+ })
1076+ }
1077+ }
0 commit comments