5 use MBTest tests => 29;
7 blib_load('Module::Build');
8 blib_load('Module::Build::ConfigData');
9 my $have_yaml = Module::Build::ConfigData->feature('YAML_support');
11 #########################
13 my $tmp = MBTest->tmpdir;
16 my $dist = DistGen->new();
17 $dist->change_build_pl
19 module_name => 'Simple',
20 scripts => [ 'script' ],
22 requires => { 'File::Spec' => 0 },
25 $dist->add_file( 'MANIFEST.SKIP', <<'---' );
28 $dist->add_file( 'script', <<'---' );
30 print "Hello, World!\n";
32 $dist->add_file( 'lib/Simple/Script.PL', <<'---' );
36 open FH, "> $filename" or die "Can't create $filename: $!";
37 print FH "Contents: $filename\n";
45 #########################
47 my $mb = Module::Build->new_from_context;
49 is $mb->license, 'perl';
51 # Make sure cleanup files added before create_build_script() get respected
52 $mb->add_to_cleanup('before_script');
54 eval {$mb->create_build_script};
56 ok -e $mb->build_script;
58 my $dist_dir = 'Simple-0.01';
60 # VMS in traditional mode needs the $dist_dir name to not have a '.' in it
61 # as this is a directory delimiter. In extended character set mode the dot
62 # is permitted for Unix format file specifications.
66 if (eval 'require VMS::Feature') {
67 $vms_efs = VMS::Feature::current("efs_charset");
69 my $efs_charset = $ENV{'DECC$EFS_CHARSET'} || '';
70 $vms_efs = $efs_charset =~ /^[ET1]/i;
72 $Is_VMS_noefs = 0 if $vms_efs;
74 $dist_dir = 'Simple-0_01';
78 is $mb->dist_dir, $dist_dir;
80 # The 'cleanup' file doesn't exist yet
81 ok grep {$_ eq 'before_script'} $mb->cleanup;
83 $mb->add_to_cleanup('save_out');
85 # The 'cleanup' file now exists
86 ok grep {$_ eq 'before_script'} $mb->cleanup;
87 ok grep {$_ eq 'save_out' } $mb->cleanup;
90 # Make sure verbose=>1 works
93 stdout_of( sub { $mb->dispatch('test', verbose => 1) } )
95 $all_ok &&= is($@, '');
96 $all_ok &&= like($output, qr/all tests successful/i);
98 # This is the output of lib/Simple/Script.PL
99 $all_ok &&= ok(-e $mb->localize_file_path('lib/Simple/Script'));
102 # We use diag() so Test::Harness doesn't get confused.
103 diag("vvvvvvvvvvvvvvvvvvvvv Simple/t/basic.t output vvvvvvvvvvvvvvvvvvvvv");
105 diag("^^^^^^^^^^^^^^^^^^^^^ Simple/t/basic.t output ^^^^^^^^^^^^^^^^^^^^^");
110 skip( 'YAML_support feature is not enabled', 7 ) unless $have_yaml;
113 stdout_of( sub { $mb->dispatch('disttest') } )
117 # After a test, the distdir should contain a blib/ directory
118 ok -e File::Spec->catdir('Simple-0.01', 'blib');
120 eval {$mb->dispatch('distdir')};
123 # The 'distdir' should contain a lib/ directory
124 ok -e File::Spec->catdir('Simple-0.01', 'lib');
126 # The freshly run 'distdir' should never contain a blib/ directory, or
127 # else it could get into the tarball
128 ok ! -e File::Spec->catdir('Simple-0.01', 'blib');
130 # Make sure all of the above was done by the new version of Module::Build
131 my $fh = IO::File->new(File::Spec->catfile($dist->dirname, 'META.yml'));
132 my $contents = do {local $/; <$fh>};
133 $contents =~ /Module::Build version ([0-9_.]+)/m;
134 cmp_ok $1, '==', $mb->VERSION, "Check version used to create META.yml: $1 == " . $mb->VERSION;
137 skip( "Archive::Tar 1.08+ not installed", 1 )
138 unless eval { require Archive::Tar && Archive::Tar->VERSION(1.08); 1 };
139 $mb->add_to_cleanup($mb->dist_dir . ".tar.gz");
140 eval {$mb->dispatch('dist')};
147 # Make sure the 'script' file was recognized as a script.
148 my $scripts = $mb->script_files;
149 ok $scripts->{script};
151 # Check that a shebang line is rewritten
152 my $blib_script = File::Spec->catfile( qw( blib script script ) );
156 skip("We do not rewrite shebang on VMS", 1) if $^O eq 'VMS';
157 my $fh = IO::File->new($blib_script);
158 my $first_line = <$fh>;
159 isnt $first_line, "#!perl -w\n", "should rewrite the shebang line";
164 eval {$mb->dispatch('realclean')};
167 ok ! -e $mb->build_script;
168 ok ! -e $mb->config_dir;
169 ok ! -e $mb->dist_dir;
172 skip( 'Windows-only test', 4 ) unless $^O =~ /^MSWin/;
174 my $script_data = <<'---';
179 $dist = DistGen->new();
180 $dist->change_build_pl({
181 module_name => 'Simple',
182 scripts => [ 'bin/script.bat' ],
186 $dist->add_file( 'bin/script.bat', $script_data );
191 $mb = Module::Build->new_from_context;
194 eval{ $mb->dispatch('build') };
197 my $script_file = File::Spec->catfile( qw(blib script), 'script.bat' );
198 ok -f $script_file, "Native batch file copied to 'scripts'";
200 my $out = slurp( $script_file );
201 is $out, $script_data, ' unmodified by pl2bat';