xref: /openbsd/gnu/usr.bin/perl/t/porting/manifest.t (revision 898184e3)
1#!./perl -w
2
3# Test the well-formed-ness of the MANIFEST file.
4
5BEGIN {
6    @INC = '..' if -f '../TestInit.pm';
7}
8use TestInit qw(T A); # T is chdir to the top level, A makes paths absolute
9
10require 't/test.pl';
11
12plan('no_plan');
13
14my $manifest = 'MANIFEST';
15
16open my $m, '<', $manifest or die "Can't open '$manifest': $!";
17my @files;
18# Test that MANIFEST uses tabs - not spaces - after the name of the file.
19while (<$m>) {
20    chomp;
21    unless( /\s/ ) {
22        push @files, $_;
23        # no need for further tests on lines without whitespace (i.e., filename only)
24        next;
25    }
26    my ($file, $separator) = /^(\S+)(\s+)/;
27    push @files, $file;
28
29    isnt($file, undef, "Line $. doesn't start with a blank") or next;
30    ok(-f $file, "File $file exists");
31    if ($separator !~ tr/\t//c) {
32	# It's all tabs
33	next;
34    } elsif ($separator !~ tr/ //c) {
35	# It's all spaces
36	fail("Spaces in entry for $file");
37    } elsif ($separator =~ tr/\t//) {
38	fail("Mixed tabs and spaces in entry for $file");
39    } else {
40	fail("Odd whitespace in entry for $file");
41    }
42}
43
44close $m or die $!;
45
46# Test that MANIFEST is properly sorted
47SKIP: {
48    skip("'Porting/manisort' not found", 1) if (! -f 'Porting/manisort');
49
50    my $result = runperl('progfile' => 'Porting/manisort',
51                         'args'     => [ '-c', $manifest ],
52                         'stderr'   => 1);
53
54    like($result, qr/is sorted properly/, 'MANIFEST sorted properly');
55}
56
57SKIP: {
58    find_git_or_skip(6);
59    chomp(my @repo= grep { !/\.gitignore$/ } `git ls-files`);
60    skip("git ls-files didnt work",3)
61        if !@repo;
62    is( 0+@repo, 0+@files, "git ls-files gives the same number of files as MANIFEST lists");
63    my %repo= map { $_ => 1 } @repo;
64    my %mani= map { $_ => 1 } @files;
65    is( 0+keys %mani, 0+@files, "no duplicate files in MANIFEST");
66    delete $mani{$_} for @repo;
67    delete $repo{$_} for @files;
68    my @not_in_mani= keys %repo;
69    my @still_in_mani= keys %mani;
70
71    is( 0+@not_in_mani, 0, "Nothing added to the repo that isn't in MANIFEST");
72    is( "not in MANIFEST: @not_in_mani", "not in MANIFEST: ",
73        "Nothing added to the repo that isn't in MANIFEST");
74    is( 0+@still_in_mani, 0, "Nothing in the MANIFEST that isn't tracked by git");
75    is( "should not be in MANIFEST: @still_in_mani", "should not be in MANIFEST: ",
76        "Nothing in the MANIFEST that isn't tracked by git");
77
78}
79
80# EOF
81