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