~ubuntu-branches/ubuntu/maverick/libmodule-starter-plugin-cgiapp-perl/maverick

« back to all changes in this revision

Viewing changes to t/module-build.t

  • Committer: Bazaar Package Importer
  • Author(s): Jaldhar H. Vyas
  • Date: 2008-09-18 22:36:44 UTC
  • Revision ID: james.westby@ubuntu.com-20080918223644-ali0eh6eno0tw5ta
Tags: upstream-0.05
ImportĀ upstreamĀ versionĀ 0.05

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!perl -T
 
2
#
 
3
# $Id$
 
4
#
 
5
use warnings;
 
6
use strict;
 
7
use Cwd qw(cwd);
 
8
use English qw( -no_match_vars );
 
9
use File::Find qw();
 
10
use File::Path qw( rmtree );
 
11
use Test::More;
 
12
 
 
13
$ENV{PATH} = undef;
 
14
my $dir  = untaint_path( cwd . '/t',       '$dir' );
 
15
my $perl = untaint_path( $EXECUTABLE_NAME, '$perl' );
 
16
 
 
17
qx{ MODULE_STARTER_DIR=$dir $perl ./script/cgiapp-starter --module=Foo --author="Jaldhar H. Vyas"  --email=jaldhar\@braincells.com --dir="$dir/Foo" --mb };
 
18
 
 
19
my @expected_files = (
 
20
    'Foo/lib/Foo.pm',       'Foo/lib/Foo/templates/runmode1.html',
 
21
    'Foo/t/pod-coverage.t', 'Foo/t/pod.t',
 
22
    'Foo/t/test-app.t',     'Foo/t/01-load.t',
 
23
    'Foo/t/perl-critic.t',  'Foo/t/boilerplate.t',
 
24
    'Foo/t/00-signature.t', 'Foo/t/perlcriticrc',
 
25
    'Foo/Build.PL',         'Foo/Changes',
 
26
    'Foo/README',           'Foo/MANIFEST.SKIP',
 
27
    'Foo/MANIFEST',         'Foo/server.pl',
 
28
);
 
29
 
 
30
my %got_files;
 
31
foreach my $file (@expected_files) {
 
32
    $got_files{$file} = -1;
 
33
}
 
34
 
 
35
File::Find::find(
 
36
    {   untaint => 1,
 
37
        wanted  => sub {
 
38
            if ( -f $File::Find::name ) {
 
39
                my $name = $File::Find::name;
 
40
                $name =~ s{^$dir/}{}msx;
 
41
                $got_files{$name} = grep { $_ eq $name } @expected_files;
 
42
            }
 
43
            return;
 
44
            }
 
45
    },
 
46
    "$dir/Foo"
 
47
);
 
48
 
 
49
plan tests => ( scalar keys %got_files ) * 2;
 
50
 
 
51
foreach my $file ( keys %got_files ) {
 
52
    ok( $got_files{$file} > -1, "Missing file $file" );
 
53
}
 
54
 
 
55
foreach my $file ( keys %got_files ) {
 
56
    ok( $got_files{$file}, "Extra file $file" );
 
57
}
 
58
 
 
59
sub untaint_path {
 
60
    my ( $path, $description ) = @_;
 
61
    if ( !( $path =~ m{ (\A[-+@\w./]+\z) }msx ) ) {
 
62
        die "$description is tainted.\n";
 
63
    }
 
64
    return $1;
 
65
}
 
66
 
 
67
END {
 
68
    if ( -d "$dir/Foo" ) {
 
69
        rmtree "$dir/Foo" || die "$OS_ERROR\n";
 
70
    }
 
71
}