@@ -190,11 +190,21 @@ mod test {
190190 use super :: run_main;
191191 use std:: env;
192192
193- #[ tokio:: test]
194- async fn normal ( ) {
193+ /// helper to avoid writing to the same GITHUB_OUTPUT file in parallel-running tests.
194+ fn setup_tmp_gh_out_path ( ) -> tempfile:: NamedTempFile {
195+ let gh_out_path = tempfile:: NamedTempFile :: new ( ) . unwrap ( ) ;
195196 unsafe {
196- env:: remove_var ( "GITHUB_OUTPUT" ) ; // avoid writing to GH_OUT in parallel-running tests
197+ env:: set_var (
198+ "GITHUB_OUTPUT" ,
199+ gh_out_path. path ( ) . to_string_lossy ( ) . to_string ( ) ,
200+ ) ;
197201 }
202+ gh_out_path
203+ }
204+
205+ #[ tokio:: test]
206+ async fn normal ( ) {
207+ let tmp_gh_out = setup_tmp_gh_out_path ( ) ;
198208 run_main ( vec ! [
199209 "cpp-linter" . to_string( ) ,
200210 "-l" . to_string( ) ,
@@ -205,23 +215,21 @@ mod test {
205215 ] )
206216 . await
207217 . unwrap ( ) ;
218+ drop ( tmp_gh_out) ;
208219 }
209220
210221 #[ tokio:: test]
211222 async fn version_command ( ) {
212- unsafe {
213- env:: remove_var ( "GITHUB_OUTPUT" ) ; // avoid writing to GH_OUT in parallel-running tests
214- }
223+ let tmp_gh_out = setup_tmp_gh_out_path ( ) ;
215224 run_main ( vec ! [ "cpp-linter" . to_string( ) , "version" . to_string( ) ] )
216225 . await
217226 . unwrap ( ) ;
227+ drop ( tmp_gh_out) ;
218228 }
219229
220230 #[ tokio:: test]
221231 async fn force_debug_output ( ) {
222- unsafe {
223- env:: remove_var ( "GITHUB_OUTPUT" ) ; // avoid writing to GH_OUT in parallel-running tests
224- }
232+ let tmp_gh_out = setup_tmp_gh_out_path ( ) ;
225233 run_main ( vec ! [
226234 "cpp-linter" . to_string( ) ,
227235 "-l" . to_string( ) ,
@@ -231,13 +239,12 @@ mod test {
231239 ] )
232240 . await
233241 . unwrap ( ) ;
242+ drop ( tmp_gh_out) ;
234243 }
235244
236245 #[ tokio:: test]
237246 async fn no_version_input ( ) {
238- unsafe {
239- env:: remove_var ( "GITHUB_OUTPUT" ) ; // avoid writing to GH_OUT in parallel-running tests
240- }
247+ let tmp_gh_out = setup_tmp_gh_out_path ( ) ;
241248 run_main ( vec ! [
242249 "cpp-linter" . to_string( ) ,
243250 "-l" . to_string( ) ,
@@ -246,12 +253,13 @@ mod test {
246253 ] )
247254 . await
248255 . unwrap ( ) ;
256+ drop ( tmp_gh_out) ;
249257 }
250258
251259 #[ tokio:: test]
252260 async fn pre_commit_env ( ) {
261+ let tmp_gh_out = setup_tmp_gh_out_path ( ) ;
253262 unsafe {
254- env:: remove_var ( "GITHUB_OUTPUT" ) ; // avoid writing to GH_OUT in parallel-running tests
255263 env:: set_var ( "PRE_COMMIT" , "1" ) ;
256264 }
257265 run_main ( vec ! [
@@ -262,15 +270,14 @@ mod test {
262270 ] )
263271 . await
264272 . unwrap_err ( ) ;
273+ drop ( tmp_gh_out) ;
265274 }
266275
267276 // Verifies that the system gracefully handles cases where all analysis is disabled.
268277 // This ensures no diagnostic comments are generated when analysis is explicitly skipped.
269278 #[ tokio:: test]
270279 async fn no_analysis ( ) {
271- unsafe {
272- env:: remove_var ( "GITHUB_OUTPUT" ) ; // avoid writing to GH_OUT in parallel-running tests
273- }
280+ let tmp_gh_out = setup_tmp_gh_out_path ( ) ;
274281 run_main ( vec ! [
275282 "cpp-linter" . to_string( ) ,
276283 "-l" . to_string( ) ,
@@ -281,19 +288,19 @@ mod test {
281288 ] )
282289 . await
283290 . unwrap ( ) ;
291+ drop ( tmp_gh_out) ;
284292 }
285293
286294 #[ tokio:: test]
287295 async fn bad_repo_root ( ) {
288- unsafe {
289- env:: remove_var ( "GITHUB_OUTPUT" ) ; // avoid writing to GH_OUT in parallel-running tests
290- }
296+ let tmp_gh_out = setup_tmp_gh_out_path ( ) ;
291297 run_main ( vec ! [
292298 "cpp-linter" . to_string( ) ,
293299 "--repo-root" . to_string( ) ,
294300 "some-non-existent-dir" . to_string( ) ,
295301 ] )
296302 . await
297303 . unwrap_err ( ) ;
304+ drop ( tmp_gh_out) ;
298305 }
299306}
0 commit comments