#!/usr/bin/perl
|
|
|
|
=pod
|
|
|
|
=head1 NAME
|
|
|
|
test.pl - a set of basic tests for Display.pm
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
Given a working installation and configuration file:
|
|
|
|
./test.pl
|
|
./test.pl -v # to dump config values, etc.
|
|
|
|
=head1 SEE ALSO
|
|
|
|
=cut
|
|
|
|
use strict;
|
|
use warnings;
|
|
use lib 'lib';
|
|
use lib 'wala';
|
|
|
|
use Test::Simple tests => 6;
|
|
use Display qw(%WalaConf %DISPLAY_CONF &handle);
|
|
|
|
sub section;
|
|
|
|
# cheap options:
|
|
my $VERBOSE;
|
|
for (@ARGV) {
|
|
$VERBOSE = 1 if m/-v|--verbose/;
|
|
}
|
|
|
|
|
|
my $testlines = <<LINES;
|
|
<textile>h1. Hello
|
|
|
|
Some stuff.
|
|
</textile>
|
|
|
|
<freeverse>
|
|
Dogs
|
|
frolic in
|
|
|
|
moonlight.
|
|
</freeverse>
|
|
|
|
<list>
|
|
one
|
|
|
|
two
|
|
</list>
|
|
LINES
|
|
|
|
my $expectedlines = <<LINES;
|
|
<h3>Hello</h3>
|
|
|
|
<p>Some stuff.</p>
|
|
|
|
<p>Dogs<br />
|
|
frolic in</p>
|
|
|
|
<p>moonlight.</p>
|
|
|
|
<ul>
|
|
<li>one</li>
|
|
|
|
<li>two</li>
|
|
</ul>
|
|
LINES
|
|
|
|
# Tests
|
|
|
|
section 'configuration';
|
|
|
|
ok (do("conf.pl"), "ran conf file");
|
|
|
|
ok (defined %WalaConf, '%WalaConf defined');
|
|
hash_print(%WalaConf) if $VERBOSE;
|
|
|
|
ok (defined %DISPLAY_CONF, '%DISPLAY_CONF defined');
|
|
hash_print(%DISPLAY_CONF) if $VERBOSE;
|
|
|
|
section 'individual subroutine tests';
|
|
|
|
ok (Display::recent_month() =~ m/\d{4}\/\d{1,2}/,
|
|
'recent_month returns a month');
|
|
|
|
section 'markup';
|
|
|
|
ok (Display::line_parse($testlines, undef) eq $expectedlines,
|
|
'line_parse works');
|
|
print "\nline_parse result:\n" .
|
|
Display::line_parse($testlines, undef) . "\n" if $VERBOSE;
|
|
|
|
my $perlcode = "IS <perl>return 'TRUE';</perl>";
|
|
Display::eval_perl($perlcode);
|
|
ok ($perlcode eq 'IS TRUE', 'eval_perl in line_parse');
|
|
|
|
section 'handle';
|
|
|
|
# Utility routines.
|
|
|
|
sub hash_print {
|
|
my %hash = @_;
|
|
my $string;
|
|
for my $key (sort keys %hash) {
|
|
$string .= "\n\t$key: $hash{$key}";
|
|
}
|
|
|
|
print $string . "\n\n";
|
|
return;
|
|
}
|
|
|
|
sub pause {
|
|
my $time = shift;
|
|
#print " pausing $time seconds\n";
|
|
sleep $time;
|
|
}
|
|
|
|
sub section {
|
|
my $msg = shift;
|
|
print "\n-- $msg --\n\n";
|
|
}
|