xref: /curl/tests/test971.pl (revision 2494b8dd)
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# - Get all options mentioned in the $cmddir.
28# - Make sure they're all mentioned in the $opts document
29# - Make sure that the version in $opts matches the version in the file in
30#   $cmddir
31#
32
33my $opts = $ARGV[0];
34my $cmddir = $ARGV[1];
35
36sub cmdfiles {
37    my ($dir)=@_;
38
39    opendir(my $dh, $dir) || die "Can't opendir $dir: $!";
40    my @opts = grep { /[a-z0-9].*\.md$/ && -f "$dir/$_" } readdir($dh);
41    closedir $dh;
42
43    for(@opts) {
44        $_ =~ s/\.md$//;
45        $file{$_}=1;
46    }
47    return @opts;
48}
49
50sub mentions {
51    my ($f) = @_;
52    my @options;
53    open(my $fh, "<", "$f");
54    while(<$fh>) {
55        chomp;
56        if(/(.*) +([0-9.]+)/) {
57            my ($flag, $version)=($1, $2);
58
59            # store the name without the leading dashes
60            $flag =~ s/^--//;
61
62            # cut out short option (if present)
63            $flag =~ s/ \(-.\)//;
64
65            # store the name without trailing space
66            $flag =~ s/ +$//;
67
68            push @options, $flag;
69
70            # options-in-versions says...
71            $oiv{$flag} = $version;
72        }
73    }
74    close($fh);
75    return @options;
76}
77
78sub versioncheck {
79    my ($f, $v)=@_;
80    open(my $fh, "<", "$cmddir/$f.md");
81    while(<$fh>) {
82        chomp;
83        if(/^Added: ([0-9.]+)/) {
84            if($1 ne $v) {
85                print STDERR "$f lists $v in doc but $1 in file\n";
86                $error++;
87            }
88            last;
89        }
90    }
91    close($fh);
92}
93
94# get all the files
95my @cmdopts = cmdfiles($cmddir);
96
97# get all the options mentioned in $o
98my @veropts = mentions($opts);
99
100# check if all files are in the doc
101for my $c (sort @cmdopts) {
102    if($oiv{$c}) {
103        # present, but at same version?
104        versioncheck($c, $oiv{$c});
105    }
106    else {
107        print STDERR "--$c is in the option directory but not in $opts!\n";
108        $error++;
109    }
110}
111
112# check if the all options in the doc have files
113for my $v (sort @veropts) {
114    if($file{$v}) {
115        # present
116    }
117    else {
118        print STDERR "$v is in the doc but NOT as a file!\n";
119        $error++;
120    }
121}
122
123print STDERR "ok\n" if(!$error);
124
125exit $error;
126