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