xref: /curl/tests/test1486.pl (revision 61b46520)
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#
27
28use strict;
29use warnings;
30
31# we may get the dir root pointed out
32my $root=$ARGV[0] || ".";
33
34my %insrc; # variable set in source
35my %indocs; # variable described in docs
36
37my $srccount = 1;
38sub getsrcvars {
39    open(my $f, "<", "$root/../src/tool_writeout.c");
40    my $mode = 0;
41    while(<$f>) {
42        if(!$mode &&
43           ($_ =~ /^static const struct writeoutvar/)) {
44            $mode = 1;
45        }
46        if($mode) {
47            if($_ =~ /^}/) {
48                last;
49            }
50            if($_ =~ /^  \{\"([^\"]*)/) {
51                my $var = $1;
52                $insrc{$var} = $srccount++;
53            }
54        }
55    }
56    close($f);
57}
58
59sub getdocsvars {
60    open(my $f, "<", "$root/../docs/cmdline-opts/write-out.md");
61    while(<$f>) {
62        if($_ =~ /^\#\# \`([^\`]*)\`/) {
63            $indocs{$1} = 1;
64        }
65    }
66    close($f);
67}
68
69getsrcvars();
70getdocsvars();
71
72my $error = 0;
73
74if((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
80my $check = 1;
81for(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
93for(sort keys %indocs) {
94    if($indocs{$_} && !$insrc{$_}) {
95        print "$_ documented, but not used in source code\n";
96        $error++;
97    }
98}
99
100print "OK\n" if(!$error);
101
102exit $error;
103