]> git.deb.at Git - pkg/blosxom.git/blob - t/driver
Add $path_info_full variable to blosxom.cgi.
[pkg/blosxom.git] / t / driver
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More qw( no_plan );
7
8 use Cwd;
9 use YAML;
10 use IO::File;
11 use File::Find;
12 use File::Copy;
13 #use File::Touch;
14 use File::Basename;
15 use Test::Differences;
16
17 my $test = basename($0);
18 $test =~ s/^\d+_?//;
19 $test =~ s/\.t$//;
20
21 my $testdir = $test;
22 $testdir = "t/$testdir" if -d "t/$testdir";
23 $testdir = cwd . "/$testdir";
24 die "cannot find root '$testdir'" unless -d $testdir;
25
26 my $blosxom_config_dir = "$testdir/config";
27 die "cannot find blosxom config dir '$blosxom_config_dir'" unless -d $blosxom_config_dir;
28 $ENV{BLOSXOM_CONFIG_DIR} = $blosxom_config_dir;
29 $ENV{TZ} = 'UTC';
30
31 my $blosxom_cgi = "$testdir/../../blosxom.cgi";
32 die "cannot find blosxom.cgi '$blosxom_cgi'" unless -f $blosxom_cgi;
33 die "blosxom.cgi '$blosxom_cgi' is not executable" unless -x $blosxom_cgi;
34
35 my $spec = YAML::LoadFile ("$testdir/spec.yaml") 
36   or die("$test - could not load spec");
37
38 touch_files("$testdir/data");
39
40 # Eval blosxom.conf
41 my ($static_dir, $static_password, @static_flavours);
42 if (my $fh = IO::File->new("$blosxom_config_dir/blosxom.conf", 'r')) {
43   no strict;
44   local $/ = undef;
45   eval <$fh>;
46 }
47
48 # Static mode
49 if ($static_password) {
50   eval {
51     require File::DirCompare;
52     require File::Remove;
53   };
54   SKIP: {
55     skip "Static tests require additional modules: $@", 1 if $@;
56     my $expected = $spec->{expected};
57     skip "Static tests require 'expected' directory", 1 unless $expected;
58     $expected = "$blosxom_config_dir/../$expected" unless $expected =~ m!^/!;
59     skip "Static tests 'expected' directory is missing", 1 unless -d $expected;
60     skip "Static tests 'static_dir' directory is missing", 1 unless -d $static_dir;
61
62     File::Remove::remove(\1, "$static_dir/*");
63
64     my $errors = qx($blosxom_cgi -quiet=1 -password=$static_password);
65     is($errors, '', 'no errors reported from static run');
66     File::DirCompare->compare($static_dir, "$blosxom_config_dir/../" . $spec->{expected}, sub {
67       my ($a, $b) = @_;
68       my ($a_short, $b_short) = ($a, $b);
69       $a_short =~ s!^.*\.\./!! if $a_short;
70       $b_short =~ s!^.*\.\./!! if $b_short;
71       if (! $b) {
72         fail("$a_short has no corresponding file");
73       } elsif (! $a) {
74         fail("$b_short has no corresponding file");
75       } else {
76         my ($got, $expected) = ('', '');
77         my $fh = IO::File->new($a, 'r') 
78           or die "cannot open static output file '$a': $!";
79         {
80           local $/ = undef;
81           $got = <$fh>;
82           $fh->close;
83         }
84         $fh = IO::File->new($b, 'r') 
85           or die "cannot open static output file '$b': $!";
86         {
87           local $/ = undef;
88           $expected = <$fh>;
89           $fh->close;
90         }
91         eq_or_diff($got, $expected, "file $a_short and $b_short match", { style => 'Unified' });
92       }
93     }, { ignore_cmp => 1 });
94   }
95 }
96
97 # Dynamic mode
98 else {
99   my %expected = ();
100   for (@{$spec->{tests}}) {
101     my ($args, $output) = @$_;
102
103     unless ($expected{$output}) {
104       my $fh = IO::File->new("$testdir/$output", 'r')
105         or die "cannot open expected output file '$output': $!";
106       {
107         local $/ = undef;
108         $expected{$output} = <$fh>;
109       }
110       $fh->close;
111     }
112
113     my $got = qx($blosxom_cgi $args);
114
115     eq_or_diff($got, $expected{$output}, "$test - got expected output for args [$args]", { style => 'Unified' });
116   }
117 }
118
119 sub touch_files {
120   find( sub {
121     if (/^(.*)\.(\d+)$/) {
122       copy($_, $1);
123       `touch -t $2 $1`;
124     }
125   },
126   shift );
127 }