Skip to content

Fix inf test ci #140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cpp-linter/src/common_fs/file_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ impl FileFilter {
for line in read_buf.split('\n') {
if line.trim_start().starts_with("path") {
assert!(line.find('=').unwrap() > 0);
let submodule = String::from("./") + line.split('=').last().unwrap().trim();
let submodule =
String::from("./") + line.split('=').next_back().unwrap().trim();
log::debug!("Found submodule: {submodule}");
let mut is_ignored = true;
for pat in &self.not_ignored {
Expand Down Expand Up @@ -159,7 +160,7 @@ impl FileFilter {
let mut is_hidden = false;
let parent = path
.components()
.last()
.next_back()
.ok_or(anyhow!("parent directory not known for {path:?}"))?;
if parent.as_os_str().to_str().unwrap().starts_with('.') {
is_hidden = true;
Expand Down
21 changes: 15 additions & 6 deletions cpp-linter/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,19 @@ pub async fn run_main(args: Vec<String>) -> Result<()> {
mod test {
use super::run_main;
use std::env;
use tempfile::NamedTempFile;

/// Avoid writing to GITHUB_OUTPUT in parallel-running tests.
///
/// This simply creates a temp file and sets the env var, GITHUB_OUTPUT, to the temp file's path.
fn monkey_patch_gh_output() {
let fake_gh_out = NamedTempFile::new().unwrap();
env::set_var("GITHUB_OUTPUT", fake_gh_out.path());
}

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

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

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

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

#[tokio::test]
async fn pre_commit_env() {
env::remove_var("GITHUB_OUTPUT"); // avoid writing to GH_OUT in parallel-running tests
monkey_patch_gh_output();
env::set_var("PRE_COMMIT", "1");
let result = run_main(vec![
"cpp-linter".to_string(),
Expand All @@ -228,7 +237,7 @@ mod test {
// This ensures no diagnostic comments are generated when analysis is explicitly skipped.
#[tokio::test]
async fn no_analysis() {
env::remove_var("GITHUB_OUTPUT"); // avoid writing to GH_OUT in parallel-running tests
monkey_patch_gh_output();
let result = run_main(vec![
"cpp-linter".to_string(),
"-l".to_string(),
Expand Down
3 changes: 2 additions & 1 deletion cpp-linter/tests/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ async fn setup(lib_root: &Path, test_params: &TestParams) {
"GITHUB_EVENT_NAME",
test_params.event_t.to_string().as_str(),
);
env::remove_var("GITHUB_OUTPUT"); // avoid writing to GH_OUT in parallel-running tests
env::set_var("GITHUB_REPOSITORY", REPO);
env::set_var("GITHUB_SHA", SHA);
env::set_var("GITHUB_TOKEN", TOKEN);
Expand Down Expand Up @@ -251,6 +250,8 @@ async fn test_comment(test_params: &TestParams) {
let tmp_dir = create_test_space(true);
let lib_root = env::current_dir().unwrap();
env::set_current_dir(tmp_dir.path()).unwrap();
let fake_gh_out = NamedTempFile::new().unwrap();
env::set_var("GITHUB_OUTPUT", fake_gh_out.path());
setup(&lib_root, test_params).await;
env::set_current_dir(lib_root.as_path()).unwrap();
drop(tmp_dir);
Expand Down
3 changes: 2 additions & 1 deletion cpp-linter/tests/reviews.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ fn generate_tool_summary(review_enabled: bool, force_lgtm: bool, tool_name: &str
}

async fn setup(lib_root: &Path, test_params: &TestParams) {
env::remove_var("GITHUB_OUTPUT"); // avoid writing to GH_OUT in parallel-running tests
env::set_var("GITHUB_EVENT_NAME", "pull_request");
env::set_var("GITHUB_REPOSITORY", REPO);
env::set_var("GITHUB_SHA", SHA);
Expand Down Expand Up @@ -247,6 +246,8 @@ async fn setup(lib_root: &Path, test_params: &TestParams) {
async fn test_review(test_params: &TestParams) {
let tmp_dir = create_test_space(true);
let lib_root = env::current_dir().unwrap();
let fake_gh_out = NamedTempFile::new().unwrap();
env::set_var("GITHUB_OUTPUT", fake_gh_out.path());
env::set_current_dir(tmp_dir.path()).unwrap();
setup(&lib_root, test_params).await;
env::set_current_dir(lib_root.as_path()).unwrap();
Expand Down