curl/tests/test1707.pl
Daniel Stenberg 9a0cf56471
curl: --help [option] displays documentation for given cmdline option
Since the documentation text blob might be gzipped, it needs to search
for what to output in a streaming manner. It then first searches for
"\nALL OPTIONS".

Then, it looks for the start to display at "\n    -[option]" and stops
again at "\n    -". Except for the last option in the man page, which
ends at "\nFILES" - the subtitle for the section following all options
in the manpage.

Test 1707 to 1710 verify

Closes #13997
2024-08-04 16:06:17 +02:00

122 lines
2.8 KiB
Perl
Executable File

#!/usr/bin/env perl
#***************************************************************************
# _ _ ____ _
# Project ___| | | | _ \| |
# / __| | | | |_) | |
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at https://curl.se/docs/copyright.html.
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the COPYING file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
# SPDX-License-Identifier: curl
#
###########################################################################
#
# This script grew out of help from Przemyslaw Iskra and Balint Szilakszi
# a late evening in the #curl IRC channel.
#
use strict;
use warnings;
my $curl = shift @ARGV;
my $opt = shift @ARGV;
my $output = shift @ARGV;
my $txt = shift @ARGV;
my $longopt;
my $shortopt;
if($opt =~ /^--/) {
$longopt = $opt;
}
else {
$shortopt = $opt;
}
# first run the help command
system("$curl -h $opt > $output");
my @curlout;
open(O, "<$output");
push @curlout, <O>;
close(O);
# figure out the short+long option combo using -h all*/
open(C, "$curl -h all|");
if($shortopt) {
while(<C>) {
if(/^ +$opt, ([^ ]*)/) {
$longopt = $1;
last;
}
}
}
else {
while(<C>) {
my $f = $_;
if(/ $opt /) {
if($f =~ /^ *(-(.)), $longopt/) {
$shortopt = $1;
}
last;
}
}
}
close(C);
my $fullopt;
if($shortopt) {
$fullopt = "$shortopt, $longopt";
}
else {
$fullopt = $longopt;
}
open(R, "<$txt");
my $show = 0;
my @txtout;
while(<R>) {
if(/^ $fullopt/) {
$show = 1;
}
elsif(/^ -/ && $show) {
last;
}
if($show) {
push @txtout, $_;
}
}
close(R);
my $error;
if(scalar(@curlout) != scalar(@txtout)) {
printf "curl -h $opt is %d lines, $txt says %d lines\n",
scalar(@curlout), scalar(@txtout);
$error++;
}
else {
# same size, compare line by line
for my $i (0 .. $#curlout) {
# trim CRLF from the data
$curlout[$i] =~ s/[\r\n]//g;
$txtout[$i] =~ s/[\r\n]//g;
if($curlout[$i] ne $txtout[$i]) {
printf "Line %d\n", $i;
printf "-h : %s\n", $curlout[$i];
printf "file : %s\n", $txtout[$i];
$error++;
}
}
}
exit $error;