From f2d87ec02e857b7ffea273d24496ddf14b8d83c3 Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Thu, 16 Dec 2021 16:50:15 +0800 Subject: [PATCH] code guideline: Fix bug of mischeck file name with '_' (#901) Fix bug that code guideline reports error when there is '_' in new file's name. And add unit test cases, which can be run with `pyhton3 -m unitest `. --- ci/coding_guidelines_check.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/ci/coding_guidelines_check.py b/ci/coding_guidelines_check.py index 8e583ccb..c3fd820e 100644 --- a/ci/coding_guidelines_check.py +++ b/ci/coding_guidelines_check.py @@ -11,6 +11,7 @@ import shlex import shutil import subprocess import sys +import unittest CLANG_FORMAT_CMD = "clang-format-12" GIT_CLANG_FORMAT_CMD = "git-clang-format-12" @@ -155,7 +156,7 @@ def run_aspell(file_path: pathlib, root: pathlib) -> bool: def check_dir_name(path: pathlib, root: pathlib) -> bool: - m = re.search(INVALID_DIR_NAME_SEGMENT, str(path.relative_to(root))) + m = re.search(INVALID_DIR_NAME_SEGMENT, str(path.relative_to(root).parent)) if m: print(f"--- found a character '_' in {m.groups()} in {path}") @@ -271,5 +272,30 @@ def main() -> int: return process_entire_pr(wamr_root, options.commits) +# run with python3 -m unitest ci/coding_guidelines_check.py +class TestCheck(unittest.TestCase): + def test_check_dir_name_failed(self): + root = pathlib.Path("/root/Workspace/") + new_file_path = root.joinpath("core/shared/platform/esp_idf/espid_memmap.c") + self.assertFalse(check_dir_name(new_file_path, root)) + + def test_check_dir_name_pass(self): + root = pathlib.Path("/root/Workspace/") + new_file_path = root.joinpath("core/shared/platform/esp-idf/espid_memmap.c") + self.assertTrue(check_dir_name(new_file_path, root)) + + def test_check_file_name_failed(self): + new_file_path = pathlib.Path( + "/root/Workspace/core/shared/platform/esp-idf/espid-memmap.c" + ) + self.assertFalse(check_file_name(new_file_path)) + + def test_check_file_name_pass(self): + new_file_path = pathlib.Path( + "/root/Workspace/core/shared/platform/esp-idf/espid_memmap.c" + ) + self.assertTrue(check_file_name(new_file_path)) + + if __name__ == "__main__": sys.exit(0 if main() else 1)