[TT# 1592][t] Improve test for open opcode delegation. All tests in the file pass...
[parrot.git] / t / configure / 034-step.t
blobda3ed40ecaa527bc217f5325b29d3c2944187693
1 #!perl
2 # Copyright (C) 2001-2009, Parrot Foundation.
3 # $Id$
5 use strict;
6 use warnings;
8 use Test::More tests => 15;
9 use Carp;
10 use Cwd;
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 |;
16 my $cwd = cwd();
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 => '#', ); };
22 like(
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";
30     my $dummy = 'dummy';
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";
34     ok(
35         $conf->genfile(
36             $dummy   => 'CFLAGS',
37             file_type => 'makefile',
38         ),
39         "genfile() returned true value with 'file_type' option being set to 'makefile'"
40     );
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";
48     my $dummy = 'dummy';
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{<!--}, ); };
53     like(
54         $@,
55         qr/^Unknown comment type/,
56         "genfile() failed due to unrecognized comment type with expected message"
57     );
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";
65     my $dummy = 'dummy';
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";
69     ok(
70         $conf->genfile(
71             $dummy       => 'CFLAGS',
72             file_type    => 'makefile',
73             feature_file => 0,
74         ),
75         "genfile() returned true value with false value for 'feature_file' option"
76     );
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";
84     my $dummy = 'dummy';
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';
88 #perl
89 if (@verbose@) { sprint "Hello world\n"; }
90 END_DUMMY
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, ) } },
94         \$stdout, \$stderr );
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";
106     my $dummy = 'dummy';
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) ;
111     capture (
112         sub { $rv = $conf->genfile( $dummy => 'CFLAGS' ) },
113         \$stdout,
114         \$stderr
115     );
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";
126     my $dummy = 'dummy';
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, ); };
131     like( $@, qr//,
132         "genfile() died as expected with replace_slashes option and line ending in trailing slash"
133     );
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";
142     my $dummy = 'dummy';
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";
147     ok(
148         $conf->genfile(
149             $dummy              => 'CFLAGS',
150             expand_gmake_syntax => 1,
151         ),
152         "genfile() did transformation of 'make' 'basename' as expected"
153     );
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";
161     my $dummy = 'dummy';
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";
167     ok(
168         $conf->genfile(
169             $dummy              => 'CFLAGS',
170             expand_gmake_syntax => 1,
171         ),
172         "genfile() did transformation of 'make' 'notdir' as expected"
173     );
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";
181     my $dummy = 'dummy';
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";
187     ok(
188         $conf->genfile(
189             $dummy              => 'CFLAGS',
190             expand_gmake_syntax => 1,
191         ),
192         "genfile() did transformation of 'make' 'addprefix' as expected"
193     );
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";
201     my $dummy = 'dummy';
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";
207     ok(
208         $conf->genfile(
209             $dummy              => 'CFLAGS',
210             expand_gmake_syntax => 1,
211         ),
212         "genfile() did transformation of 'make' 'wildcard' as expected"
213     );
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";
221     my $dummy = 'dummy';
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 ); };
227     like(
228         $@,
229         qr/^Unknown file_type '$file_type'/,
230         "genfile() failed due to unrecognized file type with expected message"
231     );
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 ###################
238 =head1 NAME
240 t/configure/034-step.t - tests Parrot::Configure::Compiler
242 =head1 SYNOPSIS
244     prove t/configure/034-step.t
246 =head1 DESCRIPTION
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.
254 =cut
256 # Local Variables:
257 #   mode: cperl
258 #   cperl-indent-level: 4
259 #   fill-column: 100
260 # End:
261 # vim: expandtab shiftwidth=4: