quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

test1707.pl (3422B)


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