From 1f461045ef5f92da955a92790845e1a0a3eadc73 Mon Sep 17 00:00:00 2001 From: Johnson Sun Date: Thu, 22 Aug 2024 04:05:07 +0800 Subject: [PATCH] test: Unify `.gitignore` across all workspaces and add tests --- cartographer_ws/.gitignore | 7 +++---- husky_ws/.gitignore | 7 +------ kobuki_ws/.gitignore | 7 +------ orbslam3_ws/.gitignore | 9 +++++++++ rtabmap_ws/.gitignore | 7 +++---- template_ws/.gitignore | 3 ++- tests/diff_base/.gitignore | 8 ++++++++ ...nt_devcontainer.py => lint_comp_template.py} | 12 +++++++++--- tests/lint_gitignore.py | 17 +++++++++++++++++ vlp_ws/.gitignore | 7 +++---- 10 files changed, 56 insertions(+), 28 deletions(-) create mode 100644 tests/diff_base/.gitignore rename tests/{lint_devcontainer.py => lint_comp_template.py} (78%) create mode 100644 tests/lint_gitignore.py diff --git a/cartographer_ws/.gitignore b/cartographer_ws/.gitignore index d56eeb47..2bc3ebb3 100644 --- a/cartographer_ws/.gitignore +++ b/cartographer_ws/.gitignore @@ -1,8 +1,7 @@ +# Visual Studio Code .vscode + +# ROS2 basic directories /build /install /log -docker/cache/* -!docker/cache/.gazebo -docker/cache/.gazebo/* -!docker/cache/.gazebo/.gitkeep \ No newline at end of file diff --git a/husky_ws/.gitignore b/husky_ws/.gitignore index 6bf2ffcd..2bc3ebb3 100644 --- a/husky_ws/.gitignore +++ b/husky_ws/.gitignore @@ -1,12 +1,7 @@ +# Visual Studio Code .vscode # ROS2 basic directories /build /install /log - -# Gazebo cache -docker/cache/* -!docker/cache/.gazebo -docker/cache/.gazebo/* -!docker/cache/.gazebo/.gitkeep \ No newline at end of file diff --git a/kobuki_ws/.gitignore b/kobuki_ws/.gitignore index 6bf2ffcd..2bc3ebb3 100644 --- a/kobuki_ws/.gitignore +++ b/kobuki_ws/.gitignore @@ -1,12 +1,7 @@ +# Visual Studio Code .vscode # ROS2 basic directories /build /install /log - -# Gazebo cache -docker/cache/* -!docker/cache/.gazebo -docker/cache/.gazebo/* -!docker/cache/.gazebo/.gitkeep \ No newline at end of file diff --git a/orbslam3_ws/.gitignore b/orbslam3_ws/.gitignore index 123266bd..891f5aab 100644 --- a/orbslam3_ws/.gitignore +++ b/orbslam3_ws/.gitignore @@ -1,2 +1,11 @@ +# Visual Studio Code +.vscode + +# ROS2 basic directories +/build +/install +/log + +# ROS2 bag files V1_02_medium.bag V1_02_medium/ diff --git a/rtabmap_ws/.gitignore b/rtabmap_ws/.gitignore index f14775a5..2bc3ebb3 100644 --- a/rtabmap_ws/.gitignore +++ b/rtabmap_ws/.gitignore @@ -1,8 +1,7 @@ +# Visual Studio Code .vscode + +# ROS2 basic directories /build /install /log -docker/cache/* -!docker/cache/.gazebo -docker/cache/.gazebo/* -!docker/cache/.gazebo/.gitkeep diff --git a/template_ws/.gitignore b/template_ws/.gitignore index 171c8a96..2bc3ebb3 100644 --- a/template_ws/.gitignore +++ b/template_ws/.gitignore @@ -1,6 +1,7 @@ +# Visual Studio Code .vscode # ROS2 basic directories /build /install -/log \ No newline at end of file +/log diff --git a/tests/diff_base/.gitignore b/tests/diff_base/.gitignore new file mode 100644 index 00000000..90c2d24c --- /dev/null +++ b/tests/diff_base/.gitignore @@ -0,0 +1,8 @@ +# Visual Studio Code +.vscode + +# ROS2 basic directories +/build +/install +/log +MULTILINE_PLACEHOLDER \ No newline at end of file diff --git a/tests/lint_devcontainer.py b/tests/lint_comp_template.py similarity index 78% rename from tests/lint_devcontainer.py rename to tests/lint_comp_template.py index f03f38ca..9a2fc853 100644 --- a/tests/lint_devcontainer.py +++ b/tests/lint_comp_template.py @@ -12,7 +12,7 @@ def compare_file_with_template(filepath, ignored_workspaces=[]): logging.info(f"Checking if '{filepath}' matches the template...") template_path = f"{repo_dir}/tests/diff_base/{filepath}" - template = Path(template_path).read_text().splitlines(keepends=True) + template = Path(template_path).read_text().splitlines(keepends=True) # keepends to preserve trailing newlines for filename in glob.glob(f"{repo_dir}/*_ws/{filepath}"): # Skip certain cases intentionally if any(ws in filename for ws in ignored_workspaces): @@ -27,13 +27,19 @@ def error(msg, i): raise ValueError(f"'{filepath}' does not match the template: '{filename}'") i = 0 while i < len(diff): + if "- MULTILINE_PLACEHOLDER" in diff[i]: # don't use exact match to avoid cases without trailing newline + i += 1 + while i < len(diff) and diff[i].startswith('+ '): + i += 1 + continue if i+1 >= len(diff): error("Odd lines", i) if not diff[i].startswith('- ') or not diff[i+1].startswith('+ '): error("Expected no line deletion and addition", i) - regexp = "^" + re.escape(diff[i][1:]).replace('PLACEHOLDER', '.*') + "$" - if not re.match(regexp, diff[i+1][1:]): + regexp = "^" + re.escape(diff[i][2:]).replace('PLACEHOLDER', '.*') + "$" + if not re.match(regexp, diff[i+1][2:]): error("Expected line deletion and addition to differ only in the placeholder", i) i += 2 compare_file_with_template(".devcontainer/devcontainer.json", ["ros1_bridge_ws"]) +compare_file_with_template(".gitignore") diff --git a/tests/lint_gitignore.py b/tests/lint_gitignore.py new file mode 100644 index 00000000..da2a26c6 --- /dev/null +++ b/tests/lint_gitignore.py @@ -0,0 +1,17 @@ +import glob +import logging +import os +from pathlib import Path + +logging.basicConfig(level=logging.INFO) +current_dir = os.path.dirname(os.path.realpath(__file__)) +repo_dir = os.path.realpath(f"{current_dir}/..") + +logging.info("Checking `.gitignore` files...") +for filename in glob.glob(f"{repo_dir}/*_ws/.gitignore"): + logging.debug(f"Checking: '{filename[len(repo_dir)+1:]}'...") + content = Path(filename).read_text() + if "gazebo" in content: + raise ValueError(f"`gazebo` should not exist since it's obsolete: '{filename}'") + if "docker/cache" in content: + raise ValueError(f"`docker/cache` should not exist since it's obsolete: '{filename}'") diff --git a/vlp_ws/.gitignore b/vlp_ws/.gitignore index d56eeb47..2bc3ebb3 100644 --- a/vlp_ws/.gitignore +++ b/vlp_ws/.gitignore @@ -1,8 +1,7 @@ +# Visual Studio Code .vscode + +# ROS2 basic directories /build /install /log -docker/cache/* -!docker/cache/.gazebo -docker/cache/.gazebo/* -!docker/cache/.gazebo/.gitkeep \ No newline at end of file