-
Notifications
You must be signed in to change notification settings - Fork 138
/
008-file_based_configuration.t
195 lines (161 loc) · 6.55 KB
/
008-file_based_configuration.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#! perl
# Copyright (C) 2007-2010, Parrot Foundation.
# 008-file_based_configuration.t
use strict;
use warnings;
BEGIN {
use FindBin qw($Bin);
use Cwd qw(cwd realpath);
our $topdir = realpath($Bin) . "/../..";
unshift @INC, qq{$topdir/lib};
}
use Test::More tests => 31;
use Carp;
use Parrot::Configure::Options qw| process_options |;
{
my $configfile = q{examples/config/file/configwithfatalstep};
my ($args, $steps_list_ref) = _test_good_config_file($configfile);
ok(! defined $args->{maintainer},
"Configuring from testfoobar: 'maintainer' not defined, as expected");
is($args->{'verbose-step'}, 'init::hints',
"Configuring from testfoobar: 'init::hints' is verbose step");
is($args->{'fatal-step'}, 'init::hints',
"Configuring from testfoobar: 'init::hints' is fatal step");
ok($args->{nomanicheck},
"Configuring from testfoobar: will omit check of MANIFEST");
is($args->{file}, $configfile,
"Configuring from testfoobar: config file correctly stored");
ok($args->{debugging},
"Configuring from testfoobar: debugging turned on");
my %steps_seen = map {$_ => 1} @{ $steps_list_ref };
ok(exists $steps_seen{'init::manifest'},
"Configuring from testfoobar: init::manifest is in list even though it will be skipped");
ok(! exists $steps_seen{'auto::perldoc'},
"Configuring from testfoobar: auto::perldoc not in list");
}
{
my $configfile = q{examples/config/file/configcompiler};
my ($args, $steps_list_ref) = _test_good_config_file($configfile);
my $c_compiler = '/usr/bin/gcc';
my $cplusplus_compiler = '/usr/bin/g++';
ok(! defined $args->{maintainer},
"Configuring from yourfoobar: 'maintainer' not defined as expected");
is($args->{'verbose-step'}, 'init::hints',
"Configuring from yourfoobar: 'init::hints' is verbose step");
ok($args->{nomanicheck},
"Configuring from yourfoobar: will omit check of MANIFEST");
is($args->{file}, $configfile,
"Configuring from yourfoobar: config file correctly stored");
ok($args->{debugging},
"Configuring from yourfoobar: debugging turned on");
is($args->{cc}, $c_compiler,
"Configuring from yourfoobar: C compiler is $c_compiler");
is($args->{cxx}, $cplusplus_compiler,
"Configuring from yourfoobar: C++ compiler is $cplusplus_compiler");
is($args->{link}, $cplusplus_compiler,
"Configuring from yourfoobar: linker is $cplusplus_compiler");
is($args->{ld}, $cplusplus_compiler,
"Configuring from yourfoobar: shared library loader is $cplusplus_compiler");
my %steps_seen = map {$_ => 1} @{ $steps_list_ref };
ok(exists $steps_seen{'init::manifest'},
"Configuring from yourfoobar: init::manifest is in list even though it will be skipped");
ok(! exists $steps_seen{'auto::perldoc'},
"Configuring from yourfoobar: auto::perldoc not in list");
}
{
my $configfile = q{t/configure/testlib/verbosefoobar};
my ($args, $steps_list_ref) = _test_good_config_file($configfile);
ok(! defined $args->{maintainer},
"Configuring from verbosefoobar: 'maintainer' not defined as expected");
ok($args->{nomanicheck},
"Configuring from verbosefoobar: will omit check of MANIFEST");
is($args->{file}, $configfile,
"Configuring from verbosefoobar: config file correctly stored");
ok($args->{debugging},
"Configuring from verbosefoobar: debugging turned on");
is($args->{verbose}, 1,
"Configuring from verbosefoobar: verbose output is on");
my %steps_seen = map {$_ => 1} @{ $steps_list_ref };
ok(exists $steps_seen{'init::manifest'},
"Configuring from verbosefoobar: init::manifest is in list even though it will be skipped");
ok(! exists $steps_seen{'auto::perldoc'},
"Configuring from verbosefoobar: auto::perldoc not in list");
}
{
my $configfile = q{t/configure/testlib/adefectivefoobar};
my $error = _test_defective_config_file($configfile);
like($error, qr/Configuration file $configfile did not parse correctly/,
"Got expected failure message after using defective configuration file");
}
{
my $configfile = q{t/configure/testlib/bdefectivefoobar};
my $error = _test_defective_config_file($configfile);
like($error, qr/Bad variable substitution in $configfile/,
"Got expected failure message after using defective configuration file");
}
{
my $configfile = q{t/configure/testlib/cdefectivefoobar};
my $error = _test_defective_config_file($configfile);
like($error, qr/Invalid general option foobar in $configfile/,
"Got expected failure message after using defective configuration file");
}
{
my $configfile = q{t/configure/testlib/ddefectivefoobar};
my $error = _test_defective_config_file($configfile);
like($error, qr/Invalid option "foobar"/,
"Got expected failure message after using defective configuration file");
}
pass("Completed all tests in $0");
################### SUBROUTINES ###################
sub _test_good_config_file {
my $configfile = shift;
local @ARGV = ( qq{--file=$configfile} );
my ($args, $steps_list_ref) = process_options(
{
mode => (defined $ARGV[0] and $ARGV[0] =~ /^--file=/)
? 'file'
: 'configure',
argv => [@ARGV],
}
);
return ($args, $steps_list_ref);
}
sub _test_defective_config_file {
my $configfile = shift;
local @ARGV = ( qq{--file=$configfile} );
eval {
my ($args, $steps_list_ref) = process_options(
{
mode => (defined $ARGV[0] and $ARGV[0] =~ /^--file=/)
? 'file'
: 'configure',
argv => [@ARGV],
}
);
};
my $error = $@;
$@ = undef;
return $error;
}
################### DOCUMENTATION ###################
=head1 NAME
008-file_based_configuration.t - test components of Parrot's file-based interface to configuration
=head1 SYNOPSIS
% prove t/configure/008-file_based_configuration.t
=head1 DESCRIPTION
The files in this directory test functionality used by F<Configure.pl>.
The tests in this file test subroutines exported by
Parrot::Configure::Options as it is used with
C<mode =E<gt> q{file}>.
=head1 AUTHOR
James E Keenan
=head1 SEE ALSO
Parrot::Configure::Options, Parrot::Configure::Options::Conf,
Parrot::Configure::Options::Conf::CLI, F<Configure.pl>.
=cut
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4: