# Path: pre_commit_hooks/check_symlinks.py
# def main(argv: Sequence[str] | None = None) -> int:
#     parser = argparse.ArgumentParser(description='Checks for broken symlinks.')
#     parser.add_argument('filenames', nargs='*', help='Filenames to check')
#     args = parser.parse_args(argv)
# 
#     retv = 0
# 
#     for filename in args.filenames:
#         if (
#                 os.path.islink(filename) and
#                 not os.path.exists(filename)
#         ):  # pragma: no cover (symlink support required)
#             print(f'{filename}: Broken symlink')
#             retv = 1
# 
#     return retv


import os
import pytest
from pre_commit_hooks.check_symlinks import main
from __future__ import annotations





xfail_symlink = pytest.mark.xfail(os.name == 'nt', reason='No symlink support')


@xfail_symlink
@pytest.mark.parametrize(
    ('dest', 'expected'), (('exists', 0), ('does-not-exist', 1)),
)
def test_main(tmpdir, dest, expected):  # pragma: no cover (symlinks)
    tmpdir.join('exists').ensure()
    symlink = tmpdir.join('symlink')
    symlink.mksymlinkto(tmpdir.join(dest))

# Path: pre_commit_hooks/check_symlinks.py
# def main(argv: Sequence[str] | None = None) -> int:
#     parser = argparse.ArgumentParser(description='Checks for broken symlinks.')
#     parser.add_argument('filenames', nargs='*', help='Filenames to check')
#     args = parser.parse_args(argv)
# 
#     retv = 0
# 
#     for filename in args.filenames:
#         if (
#                 os.path.islink(filename) and
#                 not os.path.exists(filename)
#         ):  # pragma: no cover (symlink support required)
#             print(f'{filename}: Broken symlink')
#             retv = 1
# 
#     return retv


# Path: tests/check_symlinks_test.py
import os
import pytest
from pre_commit_hooks.check_symlinks import main

from __future__ import annotations





xfail_symlink = pytest.mark.xfail(os.name == 'nt', reason='No symlink support')


@xfail_symlink
@pytest.mark.parametrize(
    ('dest', 'expected'), (('exists', 0), ('does-not-exist', 1)),
)
def test_main(tmpdir, dest, expected):  # pragma: no cover (symlinks)
    tmpdir.join('exists').ensure()
    symlink = tmpdir.join('symlink')
    symlink.mksymlinkto(tmpdir.join(dest))

    assert main((str(symlink),)) == expected