1b39c5158Smillert#!./perl -w 2b39c5158Smillert 36fb12b70Safresh1# What does this test? 46fb12b70Safresh1# This tests the well-formed-ness of the MANIFEST file. 56fb12b70Safresh1# 66fb12b70Safresh1# Why do we test this? 76fb12b70Safresh1# TK 86fb12b70Safresh1# 96fb12b70Safresh1# It's broken - how do I fix it? 106fb12b70Safresh1# If MANIFEST is not sorted properly, you will get this error output: 116fb12b70Safresh1# got ''MANIFEST' is NOT sorted properly 126fb12b70Safresh1# # ' 136fb12b70Safresh1# # expected /(?^:is sorted properly)/ 146fb12b70Safresh1# 156fb12b70Safresh1# To correct this, run either: 166fb12b70Safresh1# 176fb12b70Safresh1# ./perl -Ilib Porting/manisort -o MANIFEST MANIFEST 186fb12b70Safresh1# 196fb12b70Safresh1# which will output "'MANIFEST' is NOT sorted properly" but which will 206fb12b70Safresh1# correct the problem; or: 216fb12b70Safresh1# 229f11ffb7Safresh1# make manisort 236fb12b70Safresh1# 246fb12b70Safresh1# which will output "WARNING: re-sorting MANIFEST" but which will also 256fb12b70Safresh1# correct the problem. 26b39c5158Smillert 276fb12b70Safresh1use Config; 28b39c5158SmillertBEGIN { 29898184e3Ssthen @INC = '..' if -f '../TestInit.pm'; 30b39c5158Smillert} 3191f110e0Safresh1use TestInit qw(T); # T is chdir to the top level 32b39c5158Smillert 339f11ffb7Safresh1require './t/test.pl'; 34b39c5158Smillert 356fb12b70Safresh1skip_all("Cross-compiling, the entire source might not be available") 366fb12b70Safresh1 if $Config{usecrosscompile}; 376fb12b70Safresh1 386fb12b70Safresh1 39b39c5158Smillertplan('no_plan'); 40b39c5158Smillert 41898184e3Ssthenmy $manifest = 'MANIFEST'; 42b39c5158Smillert 43b39c5158Smillertopen my $m, '<', $manifest or die "Can't open '$manifest': $!"; 44898184e3Ssthenmy @files; 45b39c5158Smillert# Test that MANIFEST uses tabs - not spaces - after the name of the file. 46b39c5158Smillertwhile (<$m>) { 47b39c5158Smillert chomp; 48898184e3Ssthen unless( /\s/ ) { 49898184e3Ssthen push @files, $_; 50898184e3Ssthen # no need for further tests on lines without whitespace (i.e., filename only) 51898184e3Ssthen next; 52898184e3Ssthen } 53b39c5158Smillert my ($file, $separator) = /^(\S+)(\s+)/; 54898184e3Ssthen push @files, $file; 55898184e3Ssthen 56b39c5158Smillert isnt($file, undef, "Line $. doesn't start with a blank") or next; 57898184e3Ssthen ok(-f $file, "File $file exists"); 58b39c5158Smillert if ($separator !~ tr/\t//c) { 59b39c5158Smillert # It's all tabs 60b39c5158Smillert next; 61b39c5158Smillert } elsif ($separator !~ tr/ //c) { 62b39c5158Smillert # It's all spaces 63*e0680481Safresh1 fail("Spaces in entry for $file in MANIFEST at line $. (run `make manisort` to fix)"); 64b39c5158Smillert } elsif ($separator =~ tr/\t//) { 65*e0680481Safresh1 fail("Mixed tabs and spaces in entry for $file in MANIFEST at line $. (run `make manisort` to fix)"); 66b39c5158Smillert } else { 67*e0680481Safresh1 fail("Odd whitespace in entry for $file in MANIFEST at line $. (run `make manisort` to fix)"); 68b39c5158Smillert } 69b39c5158Smillert} 70b39c5158Smillert 71b39c5158Smillertclose $m or die $!; 72b39c5158Smillert 73b39c5158Smillert# Test that MANIFEST is properly sorted 74b39c5158SmillertSKIP: { 75b8851fccSafresh1 skip("Sorting order is different under EBCDIC", 1) if $::IS_EBCDIC || $::IS_EBCDIC; 76898184e3Ssthen skip("'Porting/manisort' not found", 1) if (! -f 'Porting/manisort'); 77b39c5158Smillert 78898184e3Ssthen my $result = runperl('progfile' => 'Porting/manisort', 79898184e3Ssthen 'args' => [ '-c', $manifest ], 806fb12b70Safresh1 'stderr' => 1, 816fb12b70Safresh1 'nolib' => 1 ); 82b39c5158Smillert 83b39c5158Smillert like($result, qr/is sorted properly/, 'MANIFEST sorted properly'); 84b39c5158Smillert} 85b39c5158Smillert 86898184e3SsthenSKIP: { 87898184e3Ssthen find_git_or_skip(6); 889f11ffb7Safresh1 my %seen; # De-dup ls-files output (can appear more than once) 89eac174f2Safresh1 my @repo= grep { 90eac174f2Safresh1 chomp(); 9156d68f1eSafresh1 !m{\.git_patch$} && 9256d68f1eSafresh1 !m{\.gitattributes$} && 93b46d8ef2Safresh1 !m{\.gitignore$} && 9456d68f1eSafresh1 !m{\.mailmap$} && 9556d68f1eSafresh1 !m{^\.github/} && 96eac174f2Safresh1 -e $_ && 97b46d8ef2Safresh1 !$seen{$_}++ 98eac174f2Safresh1 } `git ls-files`; 99898184e3Ssthen skip("git ls-files didnt work",3) 100898184e3Ssthen if !@repo; 101898184e3Ssthen is( 0+@repo, 0+@files, "git ls-files gives the same number of files as MANIFEST lists"); 102b8851fccSafresh1 my %repo; 103b8851fccSafresh1 ++$repo{$_} for @repo; 104b8851fccSafresh1 my %mani; 105b8851fccSafresh1 ++$mani{$_} for @files; 106b8851fccSafresh1 is( 0+keys %mani, 0+@files, "no duplicate files in MANIFEST") 107b8851fccSafresh1 or diag(join("\n ", "Duplicates:",grep $mani{$_} > 1, keys %mani)); 108898184e3Ssthen delete $mani{$_} for @repo; 109898184e3Ssthen delete $repo{$_} for @files; 110898184e3Ssthen my @not_in_mani= keys %repo; 111898184e3Ssthen my @still_in_mani= keys %mani; 112898184e3Ssthen 113898184e3Ssthen is( 0+@not_in_mani, 0, "Nothing added to the repo that isn't in MANIFEST"); 114898184e3Ssthen is( "not in MANIFEST: @not_in_mani", "not in MANIFEST: ", 115898184e3Ssthen "Nothing added to the repo that isn't in MANIFEST"); 116898184e3Ssthen is( 0+@still_in_mani, 0, "Nothing in the MANIFEST that isn't tracked by git"); 117898184e3Ssthen is( "should not be in MANIFEST: @still_in_mani", "should not be in MANIFEST: ", 118898184e3Ssthen "Nothing in the MANIFEST that isn't tracked by git"); 119898184e3Ssthen 120898184e3Ssthen} 121898184e3Ssthen 122b39c5158Smillert# EOF 123