2 # Copyright (C) 2007, Parrot Foundation.
4 # 049-options_test_prepare.t
10 use File::Basename qw( basename fileparse );
11 use File::Path qw( mkpath );
12 use File::Temp 0.13 qw| tempdir |;
13 use Test::More tests => 10;
15 use IO::CaptureOutput qw| capture |;
16 use Parrot::Configure::Options::Test::Prepare ();
20 my $tdir = tempdir( CLEANUP => 1 );
21 chdir $tdir or croak "Unable to change to temporary directory";
22 my $good_test = q{001-sometest.t};
23 my $bad_test = q{someothertest.t};
24 touch_in_this_dir($good_test);
25 touch_in_this_dir($bad_test);
26 my %tests_seen = map { basename($_), 1 }
27 Parrot::Configure::Options::Test::Prepare::_get_framework_tests($tdir);
28 ok($tests_seen{$good_test},
29 "Correctly named test identified");
30 ok(! $tests_seen{$bad_test},
31 "Incorrectly named test excluded");
33 ok( chdir $cwd, "Able to change back to starting directory");
37 my $tdir = tempdir( CLEANUP => 1 );
38 chdir $tdir or croak "Unable to change to temporary directory";
39 my $init_test = q{init/sometest-01.t};
40 my $init_hints_test = q{init/hints/sometest-01.t};
41 my $inter_test = q{inter/sometest-01.t};
42 my $auto_test = q{auto/sometest-01.t};
43 my $gen_test = q{gen/sometest-01.t};
44 my $bad_test = q{bad/sometest-01.t};
45 my $lack_number_test = q{init/test.t};
46 my $CamelCase_test = q{gen/CamelCase-01.t};
48 touch($init_hints_test);
53 touch($lack_number_test);
54 touch($CamelCase_test);
56 my ( $steps_tests_simple_ref, $steps_tests_complex_ref ) =
57 Parrot::Configure::Options::Test::Prepare::_find_steps_tests($tdir);
58 my $full_bad_test = $tdir . '/' . $bad_test;
59 ok( ! exists $steps_tests_simple_ref->{$full_bad_test},
60 "File in incorrect directory correctly excluded from list of configuration step tests");
61 my $full_lack_number_test = $tdir . '/' . $lack_number_test;
62 ok( ! exists $steps_tests_simple_ref->{$full_lack_number_test},
63 "File lacking 2-digit number correctly excluded from list of configuration step tests");
64 my $full_init_hints_test = $tdir . '/'. $init_hints_test;
65 ok( exists $steps_tests_simple_ref->{$full_init_hints_test},
66 "File in second-level directory correctly included in list of configuration step tests");
67 my $full_CamelCase_test = $tdir . '/' . $CamelCase_test;
68 ok( ! exists $steps_tests_simple_ref->{$full_CamelCase_test},
69 "File containing capital letters in name correctly excluded from list of configuration step tests");
71 my @tests_expected = qw(
78 my $not_expected = q{gen::missing};
79 push @tests_expected, $not_expected;
82 my ($stdout, $stderr);
84 sub { %tests_seen = map { $_, 1}
85 Parrot::Configure::Options::Test::Prepare::_prepare_steps_tests_list(
87 $steps_tests_complex_ref,
93 like($stderr, qr/No tests exist for configure step $not_expected/,
94 "Warning about step class lacking test captured");
96 ok( chdir $cwd, "Able to change back to starting directory");
99 pass("Completed all tests in $0");
103 my ($base, $dirs) = fileparse($path);
105 unless ( -d $dirs ) {
106 mkpath( [ $dirs ], 0, 0777 ) or croak "Unable to create dirs: $!";
108 chdir $dirs or croak "Unable to change dir: $!";
109 touch_in_this_dir( $base );
110 chdir $cwd or croak "Unable to change back dir: $!";
111 ( -e $path ) or croak "Didn't create file: $!";
114 sub touch_in_this_dir {
116 open my $FH, '>', $file or croak "Unable to open $file for writing";
117 print $FH "Hello, world\n";
118 close $FH or croak "Unable to close $file after writing";
121 ################### DOCUMENTATION ###################
125 049-options_test_prepare.t - test Parrot::Configure::Options::Test
129 % prove t/configure/049-options_test_prepare.t
133 The files in this directory test functionality used by F<Configure.pl>.
135 The tests in this file test Parrot::Configure::Options::Test::Prepare
144 Parrot::Configure::Options::Test, F<Configure.pl>.
150 # cperl-indent-level: 4
153 # vim: expandtab shiftwidth=4: