]> git.deb.at Git - pkg/blosxom.git/blobdiff - t/04_plugin_dir.t
Refactor and fix current test cases.
[pkg/blosxom.git] / t / 04_plugin_dir.t
index c27c35bbedd32a5493ed64d52e58e84d0f8245f9..f176604cd5dc510170c8a23104469a4e904f33ee 100644 (file)
@@ -1,35 +1,67 @@
-# blosxom standard $plugin_dir testing
+#!/usr/bin/perl
 
 use strict;
 
 use strict;
-use Test::More tests => 1;
-use Test::Differences;
+use warnings;
+
+use Test::More qw( no_plan );
+
 use Cwd;
 use Cwd;
+use YAML;
 use IO::File;
 use IO::File;
+use File::Find;
+use File::Copy;
+#use File::Touch;
+use File::Basename;
+use Test::Differences;
+
+my $test = basename($0);
+$test =~ s/^\d+_?//;
+$test =~ s/\.t$//;
 
 
-my $blosxom_root = 'plugin_dir';
-$blosxom_root = "t/$blosxom_root" if -d "t/$blosxom_root";
-$blosxom_root = cwd . "/$blosxom_root";
-die "cannot find root '$blosxom_root'" 
-  unless -d $blosxom_root;
+my $testdir = $test;
+$testdir = "t/$testdir" if -d "t/$testdir";
+$testdir = cwd . "/$testdir";
+die "cannot find root '$testdir'" unless -d $testdir;
 
 
-my $blosxom_config_dir = "$blosxom_root/config";
+my $blosxom_config_dir = "$testdir/config";
 die "cannot find blosxom config dir '$blosxom_config_dir'" unless -d $blosxom_config_dir;
 $ENV{BLOSXOM_CONFIG_DIR} = $blosxom_config_dir;
 
 die "cannot find blosxom config dir '$blosxom_config_dir'" unless -d $blosxom_config_dir;
 $ENV{BLOSXOM_CONFIG_DIR} = $blosxom_config_dir;
 
-my $blosxom_cgi = "$blosxom_root/../../blosxom.cgi";
+my $blosxom_cgi = "$testdir/../../blosxom.cgi";
 die "cannot find blosxom.cgi '$blosxom_cgi'" unless -f $blosxom_cgi;
 die "blosxom.cgi '$blosxom_cgi' is not executable" unless -x $blosxom_cgi;
 
 die "cannot find blosxom.cgi '$blosxom_cgi'" unless -f $blosxom_cgi;
 die "blosxom.cgi '$blosxom_cgi' is not executable" unless -x $blosxom_cgi;
 
-my $fh = IO::File->new("$blosxom_root/expected.html", 'r')
-  or die "cannot open expected output file '$blosxom_root/expected.html': $!";
-my $expected;
-{
-  local $/ = undef;
-  $expected = <$fh>;
-  $fh->close;
-}
+my $spec = YAML::LoadFile ("$testdir/spec.yaml") 
+  or fail("$test - loading spec") and next;
 
 
-my $output = qx($blosxom_cgi);
+touch_files("$testdir/data");
 
 
-eq_or_diff($output, $expected, 'html output ok');
+my %expected = ();
 
 
+for (@{$spec->{tests}}) {
+  my ($args, $output) = @$_;
+
+  unless ($expected{$output}) {
+    my $fh = IO::File->new("$testdir/$output", 'r')
+      or die "cannot open expected output file '$output': $!";
+    {
+      local $/ = undef;
+      $expected{$output} = <$fh>;
+    }
+    $fh->close;
+  }
+
+  my $got = qx($blosxom_cgi $args);
+
+  eq_or_diff($got, $expected{$output}, "$test - got expected output for args [$args]", { style => 'Unified' });
+}
+
+sub touch_files {
+  find( sub {
+    if (/^(.*)\.(\d+)$/) {
+      copy($_, $1);
+      `touch -t $2 $1`;
+    }
+  },
+  shift );
+}