This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
new perldelta
[perl5.git] / t / porting / manifest.t
CommitLineData
398f002c
NC
1#!./perl -w
2
deed50f2
JK
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#
17529fac 22# make manisort
deed50f2
JK
23#
24# which will output "WARNING: re-sorting MANIFEST" but which will also
25# correct the problem.
398f002c 26
3a73a075 27use Config;
398f002c 28BEGIN {
18388fdb 29 @INC = '..' if -f '../TestInit.pm';
398f002c 30}
ac976f88 31use TestInit qw(T); # T is chdir to the top level
398f002c 32
3d7c117d 33require './t/test.pl';
398f002c 34
3a73a075
BF
35skip_all("Cross-compiling, the entire source might not be available")
36 if $Config{usecrosscompile};
37
38
398f002c
NC
39plan('no_plan');
40
18388fdb 41my $manifest = 'MANIFEST';
398f002c
NC
42
43open my $m, '<', $manifest or die "Can't open '$manifest': $!";
dcab73c9 44my @files;
b8ca42e1 45# Test that MANIFEST uses tabs - not spaces - after the name of the file.
398f002c
NC
46while (<$m>) {
47 chomp;
dcab73c9
YO
48 unless( /\s/ ) {
49 push @files, $_;
50 # no need for further tests on lines without whitespace (i.e., filename only)
51 next;
52 }
4e86fc4b 53 my ($file, $separator) = /^(\S+)(\s+)/;
dcab73c9
YO
54 push @files, $file;
55
398f002c 56 isnt($file, undef, "Line $. doesn't start with a blank") or next;
18388fdb 57 ok(-f $file, "File $file exists");
4e86fc4b 58 if ($separator !~ tr/\t//c) {
398f002c
NC
59 # It's all tabs
60 next;
61 } elsif ($separator !~ tr/ //c) {
62 # It's all spaces
1c182948 63 fail("Spaces in entry for $file in MANIFEST at line $. (run `make manisort` to fix)");
398f002c 64 } elsif ($separator =~ tr/\t//) {
1c182948 65 fail("Mixed tabs and spaces in entry for $file in MANIFEST at line $. (run `make manisort` to fix)");
398f002c 66 } else {
1c182948 67 fail("Odd whitespace in entry for $file in MANIFEST at line $. (run `make manisort` to fix)");
398f002c
NC
68 }
69}
70
71close $m or die $!;
72
4e86fc4b
JH
73# Test that MANIFEST is properly sorted
74SKIP: {
ff23b6f8 75 skip("Sorting order is different under EBCDIC", 1) if $::IS_EBCDIC || $::IS_EBCDIC;
18388fdb 76 skip("'Porting/manisort' not found", 1) if (! -f 'Porting/manisort');
4e86fc4b 77
18388fdb
NC
78 my $result = runperl('progfile' => 'Porting/manisort',
79 'args' => [ '-c', $manifest ],
7f1eeb94
TC
80 'stderr' => 1,
81 'nolib' => 1 );
4e86fc4b
JH
82
83 like($result, qr/is sorted properly/, 'MANIFEST sorted properly');
84}
b8ca42e1 85
dcab73c9 86SKIP: {
7cadc1d0 87 find_git_or_skip(6);
af25b33d 88 my %seen; # De-dup ls-files output (can appear more than once)
bf28d609
YO
89 my @repo= grep {
90 chomp();
d42c7c41
GK
91 !m{\.git_patch$} &&
92 !m{\.gitattributes$} &&
06aba1c3 93 !m{\.gitignore$} &&
d0e1a873 94 !m{\.mailmap$} &&
79ff1055 95 !m{^\.github/} &&
bf28d609 96 -e $_ &&
eeba4e1a 97 !$seen{$_}++
bf28d609 98 } `git ls-files`;
dcab73c9
YO
99 skip("git ls-files didnt work",3)
100 if !@repo;
917bb0fa 101 is( 0+@repo, 0+@files, "git ls-files gives the same number of files as MANIFEST lists");
c46b5ef0
TC
102 my %repo;
103 ++$repo{$_} for @repo;
104 my %mani;
105 ++$mani{$_} for @files;
106 is( 0+keys %mani, 0+@files, "no duplicate files in MANIFEST")
107 or diag(join("\n ", "Duplicates:",grep $mani{$_} > 1, keys %mani));
dcab73c9
YO
108 delete $mani{$_} for @repo;
109 delete $repo{$_} for @files;
110 my @not_in_mani= keys %repo;
111 my @still_in_mani= keys %mani;
112
113 is( 0+@not_in_mani, 0, "Nothing added to the repo that isn't in MANIFEST");
114 is( "not in MANIFEST: @not_in_mani", "not in MANIFEST: ",
115 "Nothing added to the repo that isn't in MANIFEST");
116 is( 0+@still_in_mani, 0, "Nothing in the MANIFEST that isn't tracked by git");
117 is( "should not be in MANIFEST: @still_in_mani", "should not be in MANIFEST: ",
118 "Nothing in the MANIFEST that isn't tracked by git");
119
120}
121
b8ca42e1 122# EOF