test1139.pl 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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 manpage
  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) manpage.
  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 scanmdpage {
  64. my ($file, @words) = @_;
  65. open(my $mh, "<", "$file") ||
  66. die "could not open $file";
  67. my @m;
  68. while(<$mh>) {
  69. if($_ =~ /^## (.*)/) {
  70. my $w = $1;
  71. # "unquote" minuses
  72. $w =~ s/\\-/-/g;
  73. push @m, $w;
  74. }
  75. }
  76. close($mh);
  77. my @ms = sort @m;
  78. for my $i (0 .. $#m) {
  79. if($ms[$i] ne $m[$i]) {
  80. print STDERR "$file:1:ERROR: $m[$i] is not alphabetical (expected $ms[$i])\n";
  81. $errors++;
  82. # no point in reporting many
  83. last;
  84. }
  85. }
  86. foreach my $m (@words) {
  87. my @g = grep(/$m/, @m);
  88. if(!$g[0]) {
  89. print STDERR "Missing mention of $m in $file\n";
  90. $errors++;
  91. }
  92. }
  93. }
  94. my $r;
  95. # check for define aliases
  96. open($r, "<", "$curlh") ||
  97. die "no curl.h";
  98. while(<$r>) {
  99. if(/^\#define (CURL(OPT|INFO|MOPT)_\w+) (.*)/) {
  100. $alias{$1}=$3;
  101. }
  102. }
  103. close($r);
  104. my @curlopt;
  105. my @curlinfo;
  106. my @curlmopt;
  107. open($r, "<", "$syms") ||
  108. die "no input file";
  109. while(<$r>) {
  110. chomp;
  111. my $l= $_;
  112. if($l =~ /(CURL(OPT|INFO|MOPT)_\w+) *([0-9.]*) *([0-9.-]*) *([0-9.]*)/) {
  113. my ($opt, $type, $add, $dep, $rem) = ($1, $2, $3, $4, $5);
  114. if($alias{$opt}) {
  115. #print "$opt => $alias{$opt}\n";
  116. }
  117. elsif($rem) {
  118. # $opt was removed in $rem
  119. # so don't check for that
  120. }
  121. else {
  122. if($type eq "OPT") {
  123. push @curlopt, $opt,
  124. }
  125. elsif($type eq "INFO") {
  126. push @curlinfo, $opt,
  127. }
  128. elsif($type eq "MOPT") {
  129. push @curlmopt, $opt,
  130. }
  131. if(! -f "$root/docs/libcurl/opts/$opt.md") {
  132. print STDERR "Missing $opt.md\n";
  133. $errors++;
  134. }
  135. }
  136. }
  137. }
  138. close($r);
  139. scanmdpage("$root/docs/libcurl/curl_easy_setopt.md", @curlopt);
  140. scanmdpage("$root/docs/libcurl/curl_easy_getinfo.md", @curlinfo);
  141. scanmdpage("$root/docs/libcurl/curl_multi_setopt.md", @curlmopt);
  142. # using this hash array, we can skip specific options
  143. my %opts = (
  144. # pretend these --no options exists in tool_getparam.c
  145. '--no-alpn' => 1,
  146. '--no-npn' => 1,
  147. '-N, --no-buffer' => 1,
  148. '--no-sessionid' => 1,
  149. '--no-keepalive' => 1,
  150. '--no-progress-meter' => 1,
  151. '--no-clobber' => 1,
  152. # pretend these options without -no exist in curl.1 and tool_listhelp.c
  153. '--alpn' => 6,
  154. '--npn' => 6,
  155. '--eprt' => 6,
  156. '--epsv' => 6,
  157. '--keepalive' => 6,
  158. '-N, --buffer' => 6,
  159. '--sessionid' => 6,
  160. '--progress-meter' => 6,
  161. '--clobber' => 6,
  162. # deprecated options do not need to be in tool_help.c nor curl.1
  163. '--krb4' => 6,
  164. '--ftp-ssl' => 6,
  165. '--ftp-ssl-reqd' => 6,
  166. '--include' => 6,
  167. # for tests and debug only, can remain hidden
  168. '--test-event' => 6,
  169. '--wdebug' => 6,
  170. );
  171. #########################################################################
  172. # parse the curl code that parses the command line arguments!
  173. open($r, "<", "$root/src/tool_getparam.c") ||
  174. die "no input file";
  175. my $list;
  176. my @getparam; # store all parsed parameters
  177. my $prevlong = "";
  178. my $no = 0;
  179. while(<$r>) {
  180. $no++;
  181. chomp;
  182. if(/struct LongShort aliases/) {
  183. $list=1;
  184. }
  185. elsif($list) {
  186. if( /^ \{(\"[^,]*\").*\'(.)\', (.*)\}/) {
  187. my ($l, $s, $rd)=($1, $2, $3);
  188. my $sh;
  189. my $lo;
  190. my $title;
  191. if(($l cmp $prevlong) < 0) {
  192. print STDERR "tool_getparam.c:$no: '$l' is NOT placed in alpha-order\n";
  193. }
  194. if($l =~ /\"(.*)\"/) {
  195. # long option
  196. $lo = $1;
  197. $title="--$lo";
  198. }
  199. if($s ne " ") {
  200. # a short option
  201. $sh = $s;
  202. $title="-$sh, $title";
  203. }
  204. push @getparam, $title;
  205. $opts{$title} |= 1;
  206. $prevlong = $l;
  207. }
  208. }
  209. }
  210. close($r);
  211. #########################################################################
  212. # parse the curl.1 manpage, extract all documented command line options
  213. # The manpage may or may not be rebuilt, so check both possible locations
  214. open($r, "<", "$buildroot/docs/cmdline-opts/curl.1") || open($r, "<", "$root/docs/cmdline-opts/curl.1") ||
  215. die "failed getting curl.1";
  216. my @manpage; # store all parsed parameters
  217. while(<$r>) {
  218. chomp;
  219. my $l= $_;
  220. $l =~ s/\\-/-/g;
  221. if($l =~ /^\.IP \"(-[^\"]*)\"/) {
  222. my $str = $1;
  223. my $combo;
  224. if($str =~ /^-(.), --([a-z0-9.-]*)/) {
  225. # figure out the -short, --long combo
  226. $combo = "-$1, --$2";
  227. }
  228. elsif($str =~ /^--([a-z0-9.-]*)/) {
  229. # figure out the --long name
  230. $combo = "--$1";
  231. }
  232. if($combo) {
  233. push @manpage, $combo;
  234. $opts{$combo} |= 2;
  235. }
  236. }
  237. }
  238. close($r);
  239. #########################################################################
  240. # parse the curl code that outputs the curl -h list
  241. open($r, "<", "$root/src/tool_listhelp.c") ||
  242. die "no input file";
  243. my @toolhelp; # store all parsed parameters
  244. while(<$r>) {
  245. chomp;
  246. my $l= $_;
  247. if(/^ \{\" *(.*)/) {
  248. my $str=$1;
  249. my $combo;
  250. if($str =~ /^-(.), --([a-z0-9.-]*)/) {
  251. # figure out the -short, --long combo
  252. $combo = "-$1, --$2";
  253. }
  254. elsif($str =~ /^--([a-z0-9.-]*)/) {
  255. # figure out the --long name
  256. $combo = "--$1";
  257. }
  258. if($combo) {
  259. push @toolhelp, $combo;
  260. $opts{$combo} |= 4;
  261. }
  262. }
  263. }
  264. close($r);
  265. #
  266. # Now we have three arrays with options to cross-reference.
  267. foreach my $o (keys %opts) {
  268. my $where = $opts{$o};
  269. if($where != 7) {
  270. # this is not in all three places
  271. $errors++;
  272. my $exists;
  273. my $missing;
  274. if($where & 1) {
  275. $exists=" tool_getparam.c";
  276. }
  277. else {
  278. $missing=" tool_getparam.c";
  279. }
  280. if($where & 2) {
  281. $exists.= " curl.1";
  282. }
  283. else {
  284. $missing.= " curl.1";
  285. }
  286. if($where & 4) {
  287. $exists .= " tool_listhelp.c";
  288. }
  289. else {
  290. $missing .= " tool_listhelp.c";
  291. }
  292. print STDERR "$o is not in$missing (but in$exists)\n";
  293. }
  294. }
  295. print STDERR "$errors\n";