xref: /openbsd/gnu/usr.bin/perl/t/porting/manifest.t (revision a6445c1d)
1#!./perl -w
2
3# What does this test?
4# This tests the well-formed-ness of the MANIFEST file.
5#
6# Why do we test this?
7# TK
8#
9# It's broken - how do I fix it?
10# If MANIFEST is not sorted properly, you will get this error output:
11#      got ''MANIFEST' is NOT sorted properly
12#      # '
13#      # expected /(?^:is sorted properly)/
14#
15# To correct this, run either:
16#
17#   ./perl -Ilib Porting/manisort -o MANIFEST MANIFEST
18#
19# which will output "'MANIFEST' is NOT sorted properly" but which will
20# correct the problem; or:
21#
22#   make manifest
23#
24# which will output "WARNING: re-sorting MANIFEST" but which will also
25# correct the problem.
26
27use Config;
28BEGIN {
29    @INC = '..' if -f '../TestInit.pm';
30}
31use TestInit qw(T); # T is chdir to the top level
32
33require 't/test.pl';
34
35skip_all("Cross-compiling, the entire source might not be available")
36    if $Config{usecrosscompile};
37
38
39plan('no_plan');
40
41my $manifest = 'MANIFEST';
42
43open my $m, '<', $manifest or die "Can't open '$manifest': $!";
44my @files;
45# Test that MANIFEST uses tabs - not spaces - after the name of the file.
46while (<$m>) {
47    chomp;
48    unless( /\s/ ) {
49        push @files, $_;
50        # no need for further tests on lines without whitespace (i.e., filename only)
51        next;
52    }
53    my ($file, $separator) = /^(\S+)(\s+)/;
54    push @files, $file;
55
56    isnt($file, undef, "Line $. doesn't start with a blank") or next;
57    ok(-f $file, "File $file exists");
58    if ($separator !~ tr/\t//c) {
59	# It's all tabs
60	next;
61    } elsif ($separator !~ tr/ //c) {
62	# It's all spaces
63	fail("Spaces in entry for $file");
64    } elsif ($separator =~ tr/\t//) {
65	fail("Mixed tabs and spaces in entry for $file");
66    } else {
67	fail("Odd whitespace in entry for $file");
68    }
69}
70
71close $m or die $!;
72
73# Test that MANIFEST is properly sorted
74SKIP: {
75    skip("'Porting/manisort' not found", 1) if (! -f 'Porting/manisort');
76
77    my $result = runperl('progfile' => 'Porting/manisort',
78                         'args'     => [ '-c', $manifest ],
79                         'stderr'   => 1,
80                         'nolib'    => 1 );
81
82    like($result, qr/is sorted properly/, 'MANIFEST sorted properly');
83}
84
85SKIP: {
86    find_git_or_skip(6);
87    chomp(my @repo= grep { !/\.gitignore$/ } `git ls-files`);
88    skip("git ls-files didnt work",3)
89        if !@repo;
90    is( 0+@repo, 0+@files, "git ls-files gives the same number of files as MANIFEST lists");
91    my %repo= map { $_ => 1 } @repo;
92    my %mani= map { $_ => 1 } @files;
93    is( 0+keys %mani, 0+@files, "no duplicate files in MANIFEST");
94    delete $mani{$_} for @repo;
95    delete $repo{$_} for @files;
96    my @not_in_mani= keys %repo;
97    my @still_in_mani= keys %mani;
98
99    is( 0+@not_in_mani, 0, "Nothing added to the repo that isn't in MANIFEST");
100    is( "not in MANIFEST: @not_in_mani", "not in MANIFEST: ",
101        "Nothing added to the repo that isn't in MANIFEST");
102    is( 0+@still_in_mani, 0, "Nothing in the MANIFEST that isn't tracked by git");
103    is( "should not be in MANIFEST: @still_in_mani", "should not be in MANIFEST: ",
104        "Nothing in the MANIFEST that isn't tracked by git");
105
106}
107
108# EOF
109