keywords.pl 3.3 KB

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