quickjs-tart

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

test1486.pl (2689B)


      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 use strict;
     27 use warnings;
     28 
     29 # we may get the dir root pointed out
     30 my $root=$ARGV[0] || ".";
     31 
     32 my %insrc; # variable set in source
     33 my %indocs; # variable described in docs
     34 
     35 my $srccount = 1;
     36 sub getsrcvars {
     37     open(my $f, "<", "$root/../src/tool_writeout.c");
     38     my $mode = 0;
     39     while(<$f>) {
     40         if(!$mode &&
     41            ($_ =~ /^static const struct writeoutvar/)) {
     42             $mode = 1;
     43         }
     44         if($mode) {
     45             if($_ =~ /^}/) {
     46                 last;
     47             }
     48             if($_ =~ /^  \{\"([^\"]*)/) {
     49                 my $var = $1;
     50                 $insrc{$var} = $srccount++;
     51             }
     52         }
     53     }
     54     close($f);
     55 }
     56 
     57 sub getdocsvars {
     58     open(my $f, "<", "$root/../docs/cmdline-opts/write-out.md");
     59     while(<$f>) {
     60         if($_ =~ /^\#\# \`([^\`]*)\`/) {
     61             if($1 ne "header{name}" && $1 ne "output{filename}") {
     62                 $indocs{$1} = 1;
     63             }
     64         }
     65     }
     66     close($f);
     67 }
     68 
     69 getsrcvars();
     70 getdocsvars();
     71 
     72 my $error = 0;
     73 
     74 if((scalar(keys %indocs) < 10) || (scalar(keys %insrc) < 10)) {
     75     print "problems to extract variables\n";
     76     $error++;
     77 }
     78 
     79 # also verify that the source code lists them alphabetically
     80 my $check = 1;
     81 for(sort keys %insrc) {
     82     if($insrc{$_} && !$indocs{$_}) {
     83         print "$_ is not mentioned in write.out.md\n";
     84         $error++;
     85     }
     86     if($insrc{$_} ne $check) {
     87         print "$_ is not in alphabetical order\n";
     88         $error++;
     89     }
     90     $check++;
     91 }
     92 
     93 for(sort keys %indocs) {
     94     if($indocs{$_} && !$insrc{$_}) {
     95         print "$_ documented, but not used in source code\n";
     96         $error++;
     97     }
     98 }
     99 
    100 print "OK\n" if(!$error);
    101 
    102 exit $error;