xref: /curl/tests/test1488.pl (revision 8c1d9378)
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
30use strict;
31use warnings;
32use vars qw($Cpreprocessor);
33
34#
35# configurehelp perl module is generated by configure script
36#
37my $rc = eval {
38    require configurehelp;
39    configurehelp->import(qw(
40        $Cpreprocessor
41    ));
42    1;
43};
44# Set default values if configure has not generated a configurehelp.pm file.
45# This is the case with cmake.
46if (!$rc) {
47    $Cpreprocessor = 'cpp';
48}
49
50# we may get the dir root pointed out
51my $root=$ARGV[0] || ".";
52
53# need an include directory when building out-of-tree
54my $i = ($ARGV[1]) ? "-I$ARGV[1] " : '';
55my $error;
56
57
58my @syms;
59my %manpage;
60my %symadded;
61
62sub checkmanpage {
63    my ($m) = @_;
64
65    open(my $mh, "<", "$m");
66    my $line = 1;
67    my $title;
68    my $addedin;
69    while(<$mh>) {
70        if(/^Title: (.*)/i) {
71            $title = $1;
72        }
73        elsif(/^Added-in: (.*)/i) {
74            $addedin = $1;
75        }
76        if($addedin && $title) {
77            if($manpage{$title}) {
78                print "$title is a duplicate symbol in file $m\n";
79                $error++;
80            }
81            $manpage{$title} = $addedin;
82            last;
83        }
84        $line++;
85    }
86    close($mh);
87}
88
89sub scanman_md_dir {
90    my ($d) = @_;
91    opendir(my $dh, $d) ||
92        die "Can't opendir: $!";
93    my @mans = grep { /.md\z/ } readdir($dh);
94    closedir $dh;
95    for my $m (@mans) {
96        checkmanpage("$d/$m");
97    }
98}
99
100scanman_md_dir("$root/docs/libcurl");
101scanman_md_dir("$root/docs/libcurl/opts");
102
103open my $s, "<", "$root/docs/libcurl/symbols-in-versions";
104while(<$s>) {
105    if(/(^[^ \n]+) +(.*)/) {
106        my ($sym, $rest)=($1, $2);
107        my @a=split(/ +/, $rest);
108        push @syms, $sym;
109
110        $symadded{$sym}=$a[0];
111    }
112}
113close $s;
114
115my $ignored=0;
116for my $e (sort @syms) {
117    if( $manpage{$e} ) {
118
119        if( $manpage{$e} ne $symadded{$e} ) {
120            printf "%s.md says version %s, but SIV says %s\n",
121                $e, $manpage{$e}, $symadded{$e};
122            $error++;
123        }
124
125    }
126}
127print "OK\n" if(!$error);
128exit $error;
129