From 821c5f870b74ef33ba258722c6867d345aa84e83 Mon Sep 17 00:00:00 2001 From: Gavin Carr Date: Sun, 7 Oct 2007 23:51:28 +0000 Subject: [PATCH] Add Setup script for test script symlinks, and README; remove test scripts. --- t/02_smoketest.t | 67 ----------------------------- t/03_permalinks.t | 67 ----------------------------- t/04_plugin_dir.t | 67 ----------------------------- t/04_plugin_list.t | 67 ----------------------------- t/README | 81 ++++++++++++++++++++++++++++++++++++ t/Setup | 26 ++++++++++++ t/{01_templates.t => driver} | 0 t/driver_tests | 5 +++ 8 files changed, 112 insertions(+), 268 deletions(-) delete mode 100644 t/02_smoketest.t delete mode 100644 t/03_permalinks.t delete mode 100644 t/04_plugin_dir.t delete mode 100644 t/04_plugin_list.t create mode 100644 t/README create mode 100755 t/Setup rename t/{01_templates.t => driver} (100%) create mode 100644 t/driver_tests diff --git a/t/02_smoketest.t b/t/02_smoketest.t deleted file mode 100644 index f176604..0000000 --- a/t/02_smoketest.t +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/perl - -use strict; -use warnings; - -use Test::More qw( no_plan ); - -use Cwd; -use YAML; -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 $testdir = $test; -$testdir = "t/$testdir" if -d "t/$testdir"; -$testdir = cwd . "/$testdir"; -die "cannot find root '$testdir'" unless -d $testdir; - -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; - -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; - -my $spec = YAML::LoadFile ("$testdir/spec.yaml") - or fail("$test - loading spec") and next; - -touch_files("$testdir/data"); - -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 ); -} diff --git a/t/03_permalinks.t b/t/03_permalinks.t deleted file mode 100644 index f176604..0000000 --- a/t/03_permalinks.t +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/perl - -use strict; -use warnings; - -use Test::More qw( no_plan ); - -use Cwd; -use YAML; -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 $testdir = $test; -$testdir = "t/$testdir" if -d "t/$testdir"; -$testdir = cwd . "/$testdir"; -die "cannot find root '$testdir'" unless -d $testdir; - -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; - -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; - -my $spec = YAML::LoadFile ("$testdir/spec.yaml") - or fail("$test - loading spec") and next; - -touch_files("$testdir/data"); - -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 ); -} diff --git a/t/04_plugin_dir.t b/t/04_plugin_dir.t deleted file mode 100644 index f176604..0000000 --- a/t/04_plugin_dir.t +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/perl - -use strict; -use warnings; - -use Test::More qw( no_plan ); - -use Cwd; -use YAML; -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 $testdir = $test; -$testdir = "t/$testdir" if -d "t/$testdir"; -$testdir = cwd . "/$testdir"; -die "cannot find root '$testdir'" unless -d $testdir; - -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; - -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; - -my $spec = YAML::LoadFile ("$testdir/spec.yaml") - or fail("$test - loading spec") and next; - -touch_files("$testdir/data"); - -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 ); -} diff --git a/t/04_plugin_list.t b/t/04_plugin_list.t deleted file mode 100644 index f176604..0000000 --- a/t/04_plugin_list.t +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/perl - -use strict; -use warnings; - -use Test::More qw( no_plan ); - -use Cwd; -use YAML; -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 $testdir = $test; -$testdir = "t/$testdir" if -d "t/$testdir"; -$testdir = cwd . "/$testdir"; -die "cannot find root '$testdir'" unless -d $testdir; - -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; - -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; - -my $spec = YAML::LoadFile ("$testdir/spec.yaml") - or fail("$test - loading spec") and next; - -touch_files("$testdir/data"); - -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 ); -} diff --git a/t/README b/t/README new file mode 100644 index 0000000..c935d16 --- /dev/null +++ b/t/README @@ -0,0 +1,81 @@ +Running Tests +============= + + perl ./Setup + prove *.t + + + +Test Layout +=========== + +To add a new test, you want to add two things - a test script (which +is typically just a symlink to the main 'driver' script), and a test +directory. If you just want a symlink test script, then add your +test script name to 'driver_tests', and rerun Setup. To add a new +test directory, you're probably best just to copy one of the +existing ones - 'templates' is a good choice: + + cp -rp templates newtest + +Test directory layout is as follows, using 'templates' as an example: + + templates + |-- config + | `-- blosxom.conf + |-- data + | |-- 1.txt + | |-- 1.txt.200607192254 + | |-- content_type.html + | |-- date.html + | |-- foot.html + | |-- head.html + | `-- story.html + |-- expected.html + `-- spec.yaml + +The 'config' directory contains the config files for this blosxom +instance, which is minimally a 'blosxom.conf' file with the $data_dir +variable pointing to the 'data' directory. Customising this is +optional. + +The 'data directory' is the set of stories or posts you want to use +for your test, and any flavour files you want. Stories may optionally be +suffixed with a numeric timestamp (format YYYYMMDDHHMI) like the +'1.txt.200607192254' entry above, which is used to set the modify time +of the story explicitly (since CVS does not store mtimes). Providing +flavour files is recommended so that your tests don't break if the +default flavours change. + +At the top level of the test directory are a set of one or more +expected output files, and the spec.yaml files which controls the set +of tests that are run. For templates, the spec.yaml looks like this: + + tests: + - + - "" + - expected.html + +This lists the set of tests to be run (in this case just a single test). +Each test requires a list of two arguments - the arguments to path to +blosxom.cgi (in this case none, an empty string), and a file containing +the expected output. So this test will execute blosxom.cgi with no +arguments, and compare the output produced against that contained in +the 'expected.html' file. + +A longer spec.yaml example is: + + tests: + - + - "" + - expected.html + - + - path=/foo + - expected.html + - + - path=/foo/bar.html + - expected.bar + +This defines three tests, one with no arguments, one with a path of +/foo, and a third with a path of /foo/bar.html. + diff --git a/t/Setup b/t/Setup new file mode 100755 index 0000000..8334ff9 --- /dev/null +++ b/t/Setup @@ -0,0 +1,26 @@ +#!/usr/bin/env perl +# +# Script to setup test script symlinks, since CVS can't store them +# + +use strict; +use IO::File; + +my $DRIVER = 'driver'; +my $TESTS = 'driver_tests'; +die "cannot find driver file '$DRIVER'" unless -f $DRIVER; +die "cannot find tests file '$TESTS'" unless -f $TESTS; + +my @tests = (); + +my $th = IO::File->new($TESTS, 'r') + or die "cannot open tests file '$TESTS': $!"; +@tests = <$th>; +close $th; + +for my $t (@tests) { + chomp $t; + print "symlink $DRIVER $t\n"; + eval { symlink $DRIVER, $t } or die "symlink $DRIVER, $t failed: $!"; +} + diff --git a/t/01_templates.t b/t/driver similarity index 100% rename from t/01_templates.t rename to t/driver diff --git a/t/driver_tests b/t/driver_tests new file mode 100644 index 0000000..a053c50 --- /dev/null +++ b/t/driver_tests @@ -0,0 +1,5 @@ +01_templates.t +02_smoketest.t +03_permalinks.t +04_plugin_dir.t +04_plugin_list.t -- 2.30.2