2
0

test1707.pl 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. # This script grew out of help from Przemyslaw Iskra and Balint Szilakszi
  27. # a late evening in the #curl IRC channel.
  28. #
  29. use strict;
  30. use warnings;
  31. my $curl = shift @ARGV;
  32. my $opt = shift @ARGV;
  33. my $output = shift @ARGV;
  34. my $txt = shift @ARGV;
  35. my $longopt;
  36. my $shortopt;
  37. if($opt =~ /^--/) {
  38. $longopt = $opt;
  39. }
  40. else {
  41. $shortopt = $opt;
  42. }
  43. # first run the help command
  44. system("$curl -h $opt > $output");
  45. my @curlout;
  46. open(O, "<$output");
  47. push @curlout, <O>;
  48. close(O);
  49. # figure out the short+long option combo using -h all*/
  50. open(C, "$curl -h all|");
  51. if($shortopt) {
  52. while(<C>) {
  53. if(/^ +$opt, ([^ ]*)/) {
  54. $longopt = $1;
  55. last;
  56. }
  57. }
  58. }
  59. else {
  60. while(<C>) {
  61. my $f = $_;
  62. if(/ $opt /) {
  63. if($f =~ /^ *(-(.)), $longopt/) {
  64. $shortopt = $1;
  65. }
  66. last;
  67. }
  68. }
  69. }
  70. close(C);
  71. my $fullopt;
  72. if($shortopt) {
  73. $fullopt = "$shortopt, $longopt";
  74. }
  75. else {
  76. $fullopt = $longopt;
  77. }
  78. open(R, "<$txt");
  79. my $show = 0;
  80. my @txtout;
  81. while(<R>) {
  82. if(/^ $fullopt/) {
  83. $show = 1;
  84. }
  85. elsif(/^ -/ && $show) {
  86. last;
  87. }
  88. if($show) {
  89. push @txtout, $_;
  90. }
  91. }
  92. close(R);
  93. my $error;
  94. if(scalar(@curlout) != scalar(@txtout)) {
  95. printf "curl -h $opt is %d lines, $txt says %d lines\n",
  96. scalar(@curlout), scalar(@txtout);
  97. $error++;
  98. }
  99. else {
  100. # same size, compare line by line
  101. for my $i (0 .. $#curlout) {
  102. # trim CRLF from the data
  103. $curlout[$i] =~ s/[\r\n]//g;
  104. $txtout[$i] =~ s/[\r\n]//g;
  105. if($curlout[$i] ne $txtout[$i]) {
  106. printf "Line %d\n", $i;
  107. printf "-h : %s (%d bytes)\n", $curlout[$i],
  108. length($curlout[$i]);
  109. printf "file : %s (%d bytes)\n", $txtout[$i],
  110. length($txtout[$i]);
  111. if(length($curlout[$i]) == length($txtout[$i])) {
  112. my $l = length($curlout[$i]);
  113. for my $c (0 .. $l) {
  114. my $o = substr($curlout[$i], $c, 1);
  115. my $t = substr($txtout[$i], $c, 1);
  116. if($o ne $t) {
  117. print "-h col %d: %02x\n", $c, ord($o);
  118. print "file col %d: %02x\n", $c, ord($t);
  119. }
  120. }
  121. }
  122. $error++;
  123. }
  124. }
  125. }
  126. exit $error;