1#!./perl -w 2 3BEGIN { 4 chdir 't' if -d 't'; 5 require "./test.pl"; 6 set_up_inc('../lib', '..'); 7} 8 9use TestInit qw(T); # T is chdir to the top level 10use strict; 11 12find_git_or_skip('all'); 13 14my $ok= do "./Porting/updateAUTHORS.pl"; 15my $error= !$ok && $@; 16is($ok,1,"updateAUTHORS.pl compiles correctly"); 17is($error, "", "updateAUTHORS.pl compiles without error"); 18my $small_range= "544171f79ec3e50bb5003007e9f4ebb9a7e9fe84^^^" 19 . "..544171f79ec3e50bb5003007e9f4ebb9a7e9fe84"; 20my $large_range= "6d02a9e121d037896df9b91ac623c1ab4c98c99a.." 21 . "544171f79ec3e50bb5003007e9f4ebb9a7e9fe8"; 22my $with_unknown_range= "96a91e01636d3050d38ae3373a362c7d47a6647e^^^.." 23 . "96a91e01636d3050d38ae3373a362c7d47a6647e"; 24 25foreach my $tuple ( 26 [ "--who", $small_range, 27 "James E Keenan, Karl Williamson, Mark Shelor." ], 28 [ "--files", $small_range, files_expected() ], 29 [ "--rank", $large_range, rank_expected()], 30 [ "--rank --percentage", $large_range, rank_percentage_expected()], 31 [ "--rank --percentage --cumulative", $large_range, 32 rank_percentage_cumulative_expected()], 33 [ "--thanks-applied", $large_range, thanks_applied_expected() ], 34 [ "--stats", $large_range, stats_expected() ], 35 [ "--stats --numstat", $large_range, stats_numstat_expected() ], 36 [ "--who" , $with_unknown_range, "Jarkko Hietaniemi.", "(no 'unknown' authors)" ], 37) { 38 my ($arg,$range,$expect, $msg_extra)= @$tuple; 39 my $skip_it; 40 for my $endpoint (split /\.+/, $range) { 41 my $parsed= `git rev-parse --verify -q $endpoint\{commit}`; 42 if (!$parsed or $?) { 43 $skip_it = 1; 44 } 45 } 46 SKIP: { 47 if ($skip_it) { 48 skip "commit range '$range' not available (this happens in CI)", 1; 49 } 50 $msg_extra= $msg_extra ? " $msg_extra" : ""; 51 my $cmd= join " ", "$^X ./Porting/updateAUTHORS.pl", 52 $arg, $range; 53 my $result= `$cmd`; 54 is(_clean($result), _clean($expect),"Option '$arg' works as expected$msg_extra") 55 or print STDERR "$cmd\n",$result 56 } 57} 58done_testing(); 59exit 0; 60sub _clean { 61 my ($str)= @_; 62 $str=~s/\s+\z//; 63 $str=~s/[ ]+\n/\n/g; 64 return $str; 65} 66 67sub files_expected { 68 return <<'END_OF_REPORT'; 69#Pos | commits | L++ | L-- | L+- | binary_change | Name 70#----+---------+-----+-----+-----+---------------+---------------------------------- 71#1 | 1 | 28 | 0 | 28 | 0 | pod/perlfunc.pod 72#2 | 1 | 14 | 4 | 10 | 0 | cpan/Digest-SHA/lib/Digest/SHA.pm 73#3 | 1 | 5 | 5 | 0 | 0 | cpan/Digest-SHA/shasum 74#4 | 1 | 3 | 3 | 0 | 0 | cpan/Digest-SHA/src/sha64bit.c 75#5 | 1 | 3 | 3 | 0 | 0 | cpan/Digest-SHA/src/sha64bit.h 76#6 | 1 | 3 | 3 | 0 | 0 | cpan/Digest-SHA/src/sha.c 77#7 | 1 | 3 | 3 | 0 | 0 | cpan/Digest-SHA/src/sha.h 78#8 | 1 | 1 | 1 | 0 | 0 | Porting/Maintainers.pl 79#9 | 1 | 1 | 0 | 1 | 0 | AUTHORS 80END_OF_REPORT 81} 82 83sub rank_expected { 84 return <<'END_OF_REPORT'; 85#Pos | Authored | Name 86#----+----------+----------------- 87#1 | 40 | Karl Williamson 88#2 | 32 | Yves Orton 89#3 | 8 | Paul Evans 90#4 | 6 | James E Keenan 91#5 | 4 | Elvin Aslanov 92#6 | 3 | Richard Leach 93#7 | 3 | Tony Cook 94#8 | 2 | Nicholas Clark 95#9 | 1 | Dan Kogai 96#10 | 1 | David Golden 97#11 | 1 | Graham Knop 98#12 | 1 | Mark Shelor 99#13 | 1 | Tomasz Konojacki 100END_OF_REPORT 101} 102 103sub rank_percentage_expected { 104 return <<'END_OF_REPORT'; 105#Pos | %Authored | Name 106#----+-----------+----------------- 107#1 | 38.83 | Karl Williamson 108#2 | 31.07 | Yves Orton 109#3 | 7.77 | Paul Evans 110#4 | 5.83 | James E Keenan 111#5 | 3.88 | Elvin Aslanov 112#6 | 2.91 | Richard Leach 113#7 | 2.91 | Tony Cook 114#8 | 1.94 | Nicholas Clark 115#9 | 0.97 | Dan Kogai 116#10 | 0.97 | David Golden 117#11 | 0.97 | Graham Knop 118#12 | 0.97 | Mark Shelor 119#13 | 0.97 | Tomasz Konojacki 120END_OF_REPORT 121} 122 123sub rank_percentage_cumulative_expected { 124 return <<'END_OF_REPORT'; 125#Pos | %Authored | Name 126#----+-----------+----------------- 127#1 | 38.83 | Karl Williamson 128#2 | 69.90 | Yves Orton 129#3 | 77.67 | Paul Evans 130#4 | 83.50 | James E Keenan 131#5 | 87.38 | Elvin Aslanov 132#6 | 90.29 | Richard Leach 133#7 | 93.20 | Tony Cook 134#8 | 95.15 | Nicholas Clark 135#9 | 96.12 | Dan Kogai 136#10 | 97.09 | David Golden 137#11 | 98.06 | Graham Knop 138#12 | 99.03 | Mark Shelor 139#13 | 100.00 | Tomasz Konojacki 140END_OF_REPORT 141} 142 143sub thanks_applied_expected { 144 return <<'END_OF_REPORT'; 145#Pos | Applied | Name 146#----+---------+---------------- 147#1 | 7 | Karl Williamson 148#2 | 4 | James E Keenan 149END_OF_REPORT 150} 151 152sub stats_expected { 153 return <<'END_OF_REPORT'; 154#Pos | Authored | Applied | Committed | Name 155#----+----------+---------+-----------+----------------- 156#1 | 40 | 7 | 47 | Karl Williamson 157#2 | 32 | 0 | 31 | Yves Orton 158#3 | 8 | 0 | 8 | Paul Evans 159#4 | 6 | 4 | 10 | James E Keenan 160#5 | 4 | 0 | 1 | Elvin Aslanov 161#6 | 3 | 0 | 3 | Tony Cook 162#7 | 3 | 0 | 0 | Richard Leach 163#8 | 2 | 0 | 2 | Nicholas Clark 164#9 | 1 | 0 | 1 | Tomasz Konojacki 165#10 | 1 | 0 | 0 | Dan Kogai 166#11 | 1 | 0 | 0 | David Golden 167#12 | 1 | 0 | 0 | Graham Knop 168#13 | 1 | 0 | 0 | Mark Shelor 169END_OF_REPORT 170} 171 172sub stats_numstat_expected { 173 return <<'END_OF_REPORT'; 174#Pos | Authored | Applied | Committed | NFiles | L++ | L-- | L+- | Name 175#----+----------+---------+-----------+--------+------+------+------+----------------- 176#1 | 40 | 7 | 47 | 14 | 1179 | 874 | 305 | Karl Williamson 177#2 | 32 | 0 | 31 | 25 | 2547 | 1481 | 1066 | Yves Orton 178#3 | 8 | 0 | 8 | 15 | 161 | 102 | 59 | Paul Evans 179#4 | 6 | 4 | 10 | 4 | 44 | 11 | 33 | James E Keenan 180#5 | 4 | 0 | 1 | 4 | 16 | 13 | 3 | Elvin Aslanov 181#6 | 3 | 0 | 3 | 7 | 8 | 7 | 1 | Tony Cook 182#7 | 3 | 0 | 0 | 13 | 75 | 51 | 24 | Richard Leach 183#8 | 2 | 0 | 2 | 2 | 24 | 1 | 23 | Nicholas Clark 184#9 | 1 | 0 | 1 | 2 | 21 | 15 | 6 | Tomasz Konojacki 185#10 | 1 | 0 | 0 | 8 | 33 | 22 | 11 | Mark Shelor 186#11 | 1 | 0 | 0 | 5 | 93 | 7 | 86 | Graham Knop 187#12 | 1 | 0 | 0 | 4 | 9 | 4 | 5 | Dan Kogai 188#13 | 1 | 0 | 0 | 2 | 19 | 6 | 13 | David Golden 189END_OF_REPORT 190} 191