1
0

boilerplate.t 1.6 KB

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