.tests-covering-map.pl 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/env perl
  2. use 5.040;
  3. use warnings FATAL => 'all';
  4. use re '/aa';
  5. =head1 NAME
  6. .tests-covering-map.pl - which tests reach the files that no test loads, for
  7. tests-covering
  8. =head1 DESCRIPTION
  9. git-hooks/pre-commit asks tests-covering which tests a commit can break.
  10. tests-covering follows the Perl that each test loads, and asks this map about
  11. every other file in the diff. See "THE MAP" in L<Perl::Tests::Covering>.
  12. The map answers C<q{}>, which is C<NO_TESTS>, for the files of a distribution
  13. that C<prove -l t/> never reads:
  14. =over
  15. =item Documentation
  16. Markdown, POD in F<.pod> files outside F<lib/>, F<Changes>, F<LICENSE> and
  17. F<README>.
  18. =item The build and the release
  19. F<dist.ini>, F<weaver.ini>, F<prereqs.yml> and F<prereqs.json>, F<MANIFEST.SKIP>
  20. and F<cpanfile>. C<dzil> reads them, and C<dzil test> checks what they build.
  21. =item The tools and the hooks
  22. The C<perltidy> and C<perlcritic> configuration and the files that it reads,
  23. F<.mailmap>, F<.gitignore>, F<.gitattributes>, this map, F<git-hooks/> and
  24. F<.github/>.
  25. =item The author tests
  26. F<xt/>, which the hooks do not run.
  27. =item The programs that no test runs
  28. F<call.pl>, the shell scripts in F<bin/> and F<service/>, and the unit template
  29. in F<service/>.
  30. =back
  31. Anything else, it leaves unexplained, and the hook then runs every test. A
  32. file that a test reads without loading it, such as a template or a fixture,
  33. wants a rule here that names the tests that read it.
  34. =cut
  35. # Read by the tools, by dzil or by people, and by no test.
  36. my %NO_TESTS = map { $_ => 1 } qw{
  37. Changes LICENSE README README.md
  38. dist.ini weaver.ini prereqs.yml prereqs.json MANIFEST.SKIP cpanfile
  39. .perltidyrc .perlcriticrc .perlcriticrc.compat .pod_stopwords .preferred_modules.ini .preferred_binaries.ini
  40. .mailmap .gitignore .gitattributes .tests-covering-map.pl
  41. call.pl bin/build_service bin/scan_log_for_warnings.sh
  42. };
  43. return sub {
  44. my ($path) = @_;
  45. return q{} if $NO_TESTS{$path};
  46. return q{} if $path =~ m{\A(?:git-hooks|[.]github|xt)/}sx;
  47. return q{} if $path =~ m{[.]md\z}sx;
  48. return q{} if $path =~ m{[.]pod\z}sx && $path !~ m{\Alib/}sx;
  49. # The service's shell script and unit template, which no test runs.
  50. return q{} if $path =~ m{\Aservice/}sx;
  51. return;
  52. };