Skip to content

Commit 17134fb

Browse files
committed
test: prevent erroneous CI runs
I'm guessing that the parallel writes to GITHUB_OUTPUT env var are causing the test CI to behave as if the workflow never finishes. This patch, hopefully, should fix that by changing the env var's value to a temp file created during the test.
1 parent 4b1b5bd commit 17134fb

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

cpp-linter/src/run.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,19 @@ pub async fn run_main(args: Vec<String>) -> Result<()> {
159159
mod test {
160160
use super::run_main;
161161
use std::env;
162+
use tempfile::NamedTempFile;
163+
164+
/// Avoid writing to GITHUB_OUTPUT in parallel-running tests.
165+
///
166+
/// This simply creates a temp file and sets the env var, GITHUB_OUTPUT, to the temp file's path.
167+
fn monkey_patch_gh_output() {
168+
let fake_gh_out = NamedTempFile::new().unwrap();
169+
env::set_var("GITHUB_OUTPUT", fake_gh_out.path());
170+
}
162171

163172
#[tokio::test]
164173
async fn normal() {
165-
env::remove_var("GITHUB_OUTPUT"); // avoid writing to GH_OUT in parallel-running tests
174+
monkey_patch_gh_output();
166175
let result = run_main(vec![
167176
"cpp-linter".to_string(),
168177
"-l".to_string(),
@@ -177,14 +186,14 @@ mod test {
177186

178187
#[tokio::test]
179188
async fn version_command() {
180-
env::remove_var("GITHUB_OUTPUT"); // avoid writing to GH_OUT in parallel-running tests
189+
monkey_patch_gh_output();
181190
let result = run_main(vec!["cpp-linter".to_string(), "version".to_string()]).await;
182191
assert!(result.is_ok());
183192
}
184193

185194
#[tokio::test]
186195
async fn force_debug_output() {
187-
env::remove_var("GITHUB_OUTPUT"); // avoid writing to GH_OUT in parallel-running tests
196+
monkey_patch_gh_output();
188197
let result = run_main(vec![
189198
"cpp-linter".to_string(),
190199
"-l".to_string(),
@@ -199,7 +208,7 @@ mod test {
199208

200209
#[tokio::test]
201210
async fn bad_version_input() {
202-
env::remove_var("GITHUB_OUTPUT"); // avoid writing to GH_OUT in parallel-running tests
211+
monkey_patch_gh_output();
203212
let result = run_main(vec![
204213
"cpp-linter".to_string(),
205214
"-l".to_string(),
@@ -212,7 +221,7 @@ mod test {
212221

213222
#[tokio::test]
214223
async fn pre_commit_env() {
215-
env::remove_var("GITHUB_OUTPUT"); // avoid writing to GH_OUT in parallel-running tests
224+
monkey_patch_gh_output();
216225
env::set_var("PRE_COMMIT", "1");
217226
let result = run_main(vec![
218227
"cpp-linter".to_string(),
@@ -228,7 +237,7 @@ mod test {
228237
// This ensures no diagnostic comments are generated when analysis is explicitly skipped.
229238
#[tokio::test]
230239
async fn no_analysis() {
231-
env::remove_var("GITHUB_OUTPUT"); // avoid writing to GH_OUT in parallel-running tests
240+
monkey_patch_gh_output();
232241
let result = run_main(vec![
233242
"cpp-linter".to_string(),
234243
"-l".to_string(),

cpp-linter/tests/comments.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ async fn setup(lib_root: &Path, test_params: &TestParams) {
6666
"GITHUB_EVENT_NAME",
6767
test_params.event_t.to_string().as_str(),
6868
);
69-
env::remove_var("GITHUB_OUTPUT"); // avoid writing to GH_OUT in parallel-running tests
7069
env::set_var("GITHUB_REPOSITORY", REPO);
7170
env::set_var("GITHUB_SHA", SHA);
7271
env::set_var("GITHUB_TOKEN", TOKEN);
@@ -251,6 +250,8 @@ async fn test_comment(test_params: &TestParams) {
251250
let tmp_dir = create_test_space(true);
252251
let lib_root = env::current_dir().unwrap();
253252
env::set_current_dir(tmp_dir.path()).unwrap();
253+
let fake_gh_out = NamedTempFile::new().unwrap();
254+
env::set_var("GITHUB_OUTPUT", fake_gh_out.path());
254255
setup(&lib_root, test_params).await;
255256
env::set_current_dir(lib_root.as_path()).unwrap();
256257
drop(tmp_dir);

cpp-linter/tests/reviews.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ fn generate_tool_summary(review_enabled: bool, force_lgtm: bool, tool_name: &str
7272
}
7373

7474
async fn setup(lib_root: &Path, test_params: &TestParams) {
75-
env::remove_var("GITHUB_OUTPUT"); // avoid writing to GH_OUT in parallel-running tests
7675
env::set_var("GITHUB_EVENT_NAME", "pull_request");
7776
env::set_var("GITHUB_REPOSITORY", REPO);
7877
env::set_var("GITHUB_SHA", SHA);
@@ -247,6 +246,8 @@ async fn setup(lib_root: &Path, test_params: &TestParams) {
247246
async fn test_review(test_params: &TestParams) {
248247
let tmp_dir = create_test_space(true);
249248
let lib_root = env::current_dir().unwrap();
249+
let fake_gh_out = NamedTempFile::new().unwrap();
250+
env::set_var("GITHUB_OUTPUT", fake_gh_out.path());
250251
env::set_current_dir(tmp_dir.path()).unwrap();
251252
setup(&lib_root, test_params).await;
252253
env::set_current_dir(lib_root.as_path()).unwrap();

0 commit comments

Comments
 (0)