Commit | Line | Data |
8ae46e98 |
1 | package MakeTestApp; |
2 | use strict; |
3 | use warnings; |
4 | |
5 | use Exporter 'import'; |
6 | use Cwd qw(abs_path); |
7 | use File::Spec::Functions qw(updir catdir); |
8 | use File::Basename qw(dirname); |
9 | use File::Path qw(rmtree); |
10 | use File::Copy::Recursive qw(dircopy); |
11 | |
12 | our @EXPORT = qw(make_test_app); |
13 | |
14 | our $root = abs_path(catdir(dirname(__FILE__), (updir) x 2)); |
15 | |
16 | sub make_test_app { |
17 | my $tmp = "$root/t/tmp"; |
18 | rmtree $tmp if -d $tmp; |
19 | mkdir $tmp; |
20 | |
21 | # create a TestApp and copy the test libs into it |
22 | my $testapp = "$tmp/TestApp"; |
23 | mkdir $testapp; |
24 | |
25 | mkdir "$testapp/lib"; |
26 | mkdir "$testapp/script"; |
27 | |
28 | for my $command (qw(CGI FastCGI Server)) { |
29 | my $script = "$testapp/script/testapp_\L$command\E.pl"; |
30 | open my $fh, '>:raw', $script |
31 | or die "can't create $script: $!"; |
32 | print $fh <<"END_CODE"; |
33 | #!/usr/bin/env perl |
34 | |
35 | use Catalyst::ScriptRunner; |
36 | Catalyst::ScriptRunner->run('TestApp', '$command'); |
37 | |
38 | 1; |
39 | END_CODE |
40 | close $fh; |
41 | chmod 0755, $script; |
42 | } |
43 | |
44 | open my $fh, '>:raw', "$testapp/cpanfile"; |
45 | close $fh; |
46 | |
47 | File::Copy::Recursive::dircopy( "$root/t/lib", "$testapp/lib" ); |
48 | |
49 | return $testapp; |
50 | } |
51 | |
52 | 1; |