rejiggered things to deal with changing timestamps
[matthijs/upstream/blosxom.git] / t / driver.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More qw( no_plan );
7
8 use File::Copy;
9 use File::Compare;
10 use File::Find;
11 use Cwd;
12 use YAML;
13
14
15 my $orig_cwd = cwd();
16
17 opendir(my $dh, $orig_cwd) or die("Opendir failed: $!");
18
19 my @tests = grep { /^t-/ } readdir $dh;
20
21 for my $testdir (@tests) {
22   my (undef, $test) = split /-/, $testdir, 2;
23   
24   chdir $testdir;
25   my $cwd = cwd();
26
27   my $spec = YAML::LoadFile ("spec.yaml");
28
29   if (! $spec) {
30     fail ("$test - loading spec");
31     next;
32   }
33
34   my $success = 1;
35
36   copy("../../blosxom.cgi", ".") or die("Copy failed: $!");
37   chmod(0777, "blosxom.cgi");
38
39   system("perl -pi -e 's{/Library/WebServer/Documents/blosxom}{$cwd/data}' blosxom.cgi") == 0
40       or die "$!";
41
42   touch_files ();
43
44   for (@{$spec->{tests}}) {
45     my ($args, $output) = @$_;
46
47     system("./blosxom.cgi $args > ${output}.got") == 0
48         or die "$!";
49
50     if (ok(compare("${output}.got", $output) == 0, 
51            "$test - Got expected output for args [$args]")) {
52       unlink("${output}.got");
53     } else {
54       $success = 0;
55     }
56   }
57
58   if ($success) {
59     unlink("blosxom.cgi");
60   }
61
62   chdir $orig_cwd;
63 }
64
65
66
67 sub touch_files {
68   find( sub {
69     if (/^(.*)\.(\d+)$/) {
70       copy($_, $1);
71       `touch -t $2 $1`;
72     }
73   },
74         "./data");
75 }