blob: e2c2c78f1fa69556b5dec9c93f59e27a674cf655 [file] [log] [blame]
Anthony Sottile8f615292022-01-15 19:24:05 -05001from __future__ import annotations
2
Anthony Sottileda882282016-01-14 19:03:11 -08003import os
4
Benjamin Chess896c0cf2016-01-14 15:25:46 -08005import pytest
6
Anthony Sottile030bfac2019-01-31 19:19:10 -08007from pre_commit_hooks.check_symlinks import main
Benjamin Chess896c0cf2016-01-14 15:25:46 -08008
9
Anthony Sottilec5b7c352017-09-08 08:27:04 -070010xfail_symlink = pytest.mark.xfail(os.name == 'nt', reason='No symlink support')
11
12
13@xfail_symlink
Anthony Sottilee9aea742017-07-15 12:56:51 -070014@pytest.mark.parametrize(
Anthony Sottilec5b7c352017-09-08 08:27:04 -070015 ('dest', 'expected'), (('exists', 0), ('does-not-exist', 1)),
Anthony Sottilee9aea742017-07-15 12:56:51 -070016)
Anthony Sottile030bfac2019-01-31 19:19:10 -080017def test_main(tmpdir, dest, expected): # pragma: no cover (symlinks)
Anthony Sottilec5b7c352017-09-08 08:27:04 -070018 tmpdir.join('exists').ensure()
19 symlink = tmpdir.join('symlink')
20 symlink.mksymlinkto(tmpdir.join(dest))
Max Rozentsveygf35bfed2020-05-20 12:07:45 -040021 assert main((str(symlink),)) == expected
Anthony Sottilec5b7c352017-09-08 08:27:04 -070022
23
Anthony Sottile030bfac2019-01-31 19:19:10 -080024def test_main_normal_file(tmpdir):
Max Rozentsveygf35bfed2020-05-20 12:07:45 -040025 assert main((str(tmpdir.join('f').ensure()),)) == 0