Skip to content
Merged
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
7 changes: 3 additions & 4 deletions cpplint_clitest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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):
Expand Down
9 changes: 4 additions & 5 deletions cpplint_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -43,7 +43,6 @@
import tempfile

import pytest
from parameterized import parameterized # type: ignore[import-untyped]

import cpplint

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ dependencies = [ ]

optional-dependencies.dev = [
"mypy",
"parameterized",
"pylint>=3.3.4",
"pytest",
"pytest-cov",
Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a massive change. Is there a particular versions of Python and/or operating system that is so slow?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not that it's slow, it's that I oftentimes find myself having to debug the tests, for which 1 minute is not enough for. My average debugging time is about 5 minutes, and 418 is my favorite number.

Copy link
Member

@cclauss cclauss Apr 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

48 changes: 48 additions & 0 deletions regen-defs.zsh
Original file line number Diff line number Diff line change
@@ -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
129 changes: 0 additions & 129 deletions samples/boost-sample/exclude.def

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
src/inspect/*
--recursive "--exclude=src/tr1/*" src
1
3
Done processing src/inspect/unnamed_namespace_check.hpp
Expand Down