1
0

boilerplate.t 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!perl -T
  2. # vi: set tabstop=4 expandtab shiftwidth=4:
  3. use strict;
  4. use warnings;
  5. use Test::More tests => 11;
  6. sub not_in_file_ok {
  7. my ($filename, %regex) = @_;
  8. open( my $fh, '<', $filename )
  9. or die "couldn't open $filename for reading: $!";
  10. my %violated;
  11. while (my $line = <$fh>) {
  12. while (my ($desc, $regex) = each %regex) {
  13. if ($line =~ $regex) {
  14. push @{$violated{$desc}||=[]}, $.;
  15. }
  16. }
  17. }
  18. if (%violated) {
  19. fail("$filename contains boilerplate text");
  20. diag "$_ appears on lines @{$violated{$_}}" for keys %violated;
  21. } else {
  22. pass("$filename contains no boilerplate text");
  23. }
  24. }
  25. sub module_boilerplate_ok {
  26. my ($module) = @_;
  27. not_in_file_ok($module =>
  28. 'the great new $MODULENAME' => qr/ - The great new /,
  29. 'boilerplate description' => qr/Quick summary of what the module/,
  30. 'stub function definition' => qr/function[12]/,
  31. );
  32. }
  33. TODO: {
  34. #local $TODO = "Need to replace the boilerplate text";
  35. not_in_file_ok('README.md' =>
  36. "The README is used..." => qr/The README is used/,
  37. "'version information here'" => qr/to provide version information/,
  38. );
  39. not_in_file_ok(Changes =>
  40. "placeholder date/time" => qr(Date/time)
  41. );
  42. module_boilerplate_ok('lib/CMS.pm');
  43. module_boilerplate_ok('lib/CMS/Config.pm');
  44. module_boilerplate_ok('lib/CMS/Daemon.pm');
  45. module_boilerplate_ok('lib/CMS/FCGI.pm');
  46. module_boilerplate_ok('lib/CMS/FileHelper.pm');
  47. module_boilerplate_ok('lib/CMS/Handler.pm');
  48. module_boilerplate_ok('lib/CMS/Session.pm');
  49. module_boilerplate_ok('lib/CMS/Sitemap.pm');
  50. module_boilerplate_ok('lib/CMS/Trace.pm');
  51. }