This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix O_CREAT without O_TRUNC in cpan/autodie/t/utf8_open.t
[perl5.git] / t / porting / utils.t
CommitLineData
48eabb99
NC
1#!./perl -w
2
3# What does this test?
4# This checks that all the perl "utils" don't have embarrassing syntax errors
5#
6# Why do we test this?
7# Right now, without this, it's possible to pass the all the regression tests
8# even if one has introduced syntax errors into scripts such as installperl
9# or installman. No tests fail, so it's fair game to push the commit.
10# Obviously this breaks installing perl, but we won't spot this.
11# Whilst we can't easily test that the various scripts *work*, we can at least
12# check that we've not made any trivial screw ups.
13#
14# It's broken - how do I fix it?
15# Presumably it's failed because some (other) code that you changed was (also)
16# used by one of the utility scripts. So you'll have to manually test that
17# script.
18
19BEGIN {
20 @INC = '..' if -f '../TestInit.pm';
21}
22use TestInit qw(T); # T is chdir to the top level
23use strict;
24
25require 't/test.pl';
26
58df49fa
RS
27# It turns out that, since the default @INC will include your old 5.x libs, if
28# you have them, the Porting utils might load a library that no longer compiles
29# clean. This actually happened, with Local::Maketext::Lexicon from a 5.10.0
30# preventing 5.16.0-RC0 from testing successfully. This test is really only
31# needed for porters, anyway. -- rjbs, 2012-05-10
32find_git_or_skip('all');
33
48eabb99
NC
34my @maybe;
35
36open my $fh, '<', 'MANIFEST' or die "Can't open MANIFEST: $!";
37while (<$fh>) {
38 push @maybe, $1 if m!^(Porting/\S+)!;
39}
40close $fh or die $!;
41
42open $fh, '<', 'utils.lst' or die "Can't open utils.lst: $!";
43while (<$fh>) {
44 die unless m!^(\S+)!;
45 push @maybe, $1;
238d2546 46 $maybe[$#maybe] .= '.com' if $^O eq 'VMS';
48eabb99
NC
47}
48close $fh or die $!;
49
32388cc3
NC
50# regen/uconfig_h.pl is here because it's not possible to test it by running
51# it on non-*nix platforms, as it requires a Bourne shell. As it's the only file
52# in regen/ which we can syntax check but can't run, it's simpler to add it to
53# the list here, than copy-paste the entire syntax-checking logic to
54# t/porting/regen.t
55my @victims = (qw(installman installperl regen_perly.pl regen/uconfig_h.pl));
48eabb99
NC
56my %excuses = (
57 'Porting/git-deltatool' => 'Git::Wrapper',
58 'Porting/podtidy' => 'Pod::Tidy',
ac1f638f 59 'Porting/leakfinder.pl' => 'XS::APItest',
48eabb99
NC
60 );
61
62foreach (@maybe) {
63 if (/\.p[lm]$/) {
64 push @victims, $_;
238d2546 65 } elsif ($_ !~ m{^x2p/a2p}) {
48eabb99
NC
66 # test_prep doesn't (yet) have a dependency on a2p, so it seems a bit
67 # silly adding one (and forcing it to be built) just so that we can open
68 # it and determine that it's *not* a perl program, and hence of no
69 # further interest to us.
70 open $fh, '<', $_ or die "Can't open '$_': $!";
71 my $line = <$fh>;
238d2546
CB
72 if ($line =~ m{^#!(?:\S*|/usr/bin/env\s+)perl}
73 || $^O eq 'VMS' && $line =~ m{^\$ perl}) {
48eabb99
NC
74 push @victims, $_;
75 } else {
76 print "# $_ isn't a Perl script\n";
77 }
78 }
79}
80
81printf "1..%d\n", scalar @victims;
82
83foreach my $victim (@victims) {
84 SKIP: {
48eabb99
NC
85 skip ("$victim uses $excuses{$victim}, so can't test with just core modules")
86 if $excuses{$victim};
87
88 my $got = runperl(switches => ['-c'], progfile => $victim, stderr => 1);
89 is($got, "$victim syntax OK\n", "$victim compiles");
90 }
91}
92
93# Local variables:
94# cperl-indent-level: 4
95# indent-tabs-mode: nil
96# End:
97#
98# ex: set ts=8 sts=4 sw=4 et: