1#! perl 2# Copyright (C) 2007, Parrot Foundation. 3# 049-options_test_prepare.t 4 5use strict; 6use warnings; 7use Carp; 8use Cwd; 9use File::Basename qw( basename fileparse ); 10use File::Path qw( mkpath ); 11use File::Temp 0.13 qw| tempdir |; 12use Test::More tests => 12; 13use lib qw( lib ); 14use Parrot::Configure::Options::Test::Prepare (); 15 16my $cwd = cwd(); 17{ 18 my $tdir = tempdir( CLEANUP => 1 ); 19 chdir $tdir or croak "Unable to change to temporary directory"; 20 my $good_test = q{001-sometest.t}; 21 my $bad_test = q{someothertest.t}; 22 touch_in_this_dir($good_test); 23 touch_in_this_dir($bad_test); 24 my %tests_seen = map { basename($_), 1 } 25 Parrot::Configure::Options::Test::Prepare::_get_framework_tests($tdir); 26 ok($tests_seen{$good_test}, 27 "Correctly named test identified"); 28 ok(! $tests_seen{$bad_test}, 29 "Incorrectly named test excluded"); 30 31 ok( chdir $cwd, "Able to change back to starting directory"); 32} 33 34{ 35 my $tdir = tempdir( CLEANUP => 1 ); 36 chdir $tdir or croak "Unable to change to temporary directory"; 37 my $init_test = q{init/sometest-01.t}; 38 my $init_hints_test = q{init/hints/sometest-01.t}; 39 my $inter_test = q{inter/sometest-01.t}; 40 my $auto_test = q{auto/sometest-01.t}; 41 my $gen_test = q{gen/sometest-01.t}; 42 my $bad_test = q{bad/sometest-01.t}; 43 my $lack_number_test = q{init/test.t}; 44 my $CamelCase_test = q{gen/CamelCase-01.t}; 45 touch($init_test); 46 touch($init_hints_test); 47 touch($inter_test); 48 touch($auto_test); 49 touch($gen_test); 50 touch($bad_test); 51 touch($lack_number_test); 52 touch($CamelCase_test); 53 54 my ( $steps_tests_simple_ref, $steps_tests_complex_ref ) = 55 Parrot::Configure::Options::Test::Prepare::_find_steps_tests($tdir); 56 my $full_bad_test = $tdir . '/' . $bad_test; 57 ok( ! exists $steps_tests_simple_ref->{$full_bad_test}, 58 "File in incorrect directory correctly excluded from list of configuration step tests"); 59 my $full_lack_number_test = $tdir . '/' . $lack_number_test; 60 ok( ! exists $steps_tests_simple_ref->{$full_lack_number_test}, 61 "File lacking 2-digit number correctly excluded from list of configuration step tests"); 62 my $full_init_hints_test = $tdir . '/'. $init_hints_test; 63 ok( exists $steps_tests_simple_ref->{$full_init_hints_test}, 64 "File in second-level directory correctly included in list of configuration step tests"); 65 my $full_CamelCase_test = $tdir . '/' . $CamelCase_test; 66 ok( ! exists $steps_tests_simple_ref->{$full_CamelCase_test}, 67 "File containing capital letters in name correctly excluded from list of configuration step tests"); 68 69 my @tests_expected = qw( 70 init::sometest 71 init::hints::sometest 72 inter::sometest 73 auto::sometest 74 gen::sometest 75 ); 76 my @not_expected = ( q{gen::missing}, q{auto::fabulous} ); 77 my @all_tests = (); 78 push @all_tests, (@tests_expected, @not_expected); 79 my ( $steps_tests_ref, $steps_lacking_tests_ref) = 80 Parrot::Configure::Options::Test::Prepare::_prepare_steps_tests_list( 81 $tdir, 82 $steps_tests_complex_ref, 83 \@all_tests, 84 ); 85 is( scalar(@$steps_tests_ref), scalar(@tests_expected), 86 "Got expected number of existing steps" ); 87 is( scalar(@$steps_lacking_tests_ref), scalar(@not_expected), 88 "Got expected number of missing steps" ); 89 is( $steps_lacking_tests_ref->[0], $not_expected[0], 90 "Got expected missing step $not_expected[0]" ); 91 92 ok( chdir $cwd, "Able to change back to starting directory"); 93} 94 95pass("Completed all tests in $0"); 96 97sub touch { 98 my $path = shift; 99 my ($base, $dirs) = fileparse($path); 100 my $cwd = cwd(); 101 unless ( -d $dirs ) { 102 mkpath( [ $dirs ], 0, 0777 ) or croak "Unable to create dirs: $!"; 103 } 104 chdir $dirs or croak "Unable to change dir: $!"; 105 touch_in_this_dir( $base ); 106 chdir $cwd or croak "Unable to change back dir: $!"; 107 ( -e $path ) or croak "Didn't create file: $!"; 108} 109 110sub touch_in_this_dir { 111 my $file = shift; 112 open my $FH, '>', $file or croak "Unable to open $file for writing"; 113 print $FH "Hello, world\n"; 114 close $FH or croak "Unable to close $file after writing"; 115} 116 117################### DOCUMENTATION ################### 118 119=head1 NAME 120 121049-options_test_prepare.t - test Parrot::Configure::Options::Test 122 123=head1 SYNOPSIS 124 125 % prove t/configure/049-options_test_prepare.t 126 127=head1 DESCRIPTION 128 129The files in this directory test functionality used by F<Configure.pl>. 130 131The tests in this file test Parrot::Configure::Options::Test::Prepare 132subroutines. 133 134=head1 AUTHOR 135 136James E Keenan 137 138=head1 SEE ALSO 139 140Parrot::Configure::Options::Test, F<Configure.pl>. 141 142=cut 143 144# Local Variables: 145# mode: cperl 146# cperl-indent-level: 4 147# fill-column: 100 148# End: 149# vim: expandtab shiftwidth=4: 150 151