keywords.pl 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #!/usr/bin/env perl
  2. #***************************************************************************
  3. # _ _ ____ _
  4. # Project ___| | | | _ \| |
  5. # / __| | | | |_) | |
  6. # | (__| |_| | _ <| |___
  7. # \___|\___/|_| \_\_____|
  8. #
  9. # Copyright (C) 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 https://curl.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. # SPDX-License-Identifier: curl
  23. #
  24. ###########################################################################
  25. use strict;
  26. use warnings;
  27. push(@INC, $ENV{'srcdir'}) if(defined $ENV{'srcdir'});
  28. push(@INC, ".");
  29. use getpart qw(
  30. getpart
  31. loadtest
  32. );
  33. my $srcdir = $ENV{'srcdir'} || '.';
  34. my $TESTDIR="$srcdir/data";
  35. # Get all commands and find out their test numbers
  36. opendir(DIR, $TESTDIR) || die "can't opendir $TESTDIR: $!";
  37. my @cmds = grep { /^test([0-9]+)$/ && -f "$TESTDIR/$_" } readdir(DIR);
  38. closedir DIR;
  39. my $TESTCASES; # start with no test cases
  40. # cut off everything but the digits
  41. for(@cmds) {
  42. $_ =~ s/[a-z\/\.]*//g;
  43. }
  44. # the numbers from low to high
  45. for(sort { $a <=> $b } @cmds) {
  46. $TESTCASES .= " $_";
  47. }
  48. my $t;
  49. my %k; # keyword count
  50. my %t; # keyword to test case mapping
  51. my @miss; # test cases without keywords set
  52. my $count;
  53. my %errors;
  54. for $t (split(/ /, $TESTCASES)) {
  55. if(loadtest("${TESTDIR}/test${t}")) {
  56. # bad case
  57. next;
  58. }
  59. my @ec = getpart("verify", "errorcode");
  60. if($ec[0]) {
  61. # count number of check error codes
  62. $errors{ 0 + $ec[0] } ++;
  63. }
  64. my @what = getpart("info", "keywords");
  65. if(!$what[0]) {
  66. push @miss, $t;
  67. next;
  68. }
  69. for(@what) {
  70. chomp;
  71. #print "Test $t: $_\n";
  72. $k{$_}++;
  73. $t{$_} .= "$t ";
  74. }
  75. $count++;
  76. }
  77. sub show {
  78. my ($list)=@_;
  79. my @a = split(" ", $list);
  80. my $ret;
  81. my $c;
  82. my @l = sort {rand(100) - 50} @a;
  83. my @ll;
  84. for(1 .. 11) {
  85. my $v = shift @l;
  86. if($v) {
  87. push @ll, $v;
  88. }
  89. }
  90. for (sort {$a <=> $b} @ll) {
  91. if($c++ == 10) {
  92. $ret .= "...";
  93. last;
  94. }
  95. $ret .= "$_ ";
  96. }
  97. return $ret;
  98. }
  99. # sort alphabetically
  100. my @mtest = reverse sort { lc($b) cmp lc($a) } keys %k;
  101. print <<TOP
  102. <table><tr><th>Num</th><th>Keyword</th><th>Test Cases</th></tr>
  103. TOP
  104. ;
  105. for $t (@mtest) {
  106. printf "<tr><td>%d</td><td>$t</td><td>%s</td></tr>\n", $k{$t},
  107. show($t{$t});
  108. }
  109. printf "</table><p> $count out of %d tests (%d lack keywords)\n",
  110. scalar(@miss) + $count,
  111. scalar(@miss);
  112. for(@miss) {
  113. print "$_ ";
  114. }
  115. print "\n";
  116. printf "<p> %d different error codes tested for:<br>\n",
  117. scalar(keys %errors);
  118. # numerically on amount, or alphebetically if same amount
  119. my @etest = sort { $a <=> $b} keys %errors;
  120. for(@etest) {
  121. print "$_ ";
  122. }
  123. print "\n";