@@ -12,6 +12,7 @@ import (
1212	"github.com/hashicorp/terraform/internal/command/junit" 
1313	"github.com/hashicorp/terraform/internal/configs/configload" 
1414	"github.com/hashicorp/terraform/internal/moduletest" 
15+ 	"github.com/hashicorp/terraform/internal/tfdiags" 
1516)
1617
1718// This test cannot access sources when contructing output for XML files. Due to this, the majority of testing 
@@ -114,6 +115,47 @@ func Test_TestJUnitXMLFile_Save(t *testing.T) {
114115      <skipped></skipped> 
115116    </testcase> 
116117  </testsuite> 
118+ </testsuites>` ),
119+ 		},
120+ 		"<skipped> element includes file-level error diagnostics when tests are skipped due to file errors" : {
121+ 			filename : "output.xml" ,
122+ 			runner :   & local.TestSuiteRunner {},
123+ 			suite : func () moduletest.Suite  {
124+ 				file  :=  & moduletest.File {
125+ 					Name :   "file1.tftest.hcl" ,
126+ 					Status : moduletest .Error ,
127+ 					Runs : []* moduletest.Run {
128+ 						{
129+ 							Name :   "my_test" ,
130+ 							Status : moduletest .Skip ,
131+ 						},
132+ 					},
133+ 				}
134+ 				// Simulate file-level error diagnostic (e.g., invalid variable reference) 
135+ 				var  diags  tfdiags.Diagnostics 
136+ 				diags  =  diags .Append (tfdiags .Sourceless (
137+ 					tfdiags .Error ,
138+ 					"Invalid reference" ,
139+ 					"You can only reference global variables within the test file variables block." ,
140+ 				))
141+ 				file .AppendDiagnostics (diags )
142+ 				return  moduletest.Suite {
143+ 					Status : moduletest .Error ,
144+ 					Files : map [string ]* moduletest.File {
145+ 						"file1.tftest.hcl" : file ,
146+ 					},
147+ 				}
148+ 			}(),
149+ 			expectedOuput : []byte (`<?xml version="1.0" encoding="UTF-8"?><testsuites> 
150+   <testsuite name="file1.tftest.hcl" tests="1" skipped="1" failures="0" errors="0"> 
151+     <testcase name="my_test" classname="file1.tftest.hcl"> 
152+       <skipped message="Testcase skipped due to file-level errors"><![CDATA[ 
153+ Error: Invalid reference 
154+ 
155+ You can only reference global variables within the test file variables block. 
156+ ]]></skipped> 
157+     </testcase> 
158+   </testsuite> 
117159</testsuites>` ),
118160		},
119161	}
0 commit comments