keywords.pl 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #!/usr/bin/env perl
  2. #***************************************************************************
  3. # _ _ ____ _
  4. # Project ___| | | | _ \| |
  5. # / __| | | | |_) | |
  6. # | (__| |_| | _ <| |___
  7. # \___|\___/|_| \_\_____|
  8. #
  9. # Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
  10. #
  11. # This software is licensed as described in the file COPYING, which
  12. # you should have received as part of this distribution. The terms
  13. # are also available at http://curl.haxx.se/docs/copyright.html.
  14. #
  15. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  16. # copies of the Software, and permit persons to whom the Software is
  17. # furnished to do so, under the terms of the COPYING file.
  18. #
  19. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  20. # KIND, either express or implied.
  21. #
  22. ###########################################################################
  23. use strict;
  24. @INC=(@INC, $ENV{'srcdir'}, ".");
  25. require "getpart.pm"; # array functions
  26. my $srcdir = $ENV{'srcdir'} || '.';
  27. my $TESTDIR="$srcdir/data";
  28. # Get all commands and find out their test numbers
  29. opendir(DIR, $TESTDIR) || die "can't opendir $TESTDIR: $!";
  30. my @cmds = grep { /^test([0-9]+)$/ && -f "$TESTDIR/$_" } readdir(DIR);
  31. closedir DIR;
  32. my $TESTCASES; # start with no test cases
  33. # cut off everything but the digits
  34. for(@cmds) {
  35. $_ =~ s/[a-z\/\.]*//g;
  36. }
  37. # the the numbers from low to high
  38. for(sort { $a <=> $b } @cmds) {
  39. $TESTCASES .= " $_";
  40. }
  41. my $t;
  42. my %k; # keyword count
  43. my %t; # keyword to test case mapping
  44. my @miss; # test cases without keywords set
  45. my $count;
  46. my %errors;
  47. for $t (split(/ /, $TESTCASES)) {
  48. if(loadtest("${TESTDIR}/test${t}")) {
  49. # bad case
  50. next;
  51. }
  52. my @ec = getpart("verify", "errorcode");
  53. if($ec[0]) {
  54. # count number of check error codes
  55. $errors{ 0 + $ec[0] } ++;
  56. }
  57. my @what = getpart("info", "keywords");
  58. if(!$what[0]) {
  59. push @miss, $t;
  60. next;
  61. }
  62. for(@what) {
  63. chomp;
  64. #print "Test $t: $_\n";
  65. $k{$_}++;
  66. $t{$_} .= "$t ";
  67. }
  68. $count++;
  69. }
  70. sub show {
  71. my ($list)=@_;
  72. my @a = split(" ", $list);
  73. my $ret;
  74. my $c;
  75. my @l = sort {rand(100) - 50} @a;
  76. my @ll;
  77. for(1 .. 11) {
  78. my $v = shift @l;
  79. if($v) {
  80. push @ll, $v;
  81. }
  82. }
  83. for (sort {$a <=> $b} @ll) {
  84. if($c++ == 10) {
  85. $ret .= "...";
  86. last;
  87. }
  88. $ret .= "$_ ";
  89. }
  90. return $ret;
  91. }
  92. # numerically on amount, or alphebetically if same amount
  93. my @mtest = reverse sort { $k{$a} <=> $k{$b} || $b cmp $a } keys %k;
  94. print <<TOP
  95. <table><tr><th>Num</th><th>Keyword</th><th>Test Cases</th></tr>
  96. TOP
  97. ;
  98. for $t (@mtest) {
  99. printf "<tr><td>%d</td><td>$t</td><td>%s</td></tr>\n", $k{$t},
  100. show($t{$t});
  101. }
  102. printf "</table><p> $count out of %d tests (%d lack keywords)\n",
  103. scalar(@miss) + $count,
  104. scalar(@miss);
  105. for(@miss) {
  106. print STDERR "$_ ";
  107. }
  108. print STDERR "\n";
  109. printf "<p> %d different error codes tested for:<br>\n",
  110. scalar(keys %errors);
  111. # numerically on amount, or alphebetically if same amount
  112. my @etest = sort { $a <=> $b} keys %errors;
  113. for(@etest) {
  114. print "$_ ";
  115. }
  116. print "\n";