2 # Copyright (C) 2001-2009, Parrot Foundation.
8 use Test::More tests => 15;
11 use File::Temp 0.13 qw/ tempdir /;
12 use lib qw( lib t/configure/testlib );
13 use Parrot::Configure;
14 use IO::CaptureOutput qw | capture |;
17 my $conf = Parrot::Configure->new;
18 $conf->data->set( make => 'make' );
20 my $nonexistent = 'config/gen/makefiles/foobar';
21 eval { $conf->genfile( $nonexistent => 'CFLAGS', comment_type => '#', ); };
23 $@, qr/Can't open $nonexistent/, #'
24 "Got expected error message when non-existent file provided as argument to genfile()."
28 my $tdir = tempdir( CLEANUP => 1 );
29 chdir $tdir or croak "Unable to change to temporary directory";
31 open my $IN, '>', $dummy or croak "Unable to open temp file for writing";
32 print $IN qq{Hello world\n};
33 close $IN or croak "Unable to close temp file";
37 file_type => 'makefile',
39 "genfile() returned true value with 'file_type' option being set to 'makefile'"
41 unlink $dummy or croak "Unable to delete file after testing";
42 chdir $cwd or croak "Unable to change back to starting directory";
46 my $tdir = tempdir( CLEANUP => 1 );
47 chdir $tdir or croak "Unable to change to temporary directory";
49 open my $IN, '>', $dummy or croak "Unable to open temp file for writing";
50 print $IN qq{Hello world\n};
51 close $IN or croak "Unable to close temp file";
52 eval { $conf->genfile( $dummy => 'CFLAGS', file_type => 'makefile', comment_type => q{<!--}, ); };
55 qr/^Unknown comment type/,
56 "genfile() failed due to unrecognized comment type with expected message"
58 unlink $dummy or croak "Unable to delete file after testing";
59 chdir $cwd or croak "Unable to change back to starting directory";
63 my $tdir = tempdir( CLEANUP => 1 );
64 chdir $tdir or croak "Unable to change to temporary directory";
66 open my $IN, '>', $dummy or croak "Unable to open temp file for writing";
67 print $IN qq{#perl Hello world\n};
68 close $IN or croak "Unable to close temp file";
72 file_type => 'makefile',
75 "genfile() returned true value with false value for 'feature_file' option"
77 unlink $dummy or croak "Unable to delete file after testing";
78 chdir $cwd or croak "Unable to change back to starting directory";
82 my $tdir = tempdir( CLEANUP => 1 );
83 chdir $tdir or croak "Unable to change to temporary directory";
85 open my $IN, '>', $dummy or croak "Unable to open temp file for writing";
86 print $IN q{#perl\nuse strict;\n$something = 'something';\n};
87 print $IN <<'END_DUMMY';
89 if (@verbose@) { sprint "Hello world\n"; }
91 close $IN or croak "Unable to close temp file";
92 my ($stdout, $stderr);
93 capture ( sub { eval { $conf->genfile( $dummy => 'CFLAGS', feature_file => 1, ) } },
95 ok( $stderr, "Error message caught" );
96 like( $stderr, qr/sprint/, "Error message had expected content" );
97 ok( $@, "Bad Perl code caught by genfile()" );
99 unlink $dummy or croak "Unable to delete file after testing";
100 chdir $cwd or croak "Unable to change back to starting directory";
104 my $tdir = tempdir( CLEANUP => 1 );
105 chdir $tdir or croak "Unable to change to temporary directory";
107 open my $IN, '>', $dummy or croak "Unable to open temp file for writing";
108 print $IN q{@foobar@\n};
109 close $IN or croak "Unable to close temp file";
110 my ($rv, $stdout, $stderr) ;
112 sub { $rv = $conf->genfile( $dummy => 'CFLAGS' ) },
116 ok($rv, "genfile() returned true when warning expected" );
117 like( $stderr, qr/value for '\@foobar\@'/, "got expected warning" );
119 unlink $dummy or croak "Unable to delete file after testing";
120 chdir $cwd or croak "Unable to change back to starting directory";
124 my $tdir = tempdir( CLEANUP => 1 );
125 chdir $tdir or croak "Unable to change to temporary directory";
127 open my $IN, '>', $dummy or croak "Unable to open temp file for writing";
128 print $IN q{This line ends in a slash/}, qq{\n};
129 close $IN or croak "Unable to close temp file";
130 eval { $conf->genfile( $dummy => 'CFLAGS', replace_slashes => 1, ); };
132 "genfile() died as expected with replace_slashes option and line ending in trailing slash"
135 unlink $dummy or croak "Unable to delete file after testing";
136 chdir $cwd or croak "Unable to change back to starting directory";
140 my $tdir = tempdir( CLEANUP => 1 );
141 chdir $tdir or croak "Unable to change to temporary directory";
143 open my $IN, '>', $dummy or croak "Unable to open temp file for writing";
144 my $line = q{$(basename morgan/lefay/abra.ca.dabra src/foo.c hacks)};
145 print $IN $line, "\n";
146 close $IN or croak "Unable to close temp file";
150 expand_gmake_syntax => 1,
152 "genfile() did transformation of 'make' 'basename' as expected"
154 unlink $dummy or croak "Unable to delete file after testing";
155 chdir $cwd or croak "Unable to change back to starting directory";
159 my $tdir = tempdir( CLEANUP => 1 );
160 chdir $tdir or croak "Unable to change to temporary directory";
162 open my $IN, '>', $dummy or croak "Unable to open temp file for writing";
163 my $line = q{$(notdir morgan/lefay/abra.ca.dabra src/foo.c hacks)};
165 print $IN $line, "\n";
166 close $IN or croak "Unable to close temp file";
170 expand_gmake_syntax => 1,
172 "genfile() did transformation of 'make' 'notdir' as expected"
174 unlink $dummy or croak "Unable to delete file after testing";
175 chdir $cwd or croak "Unable to change back to starting directory";
179 my $tdir = tempdir( CLEANUP => 1 );
180 chdir $tdir or croak "Unable to change to temporary directory";
182 open my $IN, '>', $dummy or croak "Unable to open temp file for writing";
183 my $line = q{$(addprefix src/,morgan/lefay/abra.ca.dabra foo bar)};
185 print $IN $line, "\n";
186 close $IN or croak "Unable to close temp file";
190 expand_gmake_syntax => 1,
192 "genfile() did transformation of 'make' 'addprefix' as expected"
194 unlink $dummy or croak "Unable to delete file after testing";
195 chdir $cwd or croak "Unable to change back to starting directory";
199 my $tdir = tempdir( CLEANUP => 1 );
200 chdir $tdir or croak "Unable to change to temporary directory";
202 open my $IN, '>', $dummy or croak "Unable to open temp file for writing";
203 my $line = q{$(wildcard *.c *.o)};
205 print $IN $line, "\n";
206 close $IN or croak "Unable to close temp file";
210 expand_gmake_syntax => 1,
212 "genfile() did transformation of 'make' 'wildcard' as expected"
214 unlink $dummy or croak "Unable to delete file after testing";
215 chdir $cwd or croak "Unable to change back to starting directory";
219 my $tdir = tempdir( CLEANUP => 1 );
220 chdir $tdir or croak "Unable to change to temporary directory";
222 open my $IN, '>', $dummy or croak "Unable to open temp file for writing";
223 print $IN qq{Hello world\n};
224 close $IN or croak "Unable to close temp file";
225 my $file_type = q{foobar};
226 eval { $conf->genfile( $dummy => 'CFLAGS', file_type => $file_type ); };
229 qr/^Unknown file_type '$file_type'/,
230 "genfile() failed due to unrecognized file type with expected message"
232 unlink $dummy or croak "Unable to delete file after testing";
233 chdir $cwd or croak "Unable to change back to starting directory";
236 ################### DOCUMENTATION ###################
240 t/configure/034-step.t - tests Parrot::Configure::Compiler
244 prove t/configure/034-step.t
248 Regression tests for the L<Parrot::Configure::Compiler> module. This file holds
249 tests for Parrot::Configure::Compiler::genfile().
251 Thanks to http://start.it.uts.edu.au/w/doc/solaris/gmake/make_8.html for
252 instruction in using F<gmake> functions.
258 # cperl-indent-level: 4
261 # vim: expandtab shiftwidth=4: