1 ### make sure we can find our conf.pl file
4 require "$FindBin::Bin/inc/conf.pl";
8 use Test::More 'no_plan';
13 my $conf = gimme_conf();
16 cp_msg => ["This is just a test message"],
17 msg => ["This is just a test message"],
18 cp_error => ["This is just a test error"],
19 error => ["This is just a test error"],
22 ### check if CPANPLUS::Error can do what we expect
23 { for my $name ( keys %$map ) {
24 can_ok('CPANPLUS::Error', $name);
25 can_ok('main', $name); # did it get exported?
29 ### make sure we start with an empty stack
30 { CPANPLUS::Error->flush;
31 is( scalar(()=CPANPLUS::Error->stack), 0,
32 "Starting with empty stack" );
35 ### global variables test ###
36 { my $file = output_file();
37 unlink $file; # just in case
39 local $CPANPLUS::Error::MSG_FH = output_handle();
40 local $CPANPLUS::Error::ERROR_FH = output_handle();
42 ok( -e $file, "Output redirect file exists" );
43 ok( !-s $file, " Output file is empty" );
45 ### print a msg & error ###
46 for my $name ( keys %$map ) {
47 my $sub = __PACKAGE__->can( $name );
49 $sub->( $map->{$name}->[0], 1 );
52 ### must close it for Win32 tests!
55 ok( -s $file, " Output file now has size" );
57 my $fh = FileHandle->new( $file );
58 ok( $fh, "Opened output file for reading " );
60 my $contents = do { local $/; <$fh> };
61 my $string = CPANPLUS::Error->stack_as_string;
62 my $trace = CPANPLUS::Error->stack_as_string(1);
64 ok( $contents, " Got the file contents" );
65 ok( $string, "Got the error stack as string" );
68 for my $type ( keys %$map ) {
69 my $tag = $type; $tag =~ s/.+?_//g;
71 for my $str (@{ $map->{$type} } ) {
72 like( $contents, qr/\U\Q$tag/,
73 " Contents matches for '$type'" );
74 like( $contents, qr/\Q$str/,
75 " Contents matches for '$type'" );
77 like( $string, qr/\U\Q$tag/,
78 " String matches for '$type'" );
79 like( $string, qr/\Q$str/,
80 " String matches for '$type'" );
82 like( $trace, qr/\U\Q$tag/,
83 " Trace matches for '$type'" );
84 like( $trace, qr/\Q$str/,
85 " Trace matches for '$type'" );
87 ### extra trace tests ###
88 like( $trace, qr/\Q$str\E.*?\Q$str/s,
89 " Trace holds proper traceback" );
90 like( $trace, qr/\Q$0/,
91 " Trace holds program name" );
92 like( $trace, qr/line/,
93 " Trace holds line number information" );
97 ### check the stack, flush it, check again ###
98 is( scalar(()=CPANPLUS::Error->stack), scalar(keys(%$map)),
99 "All items on stack" );
100 is( scalar(()=CPANPLUS::Error->flush), scalar(keys(%$map)),
101 "All items flushed" );
102 is( scalar(()=CPANPLUS::Error->stack), 0,
103 "No items on stack" );
109 # c-indentation-style: bsd
111 # indent-tabs-mode: nil
113 # vim: expandtab shiftwidth=4: