2022-01-16 08:24:05 +08:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2017-10-07 14:32:11 +08:00
|
|
|
from pre_commit_hooks.check_vcs_permalinks import main
|
|
|
|
|
|
|
|
|
|
|
|
def test_trivial(tmpdir):
|
|
|
|
f = tmpdir.join('f.txt').ensure()
|
2020-05-21 00:07:45 +08:00
|
|
|
assert not main((str(f),))
|
2017-10-07 14:32:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
def test_passing(tmpdir):
|
|
|
|
f = tmpdir.join('f.txt')
|
|
|
|
f.write_binary(
|
|
|
|
# permalinks are ok
|
|
|
|
b'https://github.com/asottile/test/blob/649e6/foo%20bar#L1\n'
|
2021-04-07 02:07:08 +08:00
|
|
|
# tags are ok
|
|
|
|
b'https://github.com/asottile/test/blob/1.0.0/foo%20bar#L1\n'
|
2017-10-07 14:32:11 +08:00
|
|
|
# links to files but not line numbers are ok
|
2018-06-05 01:10:14 +08:00
|
|
|
b'https://github.com/asottile/test/blob/master/foo%20bar\n'
|
|
|
|
# regression test for overly-greedy regex
|
|
|
|
b'https://github.com/ yes / no ? /blob/master/foo#L1\n',
|
2017-10-07 14:32:11 +08:00
|
|
|
)
|
2020-05-21 00:07:45 +08:00
|
|
|
assert not main((str(f),))
|
2017-10-07 14:32:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
def test_failing(tmpdir, capsys):
|
|
|
|
with tmpdir.as_cwd():
|
|
|
|
tmpdir.join('f.txt').write_binary(
|
2020-11-17 01:33:47 +08:00
|
|
|
b'https://github.com/asottile/test/blob/master/foo#L1\n'
|
2021-04-07 02:07:08 +08:00
|
|
|
b'https://example.com/asottile/test/blob/master/foo#L1\n'
|
|
|
|
b'https://example.com/asottile/test/blob/main/foo#L1\n',
|
2017-10-07 14:32:11 +08:00
|
|
|
)
|
|
|
|
|
2020-11-17 01:33:47 +08:00
|
|
|
assert main(('f.txt', '--additional-github-domain', 'example.com'))
|
2017-10-07 14:32:11 +08:00
|
|
|
out, _ = capsys.readouterr()
|
|
|
|
assert out == (
|
|
|
|
'f.txt:1:https://github.com/asottile/test/blob/master/foo#L1\n'
|
2020-11-17 01:33:47 +08:00
|
|
|
'f.txt:2:https://example.com/asottile/test/blob/master/foo#L1\n'
|
2021-04-07 02:07:08 +08:00
|
|
|
'f.txt:3:https://example.com/asottile/test/blob/main/foo#L1\n'
|
2017-10-07 14:32:11 +08:00
|
|
|
'\n'
|
|
|
|
'Non-permanent github link detected.\n'
|
|
|
|
'On any page on github press [y] to load a permalink.\n'
|
|
|
|
)
|