@@ -9,14 +9,15 @@ use File::Spec;
9
9
use Rex::CLI;
10
10
11
11
# diag 'create some rexfiles to test...';
12
- my $fh = undef ;
13
- my $testdir = File::Temp-> newdir(' rextest.XXXX' , TMPDIR => 1, CLEANUP => 1);
12
+ my $fh = undef ;
13
+ my $testdir = File::Temp-> newdir( ' rextest.XXXX' , TMPDIR => 1, CLEANUP => 1 );
14
14
while (<DATA >) {
15
15
last if / ^__END__$ / ;
16
16
if (/ ^@@ *(\S +)$ / ) {
17
+
17
18
# diag "prepare file $1";
18
19
close ($fh ) if $fh ;
19
- open ($fh , ' >' , File::Spec-> catfile($testdir , $1 ) ) or die $! ;
20
+ open ( $fh , ' >' , File::Spec-> catfile( $testdir , $1 ) ) or die $! ;
20
21
next ;
21
22
}
22
23
print $fh $_ if $fh ;
@@ -36,78 +37,113 @@ use warnings 'redefine';
36
37
$: :QUIET = 1;
37
38
38
39
# $Rex::Logger::no_color = 1;
39
- my $logfile = File::Spec-> catfile($testdir , ' log' );
40
+ my $logfile = File::Spec-> catfile( $testdir , ' log' );
40
41
Rex::Config-> set_log_filename($logfile );
41
42
42
-
43
43
# NOW TEST
44
44
45
45
# No Rexfile warning (via Rex::Logger)
46
- Rex::CLI::load_rexfile(File::Spec-> catfile($testdir , ' no_Rexfile' ) );
46
+ Rex::CLI::load_rexfile( File::Spec-> catfile( $testdir , ' no_Rexfile' ) );
47
47
my $content = _get_log();
48
- like($content , qr / WARN - No Rexfile found/ , ' No Rexfile warning (via logger)' );
48
+ like( $content , qr / WARN - No Rexfile found/ ,
49
+ ' No Rexfile warning (via logger)' );
49
50
50
51
# Valid Rexfile
51
52
_reset_test();
52
53
output_like {
53
- Rex::CLI::load_rexfile(File::Spec-> catfile($testdir , ' Rexfile_noerror' ));
54
- } qr / ^$ / , qr / ^$ / , ' No stdout/stderr messages on valid Rexfile' ;
54
+ Rex::CLI::load_rexfile( File::Spec-> catfile( $testdir , ' Rexfile_noerror' ) );
55
+ }
56
+ qr / ^$ / , qr / ^$ / , ' No stdout/stderr messages on valid Rexfile' ;
55
57
$content = _get_log();
56
- is($content , ' ' , ' No warnings on valid Rexfile (via logger)' );
58
+ is( $content , ' ' , ' No warnings on valid Rexfile (via logger)' );
57
59
58
60
# Rexfile with warnings
59
61
_reset_test();
60
62
output_like {
61
- Rex::CLI::load_rexfile(File::Spec-> catfile($testdir , ' Rexfile_warnings' ));
62
- } qr / ^$ / , qr / ^$ / , ' No stdout/stderr messages on Rexfile with warnings' ;
63
+ Rex::CLI::load_rexfile( File::Spec-> catfile( $testdir , ' Rexfile_warnings' ) );
64
+ }
65
+ qr / ^$ / , qr / ^$ / , ' No stdout/stderr messages on Rexfile with warnings' ;
63
66
$content = _get_log();
64
- ok(!$exit_was_called , ' sub load_rexfile() not exit' );
65
- like($content , qr / WARN - You have some code warnings/ , ' Code warnings via logger' );
66
- like($content , qr / This is warning/ , ' warn() warning via logger' );
67
- like($content , qr / Use of uninitialized value \$ undef/ , ' perl warning via logger' );
68
- unlike($content , qr # at /loader/0x# , ' loader prefix is filtered in warnings report' );
67
+ ok( !$exit_was_called , ' sub load_rexfile() not exit' );
68
+ like(
69
+ $content ,
70
+ qr / WARN - You have some code warnings/ ,
71
+ ' Code warnings via logger'
72
+ );
73
+ like( $content , qr / This is warning/ , ' warn() warning via logger' );
74
+ like(
75
+ $content ,
76
+ qr / Use of uninitialized value \$ undef/ ,
77
+ ' perl warning via logger'
78
+ );
79
+ unlike(
80
+ $content ,
81
+ qr # at /loader/0x# ,
82
+ ' loader prefix is filtered in warnings report'
83
+ );
69
84
70
85
# Rexfile with fatal errors
71
86
_reset_test();
72
87
output_like {
73
- Rex::CLI::load_rexfile(File::Spec-> catfile($testdir , ' Rexfile_fatal' ));
74
- } qr / ^$ / , qr / ^$ / , ' No stdout/stderr messages on Rexfile with errors' ;
88
+ Rex::CLI::load_rexfile( File::Spec-> catfile( $testdir , ' Rexfile_fatal' ) );
89
+ }
90
+ qr / ^$ / , qr / ^$ / , ' No stdout/stderr messages on Rexfile with errors' ;
75
91
$content = _get_log();
76
- ok($exit_was_called , ' sub load_rexfile() aborts' );
77
- like($content , qr / ERROR - Compile time errors/ , ' Fatal errors via logger' );
78
- like($content , qr / syntax error at/ , ' syntax error is fatal error via logger' );
79
- unlike($content , qr # at /loader/0x# , ' loader prefix is filtered in errors report' );
92
+ ok( $exit_was_called , ' sub load_rexfile() aborts' );
93
+ like( $content , qr / ERROR - Compile time errors/ , ' Fatal errors via logger' );
94
+ like( $content , qr / syntax error at/ , ' syntax error is fatal error via logger' );
95
+ unlike(
96
+ $content ,
97
+ qr # at /loader/0x# ,
98
+ ' loader prefix is filtered in errors report'
99
+ );
80
100
81
101
# Now print messages to STDERR/STDOUT
82
102
# Valid Rexfile
83
103
_reset_test();
84
104
output_like {
85
- Rex::CLI::load_rexfile(File::Spec-> catfile($testdir , ' Rexfile_noerror_print' ));
86
- } qr / ^This is STDOUT message$ / , qr / ^This is STDERR message$ / , ' Correct stdout/stderr messages printed from valid Rexfile' ;
105
+ Rex::CLI::load_rexfile(
106
+ File::Spec-> catfile( $testdir , ' Rexfile_noerror_print' ) );
107
+ }
108
+ qr / ^This is STDOUT message$ / , qr / ^This is STDERR message$ / ,
109
+ ' Correct stdout/stderr messages printed from valid Rexfile' ;
87
110
$content = _get_log();
88
- is($content , ' ' , ' No warnings via logger on valid Rexfile that print messages' );
111
+ is( $content , ' ' ,
112
+ ' No warnings via logger on valid Rexfile that print messages' );
89
113
90
114
# Rexfile with warnings
91
115
_reset_test();
92
116
output_like {
93
- Rex::CLI::load_rexfile(File::Spec-> catfile($testdir , ' Rexfile_warnings_print' ));
94
- } qr / ^This is STDOUT message$ / , qr / ^This is STDERR message$ / , ' Correct stdout/stderr messages printed from Rexfile with warnings' ;
117
+ Rex::CLI::load_rexfile(
118
+ File::Spec-> catfile( $testdir , ' Rexfile_warnings_print' ) );
119
+ }
120
+ qr / ^This is STDOUT message$ / , qr / ^This is STDERR message$ / ,
121
+ ' Correct stdout/stderr messages printed from Rexfile with warnings' ;
95
122
$content = _get_log();
96
- like($content , qr / WARN - You have some code warnings/ , ' Code warnings exist via logger' );
123
+ like(
124
+ $content ,
125
+ qr / WARN - You have some code warnings/ ,
126
+ ' Code warnings exist via logger'
127
+ );
97
128
98
129
# Rexfile with fatal errors
99
130
_reset_test();
100
131
output_like {
101
- Rex::CLI::load_rexfile(File::Spec-> catfile($testdir , ' Rexfile_fatal_print' ));
102
- } qr / ^$ / , qr / ^$ / , ' No stdout/stderr messages printed from Rexfile that has errors' ;
132
+ Rex::CLI::load_rexfile(
133
+ File::Spec-> catfile( $testdir , ' Rexfile_fatal_print' ) );
134
+ }
135
+ qr / ^$ / , qr / ^$ / ,
136
+ ' No stdout/stderr messages printed from Rexfile that has errors' ;
103
137
$content = _get_log();
104
- ok($exit_was_called , ' sub load_rexfile() aborts' );
105
- like($content , qr / ERROR - Compile time errors/ , ' Fatal errors exist via logger' );
106
-
138
+ ok( $exit_was_called , ' sub load_rexfile() aborts' );
139
+ like(
140
+ $content ,
141
+ qr / ERROR - Compile time errors/ ,
142
+ ' Fatal errors exist via logger'
143
+ );
107
144
108
145
done_testing;
109
146
110
-
111
147
# from logger.t
112
148
sub _get_log {
113
149
local $/ ;
@@ -121,9 +157,11 @@ sub _get_log {
121
157
122
158
sub _reset_test {
123
159
$exit_was_called = undef ;
160
+
124
161
# reset log
125
162
open my $fh , ' >' , $logfile or die $! ;
126
163
close $fh ;
164
+
127
165
# reset require
128
166
delete $INC {' __Rexfile__.pm' };
129
167
}
0 commit comments