7e12204cf666c4be5684da0774360d961545af59
[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 Cwd;
11 use YAML;
12
13
14 my $orig_cwd = cwd();
15
16 opendir(my $dh, $orig_cwd) or die("Opendir failed: $!");
17
18 my @tests = grep { /^t-/ } readdir $dh;
19
20 for my $testdir (@tests) {
21   my (undef, $test) = split /-/, $testdir, 2;
22   
23   chdir $testdir;
24   my $cwd = cwd();
25
26   my $spec = YAML::LoadFile ("spec.yaml");
27
28   if (! $spec) {
29     fail ("$test - loading spec");
30     next;
31   }
32
33   my $success = 1;
34
35   copy("../../blosxom.cgi", ".") or die("Copy failed: $!");
36   chmod(0777, "blosxom.cgi");
37
38   system("perl -pi -e 's{/Library/WebServer/Documents/blosxom}{$cwd/data}' blosxom.cgi") == 0
39       or die "$!";
40
41   for (@{$spec->{tests}}) {
42     my ($args, $output) = @$_;
43
44     system("./blosxom.cgi $args > ${output}.got") == 0
45         or die "$!";
46
47     if (ok(compare("${output}.got", $output) == 0, 
48            "$test - Got expected output for args [$args]")) {
49       unlink("${output}.got");
50     } else {
51       $success = 0;
52     }
53   }
54
55   if ($success) {
56     unlink("blosxom.cgi");
57   }
58
59   chdir $orig_cwd;
60 }
61