8 use vars qw( $required );
9 use Test::More tests => 18;
11 use_ok( 'ExtUtils::Mkbootstrap' );
13 # Mkbootstrap makes a backup copy of "$_[0].bs" if it exists and is non-zero
16 if (open(OUT, '>mkboot.bs')) {
18 print OUT 'meaningless text';
23 skip("could not make dummy .bs file: $!", 2) unless $file_is_ready;
25 Mkbootstrap('mkboot');
26 ok( -s 'mkboot.bso', 'Mkbootstrap should backup the .bs file' );
28 if (open(IN, 'mkboot.bso')) {
29 chomp ($file_is_ready = <IN>);
33 is( $file_is_ready, 'meaningless text', 'backup should be a perfect copy' );
37 # if it doesn't exist or is zero bytes in size, it won't be backed up
38 Mkbootstrap('fakeboot');
39 ok( !( -f 'fakeboot.bso' ), 'Mkbootstrap should not backup an empty file' );
42 my $out = tie *STDOUT, 'TieOut';
44 # with $Verbose set, it should print status messages about libraries
45 $ExtUtils::Mkbootstrap::Verbose = 1;
47 is( $out->read, "\tbsloadlibs=\n", 'should report libraries in Verbose mode' );
49 Mkbootstrap('', 'foo');
50 like( $out->read, qr/bsloadlibs=foo/, 'should still report libraries' );
53 # if ${_[0]}_BS exists, require it
54 $file_is_ready = open(OUT, '>boot_BS');
57 skip("cannot open boot_BS for writing: $!", 1) unless $file_is_ready;
59 print OUT '$main::required = 1';
63 ok( $required, 'baseext_BS file should be require()d' );
67 # if there are any arguments, open a file named baseext.bs
68 $file_is_ready = open(OUT, '>dasboot.bs');
71 skip("cannot make dasboot.bs: $!", 5) unless $file_is_ready;
73 # if it can't be opened for writing, we want to prove that it'll die
75 chmod 0444, 'dasboot.bs';
78 skip("can write readonly files", 1) if -w 'dasboot.bs';
80 eval{ Mkbootstrap('dasboot', 1) };
81 like( $@, qr/Unable to open dasboot\.bs/, 'should die given bad filename' );
84 # now put it back like it was
85 chmod 0777, 'dasboot.bs';
86 eval{ Mkbootstrap('dasboot', 'myarg') };
87 is( $@, '', 'should not die, given good filename' );
89 # red and reed (a visual pun makes tests worth reading)
90 my $read = $out->read();
91 like( $read, qr/Writing dasboot.bs/, 'should print status' );
92 like( $read, qr/containing: my/, 'should print verbose status on request' );
94 # now be tricky, and set the status for the next skip block
95 $file_is_ready = open(IN, 'dasboot.bs');
96 ok( $file_is_ready, 'should have written a new .bs file' );
101 skip("cannot read .bs file: $!", 2) unless $file_is_ready;
103 my $file = do { local $/ = <IN> };
105 # filename should be in header
106 like( $file, qr/# dasboot DynaLoader/, 'file should have boilerplate' );
108 # should print arguments within this array
109 like( $file, qr/qw\(myarg\);/, 'should have written array to file' );
113 # overwrite this file (may whack portability, but the name's too good to waste)
114 $file_is_ready = open(OUT, '>dasboot.bs');
117 skip("cannot make dasboot.bs again: $!", 1) unless $file_is_ready;
120 # if $DynaLoader::bscode is set, write its contents to the file
121 # localize the variable to prevent "used only once"
122 local $DynaLoader::bscode;
123 $DynaLoader::bscode = 'Wall';
124 $ExtUtils::Mkbootstrap::Verbose = 0;
126 # if arguments contain '-l' or '-L' or '-R' print dl_findfile message
127 eval{ Mkbootstrap('dasboot', '-Larry') };
128 is( $@, '', 'should be able to open a file again');
130 $file_is_ready = open(IN, 'dasboot.bs');
134 skip("cannot open dasboot.bs for reading: $!", 3) unless $file_is_ready;
136 my $file = do { local $/ = <IN> };
137 is( $out->read, "Writing dasboot.bs\n", 'should hush without Verbose set' );
139 # and find our hidden tribute to a fine example
140 like( $file, qr/dl_findfile.+Larry/s, 'should load libraries if needed' );
141 like( $file, qr/Wall\n1;\n/ms, 'should write $DynaLoader::bscode if set' );
148 # clean things up, even on VMS
149 1 while unlink(qw( mkboot.bso boot_BS dasboot.bs .bs ));
155 bless( \(my $scalar), $_[0]);
160 $$self .= join('', @_);
165 return substr($$self, 0, length($$self), '');