2 # Copyright (C) 2007-2010, Parrot Foundation.
4 # 008-file_based_configuration.t
11 use Cwd qw(cwd realpath);
12 our $topdir = realpath($Bin) . "/../..";
13 unshift @INC, qq{$topdir/lib};
15 use Test::More tests => 31;
17 use Parrot::Configure::Options qw| process_options |;
20 my $configfile = q{examples/config/file/configwithfatalstep};
21 my ($args, $steps_list_ref) = _test_good_config_file($configfile);
23 ok(! defined $args->{maintainer},
24 "Configuring from testfoobar: 'maintainer' not defined, as expected");
25 is($args->{'verbose-step'}, 'init::hints',
26 "Configuring from testfoobar: 'init::hints' is verbose step");
27 is($args->{'fatal-step'}, 'init::hints',
28 "Configuring from testfoobar: 'init::hints' is fatal step");
29 ok($args->{nomanicheck},
30 "Configuring from testfoobar: will omit check of MANIFEST");
31 is($args->{file}, $configfile,
32 "Configuring from testfoobar: config file correctly stored");
33 ok($args->{debugging},
34 "Configuring from testfoobar: debugging turned on");
35 my %steps_seen = map {$_ => 1} @{ $steps_list_ref };
36 ok(exists $steps_seen{'init::manifest'},
37 "Configuring from testfoobar: init::manifest is in list even though it will be skipped");
38 ok(! exists $steps_seen{'auto::perldoc'},
39 "Configuring from testfoobar: auto::perldoc not in list");
43 my $configfile = q{examples/config/file/configcompiler};
44 my ($args, $steps_list_ref) = _test_good_config_file($configfile);
46 my $c_compiler = '/usr/bin/gcc';
47 my $cplusplus_compiler = '/usr/bin/g++';
48 ok(! defined $args->{maintainer},
49 "Configuring from yourfoobar: 'maintainer' not defined as expected");
50 is($args->{'verbose-step'}, 'init::hints',
51 "Configuring from yourfoobar: 'init::hints' is verbose step");
52 ok($args->{nomanicheck},
53 "Configuring from yourfoobar: will omit check of MANIFEST");
54 is($args->{file}, $configfile,
55 "Configuring from yourfoobar: config file correctly stored");
56 ok($args->{debugging},
57 "Configuring from yourfoobar: debugging turned on");
58 is($args->{cc}, $c_compiler,
59 "Configuring from yourfoobar: C compiler is $c_compiler");
60 is($args->{cxx}, $cplusplus_compiler,
61 "Configuring from yourfoobar: C++ compiler is $cplusplus_compiler");
62 is($args->{link}, $cplusplus_compiler,
63 "Configuring from yourfoobar: linker is $cplusplus_compiler");
64 is($args->{ld}, $cplusplus_compiler,
65 "Configuring from yourfoobar: shared library loader is $cplusplus_compiler");
67 my %steps_seen = map {$_ => 1} @{ $steps_list_ref };
69 ok(exists $steps_seen{'init::manifest'},
70 "Configuring from yourfoobar: init::manifest is in list even though it will be skipped");
71 ok(! exists $steps_seen{'auto::perldoc'},
72 "Configuring from yourfoobar: auto::perldoc not in list");
76 my $configfile = q{t/configure/testlib/verbosefoobar};
77 my ($args, $steps_list_ref) = _test_good_config_file($configfile);
79 ok(! defined $args->{maintainer},
80 "Configuring from verbosefoobar: 'maintainer' not defined as expected");
81 ok($args->{nomanicheck},
82 "Configuring from verbosefoobar: will omit check of MANIFEST");
83 is($args->{file}, $configfile,
84 "Configuring from verbosefoobar: config file correctly stored");
85 ok($args->{debugging},
86 "Configuring from verbosefoobar: debugging turned on");
87 is($args->{verbose}, 1,
88 "Configuring from verbosefoobar: verbose output is on");
90 my %steps_seen = map {$_ => 1} @{ $steps_list_ref };
92 ok(exists $steps_seen{'init::manifest'},
93 "Configuring from verbosefoobar: init::manifest is in list even though it will be skipped");
94 ok(! exists $steps_seen{'auto::perldoc'},
95 "Configuring from verbosefoobar: auto::perldoc not in list");
99 my $configfile = q{t/configure/testlib/adefectivefoobar};
100 my $error = _test_defective_config_file($configfile);
101 like($error, qr/Configuration file $configfile did not parse correctly/,
102 "Got expected failure message after using defective configuration file");
106 my $configfile = q{t/configure/testlib/bdefectivefoobar};
107 my $error = _test_defective_config_file($configfile);
108 like($error, qr/Bad variable substitution in $configfile/,
109 "Got expected failure message after using defective configuration file");
113 my $configfile = q{t/configure/testlib/cdefectivefoobar};
114 my $error = _test_defective_config_file($configfile);
115 like($error, qr/Invalid general option foobar in $configfile/,
116 "Got expected failure message after using defective configuration file");
120 my $configfile = q{t/configure/testlib/ddefectivefoobar};
121 my $error = _test_defective_config_file($configfile);
122 like($error, qr/Invalid option "foobar"/,
123 "Got expected failure message after using defective configuration file");
126 pass("Completed all tests in $0");
128 ################### SUBROUTINES ###################
130 sub _test_good_config_file {
131 my $configfile = shift;
132 local @ARGV = ( qq{--file=$configfile} );
133 my ($args, $steps_list_ref) = process_options(
135 mode => (defined $ARGV[0] and $ARGV[0] =~ /^--file=/)
141 return ($args, $steps_list_ref);
144 sub _test_defective_config_file {
145 my $configfile = shift;
146 local @ARGV = ( qq{--file=$configfile} );
148 my ($args, $steps_list_ref) = process_options(
150 mode => (defined $ARGV[0] and $ARGV[0] =~ /^--file=/)
162 ################### DOCUMENTATION ###################
166 008-file_based_configuration.t - test components of Parrot's file-based interface to configuration
170 % prove t/configure/008-file_based_configuration.t
174 The files in this directory test functionality used by F<Configure.pl>.
176 The tests in this file test subroutines exported by
177 Parrot::Configure::Options as it is used with
178 C<mode =E<gt> q{file}>.
186 Parrot::Configure::Options, Parrot::Configure::Options::Conf,
187 Parrot::Configure::Options::Conf::CLI, F<Configure.pl>.
193 # cperl-indent-level: 4
196 # vim: expandtab shiftwidth=4: