diff --git a/cpplint_clitest.py b/cpplint_clitest.py index 824a07e7..b20566fc 100755 --- a/cpplint_clitest.py +++ b/cpplint_clitest.py @@ -39,7 +39,6 @@ import tempfile import pytest -from parameterized import parameterized # type: ignore[import-untyped] from testfixtures import compare # type: ignore[import-untyped] import cpplint # noqa: F401 @@ -55,7 +54,7 @@ def run_shell_command(cmd: str, args: str, cwd: str = ".") -> tuple[int, bytes, args: A string with arguments to the command. cwd: from which folder to run. """ - cmd, args = cmd.split(), args.split() # type: ignore[assignment] + cmd, args = cmd.split(), args.replace('"', "").split() # type: ignore[assignment] proc = subprocess.run(cmd + args, cwd=cwd, capture_output=True, check=False) out, err = proc.stdout, proc.stderr @@ -175,14 +174,14 @@ class TestNoRepoSignature(TemporaryFolderClassSetup): def get_extra_command_args(self, cwd): return f" --repository {self._root} " - @parameterized.expand( + @pytest.mark.parametrize( + ("folder", "case"), [ (folder, case[:-4]) for folder in ["chromium", "vlc", "silly", "boost", "protobuf", "codelite", "v8"] for case in os.listdir(f"./samples/{folder}-sample") if case.endswith(".def") ], - name_func=lambda fun, _, x: f"test_{x.args[0]}_sample-{x.args[1]}", ) @pytest.mark.timeout(180) def test_samples(self, folder, case): diff --git a/cpplint_unittest.py b/cpplint_unittest.py index d0bda8e1..821bc786 100755 --- a/cpplint_unittest.py +++ b/cpplint_unittest.py @@ -30,7 +30,7 @@ """Unit test for cpplint.py.""" -# TODO(unknown): Add a good test that tests UpdateIncludeState. +# TODO(google): Add a good test that tests UpdateIncludeState. import codecs import os @@ -43,7 +43,6 @@ import tempfile import pytest -from parameterized import parameterized # type: ignore[import-untyped] import cpplint @@ -2230,7 +2229,7 @@ def testConstStringReferenceMembers(self): "const string &turing", "const string & godel", ] - # TODO(unknown): Enable also these tests if and when we ever + # TODO(google): Enable also these tests if and when we ever # decide to check for arbitrary member references. # "const Turing & a", # "const Church& a", @@ -4604,7 +4603,7 @@ def testConditionals(self): "", ) - @parameterized.expand(["else if", "if", "while", "for", "switch"]) + @pytest.mark.parametrize("keyword", ["else if", "if", "while", "for", "switch"]) def testControlClauseWithParensNewline(self, keyword): # The % 2 part is pseudorandom whitespace-support testing self.TestLintContains( @@ -4616,7 +4615,7 @@ def testControlClauseWithParensNewline(self, keyword): f" should be on a separate line [whitespace/newline] [5]", ) - @parameterized.expand(["else", "do", "try"]) + @pytest.mark.parametrize("keyword", ["else", "do", "try"]) def testControlClauseWithoutParensNewline(self, keyword): # The % 2 part is pseudorandom whitespace-support testing self.TestLintContains( diff --git a/pyproject.toml b/pyproject.toml index 32bccef1..a4016391 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,6 @@ dependencies = [ ] optional-dependencies.dev = [ "mypy", - "parameterized", "pylint>=3.3.4", "pytest", "pytest-cov", @@ -206,4 +205,4 @@ addopts = "--color=yes --cov-fail-under=90 --cov=cpplint" python_files = [ "*test.py" ] required_plugins = [ "pytest-cov", "pytest-timeout" ] testpaths = [ "." ] -timeout = 60 +timeout = 481 diff --git a/regen-defs.zsh b/regen-defs.zsh new file mode 100755 index 00000000..07c1880e --- /dev/null +++ b/regen-defs.zsh @@ -0,0 +1,48 @@ +#!/bin/zsh + +# Input the path of cpplint here +cpplint="$HOME/Documents/cpplint/cpplint.py" + +cd samples/ || exit 74 # EX_IOERROR + +# Loop through all .def files in the given directories +folders=(${(f)"$(cat)"}) +for folder in $folders; do + cd "$folder-sample/" || exit 66 # EX_NOINPUT + for file in ./*.def; do + if [[ ! -s "$file" ]]; then + echo "Skipping empty file: $file" + continue + fi + echo "Processing $file..." + + # Extract the command from the first line of the file + cmd=$(head -n 1 "$file") + + # Create temporary files for stdout and stderr + stdout_file=$(mktemp) + stderr_file=$(mktemp) + + # Execute the command and capture stdout and stderr + uv run "$cpplint" $cmd > "$stdout_file" 2> "$stderr_file" + ret_code=$? + + # Count the number of lines in stdout + (( num_lines=$(wc -l < "$stdout_file") + 1 )) + + # Overwrite the original definition file + { + echo "$cmd" + echo "$ret_code" + echo "$num_lines" + cat "$stdout_file" + echo + cat "$stderr_file" + echo + } > "$file" + + # Clean up temporary files + rm "$stdout_file" "$stderr_file" + done + cd .. +done diff --git a/samples/boost-sample/exclude.def b/samples/boost-sample/exclude.def deleted file mode 100644 index 731ffadb..00000000 --- a/samples/boost-sample/exclude.def +++ /dev/null @@ -1,129 +0,0 @@ ---recursive --exclude=headers/* src -1 -4 -Done processing src/inspect/unnamed_namespace_check.hpp -Done processing src/tr1/c_policy.hpp -Total errors found: 121 - -src/inspect/unnamed_namespace_check.hpp:0: No #ifndef header guard found, suggested CPP variable is: SAMPLES_BOOST_SAMPLE_SRC_INSPECT_UNNAMED_NAMESPACE_CHECK_HPP_ [build/header_guard] [5] -src/inspect/unnamed_namespace_check.hpp:11: Include the directory when naming header files [build/include_subdir] [4] -src/inspect/unnamed_namespace_check.hpp:14: Do not use unnamed namespaces in header files. See https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Namespaces for more information. [build/namespaces_headers] [4] -src/inspect/unnamed_namespace_check.hpp:17: Do not indent within a namespace. [whitespace/indent_namespace] [4] -src/inspect/unnamed_namespace_check.hpp:18: At least two spaces is best between code and comments [whitespace/comments] [2] -src/inspect/unnamed_namespace_check.hpp:19: Closing ) should be moved to the previous line [whitespace/parens] [2] -src/inspect/unnamed_namespace_check.hpp:21: Anonymous namespace should be terminated with "// namespace" [readability/namespace] [5] -src/inspect/unnamed_namespace_check.hpp:21: At least two spaces is best between code and comments [whitespace/comments] [2] -src/inspect/unnamed_namespace_check.hpp:26: { should almost always be at the end of the previous line [whitespace/braces] [4] -src/inspect/unnamed_namespace_check.hpp:27: Do not indent within a namespace. [whitespace/indent_namespace] [4] -src/inspect/unnamed_namespace_check.hpp:28: Do not indent within a namespace. [whitespace/indent_namespace] [4] -src/inspect/unnamed_namespace_check.hpp:28: { should almost always be at the end of the previous line [whitespace/braces] [4] -src/inspect/unnamed_namespace_check.hpp:29: Do not indent within a namespace. [whitespace/indent_namespace] [4] -src/inspect/unnamed_namespace_check.hpp:29: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/inspect/unnamed_namespace_check.hpp:30: Do not indent within a namespace. [whitespace/indent_namespace] [4] -src/inspect/unnamed_namespace_check.hpp:30: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/inspect/unnamed_namespace_check.hpp:30: { should almost always be at the end of the previous line [whitespace/braces] [4] -src/inspect/unnamed_namespace_check.hpp:31: Extra space after ( in function call [whitespace/parens] [4] -src/inspect/unnamed_namespace_check.hpp:31: Extra space before ) [whitespace/parens] [2] -src/inspect/unnamed_namespace_check.hpp:32: At least two spaces is best between code and comments [whitespace/comments] [2] -src/inspect/unnamed_namespace_check.hpp:32: Extra space after ( in function call [whitespace/parens] [4] -src/inspect/unnamed_namespace_check.hpp:32: Extra space before ) [whitespace/parens] [2] -src/inspect/unnamed_namespace_check.hpp:33: Extra space after ( in function call [whitespace/parens] [4] -src/inspect/unnamed_namespace_check.hpp:33: Extra space before ) [whitespace/parens] [2] -src/inspect/unnamed_namespace_check.hpp:34: At least two spaces is best between code and comments [whitespace/comments] [2] -src/inspect/unnamed_namespace_check.hpp:34: Extra space after ( in function call [whitespace/parens] [4] -src/inspect/unnamed_namespace_check.hpp:34: Extra space before ) [whitespace/parens] [2] -src/inspect/unnamed_namespace_check.hpp:35: Extra space after ( in function call [whitespace/parens] [4] -src/inspect/unnamed_namespace_check.hpp:35: Extra space before ) [whitespace/parens] [2] -src/inspect/unnamed_namespace_check.hpp:36: Extra space after ( in function call [whitespace/parens] [4] -src/inspect/unnamed_namespace_check.hpp:36: Extra space before ) [whitespace/parens] [2] -src/inspect/unnamed_namespace_check.hpp:37: Extra space after ( in function call [whitespace/parens] [4] -src/inspect/unnamed_namespace_check.hpp:37: Extra space before ) [whitespace/parens] [2] -src/inspect/unnamed_namespace_check.hpp:38: Do not indent within a namespace. [whitespace/indent_namespace] [4] -src/inspect/unnamed_namespace_check.hpp:38: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/inspect/unnamed_namespace_check.hpp:40: Do not indent within a namespace. [whitespace/indent_namespace] [4] -src/inspect/unnamed_namespace_check.hpp:40: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/inspect/unnamed_namespace_check.hpp:44: Do not indent within a namespace. [whitespace/indent_namespace] [4] -src/inspect/unnamed_namespace_check.hpp:44: { should almost always be at the end of the previous line [whitespace/braces] [4] -src/inspect/unnamed_namespace_check.hpp:48: Lines should be <= 80 characters long [whitespace/line_length] [2] -src/inspect/unnamed_namespace_check.hpp:49: Missing space before ( in for( [whitespace/parens] [5] -src/inspect/unnamed_namespace_check.hpp:50: { should almost always be at the end of the previous line [whitespace/braces] [4] -src/inspect/unnamed_namespace_check.hpp:54: Extra space after ( in function call [whitespace/parens] [4] -src/inspect/unnamed_namespace_check.hpp:54: Extra space before ) [whitespace/parens] [2] -src/inspect/unnamed_namespace_check.hpp:57: Redundant blank line at the end of a code block should be deleted. [whitespace/blank_line] [3] -src/inspect/unnamed_namespace_check.hpp:58: Do not indent within a namespace. [whitespace/indent_namespace] [4] -src/inspect/unnamed_namespace_check.hpp:59: Do not indent within a namespace. [whitespace/indent_namespace] [4] -src/inspect/unnamed_namespace_check.hpp:59: At least two spaces is best between code and comments [whitespace/comments] [2] -src/inspect/unnamed_namespace_check.hpp:60: At least two spaces is best between code and comments [whitespace/comments] [2] -src/inspect/unnamed_namespace_check.hpp:51: Add #include for string [build/include_what_you_use] [4] -src/tr1/c_policy.hpp:0: No #ifndef header guard found, suggested CPP variable is: SAMPLES_BOOST_SAMPLE_SRC_TR1_C_POLICY_HPP_ [build/header_guard] [5] -src/tr1/c_policy.hpp:9: Missing space before { [whitespace/braces] [5] -src/tr1/c_policy.hpp:13: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4] -src/tr1/c_policy.hpp:14: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4] -src/tr1/c_policy.hpp:15: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4] -src/tr1/c_policy.hpp:16: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4] -src/tr1/c_policy.hpp:17: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4] -src/tr1/c_policy.hpp:18: Lines should be <= 80 characters long [whitespace/line_length] [2] -src/tr1/c_policy.hpp:19: { should almost always be at the end of the previous line [whitespace/braces] [4] -src/tr1/c_policy.hpp:20: public: should be indented +1 space inside struct policy [whitespace/indent] [3] -src/tr1/c_policy.hpp:21: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:22: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:23: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:24: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:25: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:26: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:27: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:28: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:30: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:32: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:34: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:35: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:36: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:37: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:38: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:39: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:44: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4] -src/tr1/c_policy.hpp:45: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4] -src/tr1/c_policy.hpp:46: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4] -src/tr1/c_policy.hpp:47: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4] -src/tr1/c_policy.hpp:48: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4] -src/tr1/c_policy.hpp:49: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4] -src/tr1/c_policy.hpp:50: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4] -src/tr1/c_policy.hpp:51: Lines should be <= 80 characters long [whitespace/line_length] [2] -src/tr1/c_policy.hpp:52: { should almost always be at the end of the previous line [whitespace/braces] [4] -src/tr1/c_policy.hpp:53: public: should be indented +1 space inside struct policy [whitespace/indent] [3] -src/tr1/c_policy.hpp:54: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:55: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:56: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:57: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:58: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:59: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:60: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:61: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:63: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:65: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:67: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:68: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:69: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:70: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:71: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:72: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:76: Lines should be <= 80 characters long [whitespace/line_length] [2] -src/tr1/c_policy.hpp:88: { should almost always be at the end of the previous line [whitespace/braces] [4] -src/tr1/c_policy.hpp:89: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:89: Lines should be <= 80 characters long [whitespace/line_length] [2] -src/tr1/c_policy.hpp:93: Lines should be <= 80 characters long [whitespace/line_length] [2] -src/tr1/c_policy.hpp:105: { should almost always be at the end of the previous line [whitespace/braces] [4] -src/tr1/c_policy.hpp:106: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] -src/tr1/c_policy.hpp:106: Lines should be <= 80 characters long [whitespace/line_length] [2] -src/tr1/c_policy.hpp:109: Namespace should be terminated with "// namespace policies" [readability/namespace] [5] -src/tr1/c_policy.hpp:109: Namespace should be terminated with "// namespace math" [readability/namespace] [5] -src/tr1/c_policy.hpp:109: Namespace should be terminated with "// namespace boost" [readability/namespace] [5] -src/tr1/c_policy.hpp:109: At least two spaces is best between code and comments [whitespace/comments] [2] -src/tr1/c_policy.hpp:111: Missing space before { [whitespace/braces] [5] -src/tr1/c_policy.hpp:122: Do not indent within a namespace. [whitespace/indent_namespace] [4] -src/tr1/c_policy.hpp:123: Do not indent within a namespace. [whitespace/indent_namespace] [4] -src/tr1/c_policy.hpp:124: Do not indent within a namespace. [whitespace/indent_namespace] [4] -src/tr1/c_policy.hpp:125: Do not indent within a namespace. [whitespace/indent_namespace] [4] -src/tr1/c_policy.hpp:126: Do not indent within a namespace. [whitespace/indent_namespace] [4] -src/tr1/c_policy.hpp:131: Namespace should be terminated with "// namespace c_policies" [readability/namespace] [5] - diff --git a/samples/boost-sample/headers_inspect.def b/samples/boost-sample/headers_inspect_exclude.def similarity index 99% rename from samples/boost-sample/headers_inspect.def rename to samples/boost-sample/headers_inspect_exclude.def index 3c1d6474..61c147cb 100644 --- a/samples/boost-sample/headers_inspect.def +++ b/samples/boost-sample/headers_inspect_exclude.def @@ -1,4 +1,4 @@ -src/inspect/* +--recursive "--exclude=src/tr1/*" src 1 3 Done processing src/inspect/unnamed_namespace_check.hpp