restore executable bits on some files
[platform/upstream/curl.git] / tests / keywords.pl
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
24 use strict;
25
26 @INC=(@INC, $ENV{'srcdir'}, ".");
27
28 require "getpart.pm"; # array functions
29
30 my $srcdir = $ENV{'srcdir'} || '.';
31 my $TESTDIR="$srcdir/data";
32
33 # Get all commands and find out their test numbers
34 opendir(DIR, $TESTDIR) || die "can't opendir $TESTDIR: $!";
35 my @cmds = grep { /^test([0-9]+)$/ && -f "$TESTDIR/$_" } readdir(DIR);
36 closedir DIR;
37
38 my $TESTCASES; # start with no test cases
39
40 # cut off everything but the digits
41 for(@cmds) {
42     $_ =~ s/[a-z\/\.]*//g;
43 }
44 # the the numbers from low to high
45 for(sort { $a <=> $b } @cmds) {
46     $TESTCASES .= " $_";
47 }
48
49 my $t;
50
51 my %k; # keyword count
52 my %t; # keyword to test case mapping
53 my @miss; # test cases without keywords set
54
55 my $count;
56
57 my %errors;
58
59 for $t (split(/ /, $TESTCASES)) {
60     if(loadtest("${TESTDIR}/test${t}")) {
61         # bad case
62         next;
63     }
64
65     my @ec = getpart("verify", "errorcode");
66     if($ec[0]) {
67         # count number of check error codes
68         $errors{ 0 + $ec[0] } ++;
69     }
70
71
72     my @what = getpart("info", "keywords");
73
74     if(!$what[0]) {
75         push @miss, $t;
76         next;
77     }
78
79     for(@what) {
80         chomp;
81         #print "Test $t: $_\n";
82         $k{$_}++;
83         $t{$_} .= "$t ";
84     }
85
86
87
88
89
90
91
92
93     $count++;
94 }
95
96 sub show {
97     my ($list)=@_;
98     my @a = split(" ", $list);
99     my $ret;
100
101     my $c;
102     my @l = sort {rand(100) - 50} @a;
103     my @ll;
104
105     for(1 .. 11) {
106         my $v = shift @l;
107         if($v) {
108             push @ll, $v;
109         }
110     }
111
112     for (sort {$a <=> $b} @ll) {
113         if($c++ == 10) {
114             $ret .= "...";
115             last;
116         }
117         $ret .= "$_ ";
118     }
119     return $ret;
120 }
121
122 # numerically on amount, or alphebetically if same amount
123 my @mtest = reverse sort { $k{$a} <=> $k{$b} || $b cmp $a } keys %k;
124
125 print <<TOP
126 <table><tr><th>Num</th><th>Keyword</th><th>Test Cases</th></tr>
127 TOP
128     ;
129 for $t (@mtest) {
130     printf "<tr><td>%d</td><td>$t</td><td>%s</td></tr>\n", $k{$t},
131     show($t{$t});
132 }
133 printf "</table><p> $count out of %d tests (%d lack keywords)\n",
134     scalar(@miss) + $count,
135     scalar(@miss);
136
137 for(@miss) {
138     print STDERR "$_ ";
139 }
140
141 print STDERR "\n";
142
143 printf "<p> %d different error codes tested for:<br>\n",
144     scalar(keys %errors);
145
146 # numerically on amount, or alphebetically if same amount
147 my @etest = sort { $a <=> $b} keys %errors;
148
149 for(@etest) {
150     print "$_ ";
151 }
152 print "\n";