Almost-minimal filesystem based blog.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
1.9 KiB

17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
  1. #!/usr/bin/perl
  2. =pod
  3. =head1 NAME
  4. test.pl - a set of basic tests for Display.pm
  5. =head1 SYNOPSIS
  6. Given a working installation and configuration file:
  7. ./test.pl
  8. ./test.pl -v # to dump config values, etc.
  9. =cut
  10. use strict;
  11. use warnings;
  12. use lib 'lib';
  13. use lib 'wala';
  14. use Test::Simple tests => 8;
  15. use Display;
  16. sub section;
  17. # cheap options:
  18. my $VERBOSE;
  19. for (@ARGV) {
  20. $VERBOSE = 1 if m/-v|--verbose/;
  21. }
  22. my $testlines = <<LINES;
  23. <textile>h1. Hello
  24. Some stuff.
  25. </textile>
  26. <freeverse>
  27. Dogs
  28. frolic in
  29. moonlight.
  30. </freeverse>
  31. <list>
  32. one
  33. two
  34. </list>
  35. LINES
  36. my $expectedlines = <<LINES;
  37. <h3>Hello</h3>
  38. <p>Some stuff.</p>
  39. <p>Dogs<br />
  40. frolic in</p>
  41. <p>moonlight.</p>
  42. <ul>
  43. <li>one</li>
  44. <li>two</li>
  45. </ul>
  46. LINES
  47. # Tests
  48. section 'configuration';
  49. our (%DISPLAY_CONF, %WalaConf);
  50. ok (do "conf.pl", "ran conf file");
  51. ok (defined %WalaConf, '%WalaConf defined');
  52. hash_print(%WalaConf) if $VERBOSE;
  53. ok (defined %DISPLAY_CONF, '%DISPLAY_CONF defined');
  54. hash_print(%DISPLAY_CONF) if $VERBOSE;
  55. ok (my $d = Display->new(%DISPLAY_CONF), "Got Display object.");
  56. $d->walaconf(%WalaConf);
  57. section 'individual subroutine tests';
  58. ok ($d->recent_month() =~ m/\d{4}\/\d{1,2}/,
  59. 'recent_month returns a month');
  60. section 'markup';
  61. ok ($d->line_parse($testlines, undef) eq $expectedlines,
  62. 'line_parse works');
  63. print "\nline_parse result:\n" .
  64. $d->line_parse($testlines, undef) . "\n" if $VERBOSE;
  65. my $perlcode = "IS <perl>return 'TRUE';</perl>";
  66. $d->eval_perl($perlcode);
  67. ok ($perlcode eq 'IS TRUE', 'eval_perl in line_parse');
  68. section 'handle';
  69. # Utility routines.
  70. sub hash_print {
  71. my %hash = @_;
  72. my $string;
  73. for my $key (sort keys %hash) {
  74. $string .= "\n\t$key: $hash{$key}";
  75. }
  76. print $string . "\n\n";
  77. return;
  78. }
  79. sub pause {
  80. my $time = shift;
  81. #print " pausing $time seconds\n";
  82. sleep $time;
  83. }
  84. sub section {
  85. my $msg = shift;
  86. print "\n-- $msg --\n\n";
  87. }