Merge 0d927ca8a045baf525c13671e7c35fd7ed2cc148 into 553741557a57df44a46fb3ab72b6aafeaf945337

This commit is contained in:
frankliee 2026-10-26 16:40:39 +08:00 committed by GitHub
commit f709d0dae3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 39 additions and 1 deletions

View File

@ -68,6 +68,8 @@ if [ "${1:-}" = "--check" ]; then
fi
else
echo "Formatting $FILE_COUNT files in csrc/..."
echo "$FILES" | xargs "$CLANG_FORMAT_BIN" -i
while IFS= read -r file; do
"$CLANG_FORMAT_BIN" -i "$file"
done <<< "$FILES"
echo "Done."
fi

View File

@ -0,0 +1,36 @@
from __future__ import annotations
import shutil
import subprocess
from pathlib import Path
import pytest
@pytest.mark.ci
@pytest.mark.ci_npu
def test_format_csrc_with_spaces(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
formatter = shutil.which("clang-format")
if formatter is None:
pytest.skip("clang-format is required (see requirements-dev.txt)")
monkeypatch.setenv("CLANG_FORMAT", formatter)
repo = Path(__file__).resolve().parents[2]
checkout = tmp_path / "checkout with spaces"
(checkout / "scripts").mkdir(parents=True)
(checkout / "csrc").mkdir()
script = checkout / "scripts/format_csrc.sh"
shutil.copyfile(repo / "scripts/format_csrc.sh", script)
shutil.copyfile(repo / ".clang-format", checkout / ".clang-format")
source = checkout / "csrc/source with spaces.cpp"
source.write_text("int value=1;\n")
for args in ([], ["--check"]):
subprocess.run(
["bash", str(script), *args],
check=True,
capture_output=True,
text=True,
timeout=15,
)
assert source.read_text() == "int value = 1;\n"