Add "--check" option support to trailing_whitespace hook

This commit is contained in:
zhiwei.meng 2026-04-02 15:20:54 +08:00
parent 3b8b26a097
commit 4842364696
2 changed files with 40 additions and 7 deletions

View file

@ -18,6 +18,23 @@ def test_fixes_trailing_whitespace(input_s, expected, tmpdir):
assert main((str(path),)) == 1
assert path.read() == expected
@pytest.mark.parametrize(
('input_s', 'exit_code', "lines"),
(
('foo \nbar \n', 1, [1,2]),
('bar\t\nbaz\t\n', 1, [1,2]),
('bar\nbaz\t\n', 1, [2]),
),
)
def test_fixes_trailing_whitespace_check_only(capsys, input_s, exit_code, lines, tmpdir):
path = tmpdir.join('file.md')
path.write(input_s)
assert main(('--check', str(path),)) == exit_code
assert path.read() == input_s
captured = capsys.readouterr()
location = "@ " + ','.join(map(str, lines))
assert location in captured.out
def test_ok_no_newline_end_of_file(tmpdir):
filename = tmpdir.join('f')