test1139.pl 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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. #
  26. # Scan symbols-in-version (which is verified to be correct by test 1119), then
  27. # verify that each option mention in there that should have its own man page
  28. # actually does.
  29. #
  30. # In addition, make sure that every current option to curl_easy_setopt,
  31. # curl_easy_getinfo and curl_multi_setopt are also mentioned in their
  32. # corresponding main (index) man page.
  33. #
  34. # src/tool_getparam.c lists all options curl can parse
  35. # docs/curl.1 documents all command line options
  36. # src/tool_listhelp.c outputs all options with curl -h
  37. # - make sure they're all in sync
  38. #
  39. # Output all deviances to stderr.
  40. use strict;
  41. use warnings;
  42. # we may get the dir roots pointed out
  43. my $root=$ARGV[0] || ".";
  44. my $buildroot=$ARGV[1] || ".";
  45. my $syms = "$root/docs/libcurl/symbols-in-versions";
  46. my $curlh = "$root/include/curl/curl.h";
  47. my $errors=0;
  48. # the prepopulated alias list is the CURLINFO_* defines that are used for the
  49. # debug function callback and the fact that they use the same prefix as the
  50. # curl_easy_getinfo options was a mistake.
  51. my %alias = (
  52. 'CURLINFO_DATA_IN' => 'none',
  53. 'CURLINFO_DATA_OUT' => 'none',
  54. 'CURLINFO_END' => 'none',
  55. 'CURLINFO_HEADER_IN' => 'none',
  56. 'CURLINFO_HEADER_OUT' => 'none',
  57. 'CURLINFO_LASTONE' => 'none',
  58. 'CURLINFO_NONE' => 'none',
  59. 'CURLINFO_SSL_DATA_IN' => 'none',
  60. 'CURLINFO_SSL_DATA_OUT' => 'none',
  61. 'CURLINFO_TEXT' => 'none'
  62. );
  63. sub scanmanpage {
  64. my ($file, @words) = @_;
  65. open(my $mh, "<", "$file") ||
  66. die "could not open $file";
  67. my @m;
  68. while(<$mh>) {
  69. if($_ =~ /^\.IP (.*)/) {
  70. my $w = $1;
  71. # "unquote" minuses
  72. $w =~ s/\\-/-/g;
  73. push @m, $w;
  74. }
  75. }
  76. close($mh);
  77. foreach my $m (@words) {
  78. my @g = grep(/$m/, @m);
  79. if(!$g[0]) {
  80. print STDERR "Missing mention of $m in $file\n";
  81. $errors++;
  82. }
  83. }
  84. }
  85. my $r;
  86. # check for define aliases
  87. open($r, "<", "$curlh") ||
  88. die "no curl.h";
  89. while(<$r>) {
  90. if(/^\#define (CURL(OPT|INFO|MOPT)_\w+) (.*)/) {
  91. $alias{$1}=$3;
  92. }
  93. }
  94. close($r);
  95. my @curlopt;
  96. my @curlinfo;
  97. my @curlmopt;
  98. open($r, "<", "$syms") ||
  99. die "no input file";
  100. while(<$r>) {
  101. chomp;
  102. my $l= $_;
  103. if($l =~ /(CURL(OPT|INFO|MOPT)_\w+) *([0-9.]*) *([0-9.-]*) *([0-9.]*)/) {
  104. my ($opt, $type, $add, $dep, $rem) = ($1, $2, $3, $4, $5);
  105. if($alias{$opt}) {
  106. #print "$opt => $alias{$opt}\n";
  107. }
  108. elsif($rem) {
  109. # $opt was removed in $rem
  110. # so don't check for that
  111. }
  112. else {
  113. if($type eq "OPT") {
  114. push @curlopt, $opt,
  115. }
  116. elsif($type eq "INFO") {
  117. push @curlinfo, $opt,
  118. }
  119. elsif($type eq "MOPT") {
  120. push @curlmopt, $opt,
  121. }
  122. if(! -f "$buildroot/docs/libcurl/opts/$opt.3") {
  123. print STDERR "Missing $opt.3\n";
  124. $errors++;
  125. }
  126. }
  127. }
  128. }
  129. close($r);
  130. scanmanpage("$buildroot/docs/libcurl/curl_easy_setopt.3", @curlopt);
  131. scanmanpage("$buildroot/docs/libcurl/curl_easy_getinfo.3", @curlinfo);
  132. scanmanpage("$buildroot/docs/libcurl/curl_multi_setopt.3", @curlmopt);
  133. # using this hash array, we can skip specific options
  134. my %opts = (
  135. # pretend these --no options exists in tool_getparam.c
  136. '--no-alpn' => 1,
  137. '--no-npn' => 1,
  138. '-N, --no-buffer' => 1,
  139. '--no-sessionid' => 1,
  140. '--no-keepalive' => 1,
  141. '--no-progress-meter' => 1,
  142. '--no-clobber' => 1,
  143. # pretend these options without -no exist in curl.1 and tool_listhelp.c
  144. '--alpn' => 6,
  145. '--npn' => 6,
  146. '--eprt' => 6,
  147. '--epsv' => 6,
  148. '--keepalive' => 6,
  149. '-N, --buffer' => 6,
  150. '--sessionid' => 6,
  151. '--progress-meter' => 6,
  152. '--clobber' => 6,
  153. # deprecated options do not need to be in tool_help.c nor curl.1
  154. '--krb4' => 6,
  155. '--ftp-ssl' => 6,
  156. '--ftp-ssl-reqd' => 6,
  157. # for tests and debug only, can remain hidden
  158. '--test-event' => 6,
  159. '--wdebug' => 6,
  160. );
  161. #########################################################################
  162. # parse the curl code that parses the command line arguments!
  163. open($r, "<", "$root/src/tool_getparam.c") ||
  164. die "no input file";
  165. my $list;
  166. my @getparam; # store all parsed parameters
  167. my $prevlong = "";
  168. my $no = 0;
  169. while(<$r>) {
  170. $no++;
  171. chomp;
  172. if(/struct LongShort aliases/) {
  173. $list=1;
  174. }
  175. elsif($list) {
  176. if( /^ \{(\"[^,]*\").*\'(.)\', (.*)\}/) {
  177. my ($l, $s, $rd)=($1, $2, $3);
  178. my $sh;
  179. my $lo;
  180. my $title;
  181. if(($l cmp $prevlong) < 0) {
  182. print STDERR "tool_getparam.c:$no: '$l' is NOT placed in alpha-order\n";
  183. }
  184. if($l =~ /\"(.*)\"/) {
  185. # long option
  186. $lo = $1;
  187. $title="--$lo";
  188. }
  189. if($s ne " ") {
  190. # a short option
  191. $sh = $s;
  192. $title="-$sh, $title";
  193. }
  194. push @getparam, $title;
  195. $opts{$title} |= 1;
  196. $prevlong = $l;
  197. }
  198. }
  199. }
  200. close($r);
  201. #########################################################################
  202. # parse the curl.1 man page, extract all documented command line options
  203. # The man page may or may not be rebuilt, so check both possible locations
  204. open($r, "<", "$buildroot/docs/cmdline-opts/curl.1") || open($r, "<", "$root/docs/cmdline-opts/curl.1") ||
  205. die "failed getting curl.1";
  206. my @manpage; # store all parsed parameters
  207. while(<$r>) {
  208. chomp;
  209. my $l= $_;
  210. $l =~ s/\\-/-/g;
  211. if($l =~ /^\.IP \"(-[^\"]*)\"/) {
  212. my $str = $1;
  213. my $combo;
  214. if($str =~ /^-(.), --([a-z0-9.-]*)/) {
  215. # figure out the -short, --long combo
  216. $combo = "-$1, --$2";
  217. }
  218. elsif($str =~ /^--([a-z0-9.-]*)/) {
  219. # figure out the --long name
  220. $combo = "--$1";
  221. }
  222. if($combo) {
  223. push @manpage, $combo;
  224. $opts{$combo} |= 2;
  225. }
  226. }
  227. }
  228. close($r);
  229. #########################################################################
  230. # parse the curl code that outputs the curl -h list
  231. open($r, "<", "$root/src/tool_listhelp.c") ||
  232. die "no input file";
  233. my @toolhelp; # store all parsed parameters
  234. while(<$r>) {
  235. chomp;
  236. my $l= $_;
  237. if(/^ \{\" *(.*)/) {
  238. my $str=$1;
  239. my $combo;
  240. if($str =~ /^-(.), --([a-z0-9.-]*)/) {
  241. # figure out the -short, --long combo
  242. $combo = "-$1, --$2";
  243. }
  244. elsif($str =~ /^--([a-z0-9.-]*)/) {
  245. # figure out the --long name
  246. $combo = "--$1";
  247. }
  248. if($combo) {
  249. push @toolhelp, $combo;
  250. $opts{$combo} |= 4;
  251. }
  252. }
  253. }
  254. close($r);
  255. #
  256. # Now we have three arrays with options to cross-reference.
  257. foreach my $o (keys %opts) {
  258. my $where = $opts{$o};
  259. if($where != 7) {
  260. # this is not in all three places
  261. $errors++;
  262. my $exists;
  263. my $missing;
  264. if($where & 1) {
  265. $exists=" tool_getparam.c";
  266. }
  267. else {
  268. $missing=" tool_getparam.c";
  269. }
  270. if($where & 2) {
  271. $exists.= " curl.1";
  272. }
  273. else {
  274. $missing.= " curl.1";
  275. }
  276. if($where & 4) {
  277. $exists .= " tool_listhelp.c";
  278. }
  279. else {
  280. $missing .= " tool_listhelp.c";
  281. }
  282. print STDERR "$o is not in$missing (but in$exists)\n";
  283. }
  284. }
  285. print STDERR "$errors\n";