aff0e23d79a317c919f71dfc5bc5c9cf6ff19432
[catagits/Catalyst-Model-DBIC-Schema.git] / t / 04testapp.t
1 use strict;
2 use Test::More;
3 use FindBin;
4 use File::Spec;
5 use File::Find;
6
7 plan skip_all => 'Enable this optional test with $ENV{C_M_DBIC_SCHEMA_TESTAPP}'
8     unless $ENV{C_M_DBIC_SCHEMA_TESTAPP};
9
10 my $test_params = [
11     [ 'TestSchema', 'DBIC::Schema', '' ],
12     [ 'TestSchemaDSN', 'DBIC::Schema', 'fakedsn fakeuser fakepass' ],
13     [ 'TestSchemaLoader', 'DBIC::SchemaLoader', 'fakedsn fakeuser fakepass' ],
14 ];
15
16 plan tests => (2 * @$test_params);
17
18 my $test_dir   = $FindBin::Bin;
19 my $blib_dir   = File::Spec->catdir ($test_dir, '..', 'blib', 'lib');
20 my $cat_dir    = File::Spec->catdir ($test_dir, 'TestApp');
21 my $catlib_dir = File::Spec->catdir ($cat_dir, 'lib');
22 my $creator    = File::Spec->catfile($cat_dir, 'script', 'testapp_create.pl');
23 my $model_dir  = File::Spec->catdir ($catlib_dir, 'TestApp', 'Model');
24
25 chdir($test_dir);
26 system("catalyst.pl TestApp");
27 chdir($cat_dir);
28
29 foreach my $tparam (@$test_params) {
30    my ($model, $helper, $args) = @$tparam;
31    system("$^X -I$blib_dir $creator model $model $helper $model $args");
32    my $model_path = File::Spec->catfile($model_dir, $model . '.pm');
33    ok( -f $model_path, "$model_path is a file" );
34    my $compile_rv = system("$^X -I$blib_dir -I$catlib_dir -c $model_path");
35    ok($compile_rv == 0, "perl -c $model_path");
36 }
37
38 chdir($test_dir);
39
40 sub rm_rf {
41     my $name = $File::Find::name;
42     if(-d $name) { rmdir $name or die "Cannot rmdir $name: $!" }
43     else { unlink $name or die "Cannot unlink $name: $!" }
44 }
45 finddepth(\&rm_rf, $cat_dir);