6 use Test::More qw( no_plan );
15 use Test::Differences;
17 my $test = basename($0);
22 $testdir = "t/$testdir" if -d "t/$testdir";
23 $testdir = cwd . "/$testdir";
24 die "cannot find root '$testdir'" unless -d $testdir;
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;
31 my $blosxom_cgi = $ENV{BLOSXOM_CGI};
32 unless ($blosxom_cgi && -f $blosxom_cgi) {
33 if (-f "$testdir/../../blosxom.cgi") {
34 $blosxom_cgi = "$testdir/../../blosxom.cgi";
35 warn "ignoring BLOSXOM_CGI setting '$ENV{BLOSXOM_CGI}' - using '$blosxom_cgi' instead"
38 elsif ($blosxom_cgi) {
39 die "cannot find blosxom.cgi '$blosxom_cgi' - check your BLOSXOM_CGI environment variable";
42 die "cannot find blosxom.cgi - please set the BLOSXOM_CGI environment variable";
45 die "blosxom.cgi '$blosxom_cgi' is not executable" unless -x $blosxom_cgi;
47 my $spec = YAML::LoadFile ("$testdir/spec.yaml")
48 or die("$test - could not load spec");
50 touch_files("$testdir/data");
53 my ($static_dir, $static_password, @static_flavours);
54 if (my $fh = IO::File->new("$blosxom_config_dir/blosxom.conf", 'r')) {
61 if ($static_password) {
63 require File::DirCompare;
67 skip "Static tests require additional modules: $@", 1 if $@;
68 my $expected = $spec->{expected};
69 skip "Static tests require 'expected' directory", 1 unless $expected;
70 $expected = "$blosxom_config_dir/../$expected" unless $expected =~ m!^/!;
71 skip "Static tests 'expected' directory is missing", 1 unless -d $expected;
72 skip "Static tests 'static_dir' directory is missing", 1 unless -d $static_dir;
74 File::Remove::remove(\1, "$static_dir/*");
76 my $errors = qx($blosxom_cgi -quiet=1 -password=$static_password);
77 is($errors, '', 'no errors reported from static run');
78 File::DirCompare->compare($static_dir, "$blosxom_config_dir/../" . $spec->{expected}, sub {
80 my ($a_short, $b_short) = ($a, $b);
81 $a_short =~ s!^.*\.\./!! if $a_short;
82 $b_short =~ s!^.*\.\./!! if $b_short;
83 return if $b =~ m! /CVS$ !x;
85 fail("$a_short has no corresponding file");
87 fail("$b_short has no corresponding file");
89 my ($got, $expected) = ('', '');
90 my $fh = IO::File->new($a, 'r')
91 or die "cannot open static output file '$a': $!";
97 $fh = IO::File->new($b, 'r')
98 or die "cannot open static output file '$b': $!";
104 eq_or_diff($got, $expected, "file $a_short and $b_short match", { style => 'Unified' });
106 }, { ignore_cmp => 1 });
108 # Cleanup static output
109 File::Remove::remove(\1, "$static_dir/*") unless $ENV{BLOSXOM_STATIC_NO_CLEANUP};
116 for (@{$spec->{tests}}) {
117 my ($args, $output) = @$_;
119 unless ($expected{$output}) {
120 my $fh = IO::File->new("$testdir/$output", 'r')
121 or die "cannot open expected output file '$output': $!";
124 $expected{$output} = <$fh>;
129 my $got = qx($blosxom_cgi $args);
131 eq_or_diff($got, $expected{$output}, "$test - got expected output for args [$args]", { style => 'Unified' });
137 if (/^(.*)\.(\d+)$/) {