Skip to content

Commit 593a356

Browse files
committed
stub a GITHUB_OUTPUT env var with tmp path
1 parent 02433e5 commit 593a356

1 file changed

Lines changed: 24 additions & 19 deletions

File tree

cpp-linter/src/run.rs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,19 @@ 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::TempDir {
195+
let tmp_dir = tempfile::tempdir().unwrap();
196+
let gh_out_path = tmp_dir.path().join("gh_out");
195197
unsafe {
196-
env::remove_var("GITHUB_OUTPUT"); // avoid writing to GH_OUT in parallel-running tests
198+
env::set_var("GITHUB_OUTPUT", gh_out_path.to_string_lossy().to_string());
197199
}
200+
tmp_dir
201+
}
202+
203+
#[tokio::test]
204+
async fn normal() {
205+
let tmp_gh_out = setup_tmp_gh_out_path();
198206
run_main(vec![
199207
"cpp-linter".to_string(),
200208
"-l".to_string(),
@@ -205,23 +213,21 @@ mod test {
205213
])
206214
.await
207215
.unwrap();
216+
drop(tmp_gh_out);
208217
}
209218

210219
#[tokio::test]
211220
async fn version_command() {
212-
unsafe {
213-
env::remove_var("GITHUB_OUTPUT"); // avoid writing to GH_OUT in parallel-running tests
214-
}
221+
let tmp_gh_out = setup_tmp_gh_out_path();
215222
run_main(vec!["cpp-linter".to_string(), "version".to_string()])
216223
.await
217224
.unwrap();
225+
drop(tmp_gh_out);
218226
}
219227

220228
#[tokio::test]
221229
async fn force_debug_output() {
222-
unsafe {
223-
env::remove_var("GITHUB_OUTPUT"); // avoid writing to GH_OUT in parallel-running tests
224-
}
230+
let tmp_gh_out = setup_tmp_gh_out_path();
225231
run_main(vec![
226232
"cpp-linter".to_string(),
227233
"-l".to_string(),
@@ -231,13 +237,12 @@ mod test {
231237
])
232238
.await
233239
.unwrap();
240+
drop(tmp_gh_out);
234241
}
235242

236243
#[tokio::test]
237244
async fn no_version_input() {
238-
unsafe {
239-
env::remove_var("GITHUB_OUTPUT"); // avoid writing to GH_OUT in parallel-running tests
240-
}
245+
let tmp_gh_out = setup_tmp_gh_out_path();
241246
run_main(vec![
242247
"cpp-linter".to_string(),
243248
"-l".to_string(),
@@ -246,12 +251,13 @@ mod test {
246251
])
247252
.await
248253
.unwrap();
254+
drop(tmp_gh_out);
249255
}
250256

251257
#[tokio::test]
252258
async fn pre_commit_env() {
259+
let tmp_gh_out = setup_tmp_gh_out_path();
253260
unsafe {
254-
env::remove_var("GITHUB_OUTPUT"); // avoid writing to GH_OUT in parallel-running tests
255261
env::set_var("PRE_COMMIT", "1");
256262
}
257263
run_main(vec![
@@ -262,15 +268,14 @@ mod test {
262268
])
263269
.await
264270
.unwrap_err();
271+
drop(tmp_gh_out);
265272
}
266273

267274
// Verifies that the system gracefully handles cases where all analysis is disabled.
268275
// This ensures no diagnostic comments are generated when analysis is explicitly skipped.
269276
#[tokio::test]
270277
async fn no_analysis() {
271-
unsafe {
272-
env::remove_var("GITHUB_OUTPUT"); // avoid writing to GH_OUT in parallel-running tests
273-
}
278+
let tmp_gh_out = setup_tmp_gh_out_path();
274279
run_main(vec![
275280
"cpp-linter".to_string(),
276281
"-l".to_string(),
@@ -281,19 +286,19 @@ mod test {
281286
])
282287
.await
283288
.unwrap();
289+
drop(tmp_gh_out);
284290
}
285291

286292
#[tokio::test]
287293
async fn bad_repo_root() {
288-
unsafe {
289-
env::remove_var("GITHUB_OUTPUT"); // avoid writing to GH_OUT in parallel-running tests
290-
}
294+
let tmp_gh_out = setup_tmp_gh_out_path();
291295
run_main(vec![
292296
"cpp-linter".to_string(),
293297
"--repo-root".to_string(),
294298
"some-non-existent-dir".to_string(),
295299
])
296300
.await
297301
.unwrap_err();
302+
drop(tmp_gh_out);
298303
}
299304
}

0 commit comments

Comments
 (0)