#!/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. =cut use strict; use warnings; use lib 'lib'; use lib 'wala'; use Test::Simple tests => 8; use Display; sub section; # cheap options: my $VERBOSE; for (@ARGV) { $VERBOSE = 1 if m/-v|--verbose/; } my $testlines = <h1. Hello Some stuff. Dogs frolic in moonlight. one two LINES my $expectedlines = <Hello

Some stuff.

Dogs
frolic in

moonlight.

LINES # Tests section 'configuration'; our (%DISPLAY_CONF, %WalaConf); 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; ok (my $d = Display->new(%DISPLAY_CONF), "Got Display object."); $d->walaconf(%WalaConf); section 'individual subroutine tests'; ok ($d->recent_month() =~ m/\d{4}\/\d{1,2}/, 'recent_month returns a month'); section 'markup'; ok ($d->line_parse($testlines, undef) eq $expectedlines, 'line_parse works'); print "\nline_parse result:\n" . $d->line_parse($testlines, undef) . "\n" if $VERBOSE; my $perlcode = "IS return 'TRUE';"; $d->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"; }