2 # Copyright (C) 2007-2008, Parrot Foundation.
8 use Test::More tests => 12;
12 use File::Path qw( mkpath );
13 use File::Temp qw( tempdir );
16 use_ok('config::gen::platform');
17 use Parrot::Configure::Options qw( process_options );
18 use Parrot::Configure::Step::Test;
19 use Parrot::Configure::Test qw(
20 test_step_constructor_and_description
22 use Parrot::Configure::Utils qw( _slurp );
23 use IO::CaptureOutput qw( capture );
25 ########## regular ##########
27 my ($args, $step_list_ref) = process_options(
34 my $conf = Parrot::Configure::Step::Test->new;
35 $conf->include_config_results( $args );
37 my $pkg = q{gen::platform};
38 $conf->add_steps($pkg);
39 $conf->options->set( %{$args} );
40 my $step = test_step_constructor_and_description($conf);
42 my $platform_orig = $conf->data->get('osname');
43 my $archname_orig = $conf->data->get('archname');
44 $conf->data->set( archname => 'foo-bar' );
46 ########## _get_generated() ##########
48 my $TEMP_generated_orig = $conf->data->get('TEMP_generated');
50 $conf->options->set(verbose => 1);
51 my ($stdout, $stderr, $rv);
52 my $expected = q{foo};
53 $conf->data->set( TEMP_generated => $expected );
55 sub { $rv = $step->_get_generated( $conf ) },
59 is( $rv, $expected, "Got expected generated");
60 like( $stdout, qr/\($expected\)/, "Got expected verbose output");
62 $conf->data->set( TEMP_generated => undef );
63 $conf->options->set(verbose => 0);
64 is( $step->_get_generated( $conf ), q{},
65 "Got expected generated");
67 # re-set to original values
68 $conf->data->set( TEMP_generated => $TEMP_generated_orig );
70 ########## _handle_asm() ##########
72 my $platform_asm_orig = $conf->data->get('platform_asm');
75 my $tdir = tempdir( CLEANUP => 1 );
76 chdir $tdir or croak "Unable to change to temporary directory";
77 $conf->data->set( platform_asm => 1 );
79 $conf->data->set( platform => $platform );
80 mkpath( 'src', { mode => 0755 } ) or croak "Unable to make testing directory";
81 my $asmfile = File::Spec->catfile( 'src', 'platform_asm.s' );
82 open my $FH, '>', $asmfile or croak "Unable to open handle for writing";
83 print $FH "Hello asm\n";
84 close $FH or croak "Unable to close handle after writing";
85 $step->_handle_asm($conf);
86 my $text = _slurp( $asmfile );
87 like($text, qr/Hello asm/s, "File unchanged, as expected");
89 chdir $cwd or croak "Unable to change back to starting directory";
91 # re-set to original values
92 $conf->data->set( platform_asm => $platform_asm_orig );
93 $conf->data->set( platform => $platform_orig );
96 my $tdir = tempdir( CLEANUP => 1 );
97 chdir $tdir or croak "Unable to change to temporary directory";
98 $conf->data->set( platform_asm => 1 );
100 $conf->data->set( platform => $platform );
102 mkpath( 'src', { mode => 0755 } )
103 or croak "Unable to make testing directory";
105 my $asmfile = File::Spec->catfile( 'src', 'platform_asm.s' );
106 open my $FH, '>', $asmfile or croak "Unable to open handle for writing";
107 print $FH "Hello asm\n";
108 close $FH or croak "Unable to close handle after writing";
110 my $path = File::Spec->catdir( 'config', 'gen', 'platform', $platform );
111 mkpath( $path, { mode => 0755 } )
112 or croak "Unable to make testing directory";
114 my $configfile = File::Spec->catfile( $path, 'asm.s' );
115 open my $FH2, '>', $configfile or croak "Unable to open handle for writing";
116 print $FH2 "Goodbye world\n";
117 close $FH2 or croak "Unable to close handle after writing";
119 $step->_handle_asm($conf);
121 my $text = _slurp( $asmfile );
122 like($text, qr/Goodbye world/s, "File changed, as expected");
124 chdir $cwd or croak "Unable to change back to starting directory";
126 # re-set to original values
127 $conf->data->set( platform_asm => $platform_asm_orig );
128 $conf->data->set( platform => $platform_orig );
130 ########## _handle_begin_c() ##########
132 my $tdir = tempdir( CLEANUP => 1 );
133 chdir $tdir or croak "Unable to change to temporary directory";
134 my $platform = 'darwin';
135 $conf->data->set( platform => $platform );
137 my $path = File::Spec->catdir( 'config', 'gen', 'platform', $platform );
138 mkpath( $path, { mode => 0755 } ) or croak "Unable to make testing directory";
139 copy qq{$cwd/config/gen/platform/$platform/begin.c},
141 or croak "Unable to copy file for testing";
143 mkpath( 'src', { mode => 0755 } ) or croak "Unable to make testing directory";
144 my $plat_c = q{src/platform.c};
145 open my $PLATFORM_C, '>', $plat_c
146 or croak "Unable to open handle for writing";
147 $step->_handle_begin_c($platform, $PLATFORM_C);
148 close $PLATFORM_C or croak "Unable to close handle after writing";
150 my $text = _slurp( $plat_c );
151 like($text, qr/#undef environ.*#undef bool/s,
152 "Got expected text in header file");
153 unlike($text, qr/Local variables/s, "Coda stripped, as desired");
155 chdir $cwd or croak "Unable to change back to starting directory";
158 pass("Completed all tests in $0");
160 ################### DOCUMENTATION ###################
164 gen/platform-01.t - test gen::platform
168 % prove t/steps/gen/platform-01.t
172 The files in this directory test functionality used by F<Configure.pl>.
174 The tests in this file test gen::platform.
182 config::gen::platform, F<Configure.pl>.
188 # cperl-indent-level: 4
191 # vim: expandtab shiftwidth=4: