mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-14 13:00:10 -06:00
Merge pull request #2706 from pre-commit/perl-tests
test perl language directly
This commit is contained in:
7
testing/resources/perl_hooks_repo/.gitignore
vendored
7
testing/resources/perl_hooks_repo/.gitignore
vendored
@@ -1,7 +0,0 @@
|
||||
/MYMETA.json
|
||||
/MYMETA.yml
|
||||
/Makefile
|
||||
/PreCommitHello-*.tar.*
|
||||
/PreCommitHello-*/
|
||||
/blib/
|
||||
/pm_to_blib
|
||||
@@ -1,5 +0,0 @@
|
||||
- id: perl-hook
|
||||
name: perl example hook
|
||||
entry: pre-commit-perl-hello
|
||||
language: perl
|
||||
files: ''
|
||||
@@ -1,4 +0,0 @@
|
||||
MANIFEST
|
||||
Makefile.PL
|
||||
bin/pre-commit-perl-hello
|
||||
lib/PreCommitHello.pm
|
||||
@@ -1,10 +0,0 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use ExtUtils::MakeMaker;
|
||||
|
||||
WriteMakefile(
|
||||
NAME => "PreCommitHello",
|
||||
VERSION_FROM => "lib/PreCommitHello.pm",
|
||||
EXE_FILES => [qw(bin/pre-commit-perl-hello)],
|
||||
);
|
||||
@@ -1,7 +0,0 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use PreCommitHello;
|
||||
|
||||
PreCommitHello::hello();
|
||||
@@ -1,12 +0,0 @@
|
||||
package PreCommitHello;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
our $VERSION = "0.1.0";
|
||||
|
||||
sub hello {
|
||||
print "Hello from perl-commit Perl!\n";
|
||||
}
|
||||
|
||||
1;
|
||||
69
tests/languages/perl_test.py
Normal file
69
tests/languages/perl_test.py
Normal file
@@ -0,0 +1,69 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pre_commit.languages import perl
|
||||
from pre_commit.store import _make_local_repo
|
||||
from pre_commit.util import make_executable
|
||||
from testing.language_helpers import run_language
|
||||
|
||||
|
||||
def test_perl_install(tmp_path):
|
||||
makefile_pl = '''\
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use ExtUtils::MakeMaker;
|
||||
|
||||
WriteMakefile(
|
||||
NAME => "PreCommitHello",
|
||||
VERSION_FROM => "lib/PreCommitHello.pm",
|
||||
EXE_FILES => [qw(bin/pre-commit-perl-hello)],
|
||||
);
|
||||
'''
|
||||
bin_perl_hello = '''\
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use PreCommitHello;
|
||||
|
||||
PreCommitHello::hello();
|
||||
'''
|
||||
lib_hello_pm = '''\
|
||||
package PreCommitHello;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
our $VERSION = "0.1.0";
|
||||
|
||||
sub hello {
|
||||
print "Hello from perl-commit Perl!\n";
|
||||
}
|
||||
|
||||
1;
|
||||
'''
|
||||
tmp_path.joinpath('Makefile.PL').write_text(makefile_pl)
|
||||
bin_dir = tmp_path.joinpath('bin')
|
||||
bin_dir.mkdir()
|
||||
exe = bin_dir.joinpath('pre-commit-perl-hello')
|
||||
exe.write_text(bin_perl_hello)
|
||||
make_executable(exe)
|
||||
lib_dir = tmp_path.joinpath('lib')
|
||||
lib_dir.mkdir()
|
||||
lib_dir.joinpath('PreCommitHello.pm').write_text(lib_hello_pm)
|
||||
|
||||
ret = run_language(tmp_path, perl, 'pre-commit-perl-hello')
|
||||
assert ret == (0, b'Hello from perl-commit Perl!\n')
|
||||
|
||||
|
||||
def test_perl_additional_dependencies(tmp_path):
|
||||
_make_local_repo(str(tmp_path))
|
||||
|
||||
ret, out = run_language(
|
||||
tmp_path,
|
||||
perl,
|
||||
'perltidy --version',
|
||||
deps=('SHANCOCK/Perl-Tidy-20211029.tar.gz',),
|
||||
)
|
||||
assert ret == 0
|
||||
assert out.startswith(b'This is perltidy, v20211029')
|
||||
@@ -981,30 +981,6 @@ def test_manifest_hooks(tempdir_factory, store):
|
||||
)
|
||||
|
||||
|
||||
def test_perl_hook(tempdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tempdir_factory, store, 'perl_hooks_repo',
|
||||
'perl-hook', [], b'Hello from perl-commit Perl!\n',
|
||||
)
|
||||
|
||||
|
||||
def test_local_perl_additional_dependencies(store):
|
||||
config = {
|
||||
'repo': 'local',
|
||||
'hooks': [{
|
||||
'id': 'hello',
|
||||
'name': 'hello',
|
||||
'entry': 'perltidy --version',
|
||||
'language': 'perl',
|
||||
'additional_dependencies': ['SHANCOCK/Perl-Tidy-20211029.tar.gz'],
|
||||
}],
|
||||
}
|
||||
hook = _get_hook(config, store, 'hello')
|
||||
ret, out = _hook_run(hook, (), color=False)
|
||||
assert ret == 0
|
||||
assert _norm_out(out).startswith(b'This is perltidy, v20211029')
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'repo',
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user