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();
38 ### this *has* to be set, as we're testing the contents of the file
39 ### to see if it matches what's stored in the buffer.
40 local $CPANPLUS::Error::MSG_FH = output_handle();
41 local $CPANPLUS::Error::ERROR_FH = output_handle();
43 ok( -e $file, "Output redirect file exists" );
44 ok( !-s $file, " Output file is empty" );
46 ### print a msg & error ###
47 for my $name ( keys %$map ) {
48 my $sub = __PACKAGE__->can( $name );
50 $sub->( $map->{$name}->[0], 1 );
53 ### must close it for Win32 tests!
56 ok( -s $file, " Output file now has size" );
58 my $fh = FileHandle->new( $file );
59 ok( $fh, "Opened output file for reading " );
61 my $contents = do { local $/; <$fh> };
62 my $string = CPANPLUS::Error->stack_as_string;
63 my $trace = CPANPLUS::Error->stack_as_string(1);
65 ok( $contents, " Got the file contents" );
66 ok( $string, "Got the error stack as string" );
69 for my $type ( keys %$map ) {
70 my $tag = $type; $tag =~ s/.+?_//g;
72 for my $str (@{ $map->{$type} } ) {
73 like( $contents, qr/\U\Q$tag/,
74 " Contents matches for '$type'" );
75 like( $contents, qr/\Q$str/,
76 " Contents matches for '$type'" );
78 like( $string, qr/\U\Q$tag/,
79 " String matches for '$type'" );
80 like( $string, qr/\Q$str/,
81 " String matches for '$type'" );
83 like( $trace, qr/\U\Q$tag/,
84 " Trace matches for '$type'" );
85 like( $trace, qr/\Q$str/,
86 " Trace matches for '$type'" );
88 ### extra trace tests ###
89 like( $trace, qr/\Q$str\E.*?\Q$str/s,
90 " Trace holds proper traceback" );
91 like( $trace, qr/\Q$0/,
92 " Trace holds program name" );
93 like( $trace, qr/line/,
94 " Trace holds line number information" );
98 ### check the stack, flush it, check again ###
99 is( scalar(()=CPANPLUS::Error->stack), scalar(keys(%$map)),
100 "All items on stack" );
101 is( scalar(()=CPANPLUS::Error->flush), scalar(keys(%$map)),
102 "All items flushed" );
103 is( scalar(()=CPANPLUS::Error->stack), 0,
104 "No items on stack" );
110 # c-indentation-style: bsd
112 # indent-tabs-mode: nil
114 # vim: expandtab shiftwidth=4: