2 # Copyright (C) 2007, Parrot Foundation.
8 use Test::More tests => 33;
11 use File::Path qw| mkpath |;
12 use File::Temp qw| tempdir |;
13 use lib qw( lib t/configure/testlib );
14 use_ok('config::auto::pmc');
15 use Parrot::Configure::Options qw( process_options );
16 use Parrot::Configure::Step::Test;
17 use Parrot::Configure::Test qw(
18 test_step_constructor_and_description
20 use IO::CaptureOutput qw( capture );
22 ########## regular ##########
24 my ($args, $step_list_ref) = process_options(
31 my $conf = Parrot::Configure::Step::Test->new;
32 $conf->include_config_results( $args );
34 my $pkg = q{auto::pmc};
36 $conf->add_steps($pkg);
38 my $serialized = $conf->pcfreeze();
40 $conf->options->set( %{$args} );
41 my $step = test_step_constructor_and_description($conf);
43 my $ret = $step->runstep($conf);
44 ok( $ret, "runstep() returned true value" );
46 $conf->replenish($serialized);
48 ########## contains_pccmethod() ##########
50 ($args, $step_list_ref) = process_options(
57 $conf->options->set( %{$args} );
58 $step = test_step_constructor_and_description($conf);
61 my $tdir = tempdir( CLEANUP => 1 );
62 ok( chdir $tdir, 'changed to temp directory for testing' );
64 my $pmc_with_PCCMETHOD = q{yes.pmc};
65 open my $IN1, ">", $pmc_with_PCCMETHOD
66 or croak "Unable to open file for writing: $!";
67 print $IN1 "PCCMETHOD\n";
68 close $IN1 or croak "Unable to close file after writing: $!";
69 ok(auto::pmc::contains_pccmethod($pmc_with_PCCMETHOD),
70 "Internal subroutine contains_pccmethod returns true as expected");
72 my $pmc_sans_PCCMETHOD = q{no.pmc};
73 open my $IN2, ">", $pmc_sans_PCCMETHOD
74 or croak "Unable to open file for writing: $!";
75 print $IN2 "Hello world\n";
76 close $IN2 or croak "Unable to close file after writing: $!";
78 auto::pmc::contains_pccmethod($pmc_sans_PCCMETHOD)
79 ), "Internal subroutine contains_pccmethod returns true as expected"
83 eval { auto::pmc::contains_pccmethod($file); };
84 like($@, qr/Can't read '$file'/, "Got expected 'die' message"); #'
86 ok( chdir $cwd, 'changed back to original directory after testing' );
89 ########## get_pmc_order() ##########
92 my $tdir = tempdir( CLEANUP => 1 );
93 ok( chdir $tdir, 'changed to temp directory for testing' );
95 my $pmcdir = qq{$tdir/src/pmc};
96 ok(mkpath($pmcdir, { mode => 0755 }), "Able to make directory for testing");
97 my $num = qq{$pmcdir/pmc.num};
98 open my $OUT3, ">", $num or croak "Unable to open file for writing: $!";
99 print $OUT3 "# comment line\n";
101 print $OUT3 "default.pmc\t0\n";
102 print $OUT3 "null.pmc 1\n";
103 print $OUT3 "env.pmc 2\n";
104 print $OUT3 "notapmc 3\n";
105 close $OUT3 or croak "Unable to close file after writing: $!";
106 my $order_ref = auto::pmc::get_pmc_order();
114 "Able to read src/pmc/pmc.num correctly"
117 my @pmcs = qw| env.pmc default.pmc null.pmc other.pmc |;
118 my $pseudoman = 'MANIFEST';
119 open my $MAN, '>', $pseudoman or croak "Unable to open $pseudoman";
120 print $MAN "src/pmc/$_\n" for @pmcs;
123 split / /, auto::pmc::get_sorted_pmc_str(@pmcs);
126 [ qw| default.pmc null.pmc env.pmc other.pmc | ],
127 "PMCs sorted correctly"
130 ok( chdir $cwd, 'changed back to original directory after testing' );
134 my $tdir = tempdir( CLEANUP => 1 );
135 ok( chdir $tdir, 'changed to temp directory for testing' );
137 my $pmcdir = qq{$tdir/src/pmc};
138 ok(mkpath($pmcdir, { mode => 0755 }), "Able to make directory for testing");
139 my $num = qq{$pmcdir/pmc.num};
140 open my $OUT4, ">", $num or croak "Unable to open file for writing: $!";
141 print $OUT4 "# comment line\n";
143 print $OUT4 "default.pmc\t0\n";
144 print $OUT4 "null.pmc 1\n";
145 print $OUT4 "env.pmc 2\n";
146 print $OUT4 "notapmc 3\n";
147 close $OUT4 or croak "Unable to close file after writing: $!";
148 my $order_ref = auto::pmc::get_pmc_order();
156 "Able to read src/pmc/pmc.num correctly"
159 my @pmcs = qw| env.pmc default.pmc null.pmc other.pmc |;
160 my $pseudoman = 'MANIFEST';
161 open my $MAN, '>', $pseudoman or croak "Unable to open $pseudoman";
162 print $MAN "src/pmc/$_\n" for @pmcs[0..2];
165 my ($stdout, $stderr);
168 @sorted_pmcs = split / /,
169 auto::pmc::get_sorted_pmc_str(@pmcs);
175 qr/PMCs found in \/src\/pmc not found in MANIFEST: $pmcs[3]/,
176 "Got expected warning",
180 [ qw| default.pmc null.pmc env.pmc other.pmc | ],
181 "PMCs sorted correctly"
185 ok( chdir $cwd, 'changed back to original directory after testing' );
189 my $tdir = tempdir( CLEANUP => 1 );
190 ok( chdir $tdir, 'changed to temp directory for testing' );
192 my $pmcdir = qq{$tdir/src/pmc};
193 ok(mkpath($pmcdir, { mode => 0755 }), "Able to make directory for testing");
194 eval { my $order_ref = auto::pmc::get_pmc_order(); };
196 qr/Can't read src\/pmc\/pmc\.num/, "Got expected 'die' message");
199 ok( chdir $cwd, 'changed back to original directory after testing' );
202 my $seen_man = auto::pmc::pmcs_in_manifest();
203 ok( keys %{$seen_man}, 'src/pmc/*.pmc files were seen in MANIFEST' );
206 my $tdir = tempdir( CLEANUP => 1 );
207 ok( chdir $tdir, 'changed to temp directory for testing' );
209 my @pmcs = qw| env.pmc default.pmc null.pmc other.pmc |;
210 my $pseudoman = 'foobar';
211 open my $MAN, '>', $pseudoman or croak "Unable to open $pseudoman";
212 print $MAN "src/pmc/$_\n" for @pmcs;
215 my $seen_manifest = auto::pmc::pmcs_in_manifest($pseudoman);
218 { map { $_ => 1} @pmcs },
219 "Got expected files in differently named MANIFEST",
221 ok( chdir $cwd, 'changed back to original directory after testing' );
224 pass("Completed all tests in $0");
226 ################### DOCUMENTATION ###################
230 auto/pmc-01.t - test auto::pmc
234 % prove t/steps/auto/pmc-01.t
238 The files in this directory test functionality used by F<Configure.pl>.
240 The tests in this file test auto::pmc.
248 config::auto::pmc, F<Configure.pl>.
254 # cperl-indent-level: 4
257 # vim: expandtab shiftwidth=4: