From 11ad182e0e1566c645f6bc3ec8206f6f9b4c24d4 Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Sat, 5 Apr 2025 16:16:56 -0400 Subject: [PATCH 1/4] increase default pytest timeout to 481s Sometimes, one hath th'need to debugst the tests. And 60s turned the good ol' debugger into Indiana Jones escapingst a rolling boulder. No more. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index f028050..45dad7b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -209,4 +209,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 From 1e39bffccec7c31e7c34ea990ec7ca905cc7da67 Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Sat, 5 Apr 2025 17:32:13 -0400 Subject: [PATCH 2/4] remove duplicate boost sample for testing inspect headers Before this, the exclude test did not test excluding at all and just duplicated all the errors contained in the other two .def's --- samples/boost-sample/exclude.def | 129 ------------------ ...nspect.def => headers_inspect_exclude.def} | 2 +- 2 files changed, 1 insertion(+), 130 deletions(-) delete mode 100644 samples/boost-sample/exclude.def rename samples/boost-sample/{headers_inspect.def => headers_inspect_exclude.def} (99%) diff --git a/samples/boost-sample/exclude.def b/samples/boost-sample/exclude.def deleted file mode 100644 index 731ffad..0000000 --- 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 3c1d647..61c147c 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 From c0eb131751a00bbaa3d74f9569081f50afa8737d Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Sat, 5 Apr 2025 18:11:34 -0400 Subject: [PATCH 3/4] use pytest parametrized instead of parameterized & google todo credit This unfortunately means we must use test names like test_samples[silly-includeorder_cfirst] now. todo(unknown)s were replaced with the appropriate todo(google)s credit (we do not have the knowledge to be more specific than that) --- cpplint_clitest.py | 7 +++---- cpplint_unittest.py | 9 ++++----- pyproject.toml | 1 - 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/cpplint_clitest.py b/cpplint_clitest.py index 2694712..c6baaaa 100755 --- a/cpplint_clitest.py +++ b/cpplint_clitest.py @@ -41,7 +41,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 @@ -57,7 +56,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 @@ -177,14 +176,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 079c7d3..140d7e2 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. from __future__ import annotations @@ -45,7 +45,6 @@ import tempfile import pytest -from parameterized import parameterized # type: ignore[import-untyped] import cpplint @@ -2232,7 +2231,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", @@ -4606,7 +4605,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( @@ -4618,7 +4617,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 45dad7b..60218e4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,7 +42,6 @@ dependencies = [ ] optional-dependencies.dev = [ "mypy", - "parameterized", "pylint>=2.11", "pytest", "pytest-cov", From e91570a4c09b66545858a9d9a9f255ef29edea34 Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Sat, 5 Apr 2025 18:19:21 -0400 Subject: [PATCH 4/4] add script to update CLI test definitions Obviously, we should still check all the changes to the test definitions. This script just makes finding these changes easier. --- regen-defs.zsh | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 regen-defs.zsh diff --git a/regen-defs.zsh b/regen-defs.zsh new file mode 100755 index 0000000..07c1880 --- /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