test1486.pl 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. use strict;
  28. use warnings;
  29. # we may get the dir root pointed out
  30. my $root=$ARGV[0] || ".";
  31. my %insrc; # variable set in source
  32. my %indocs; # variable described in docs
  33. my $srccount = 1;
  34. sub getsrcvars {
  35. open(my $f, "<", "$root/../src/tool_writeout.c");
  36. my $mode = 0;
  37. while(<$f>) {
  38. if(!$mode &&
  39. ($_ =~ /^static const struct writeoutvar/)) {
  40. $mode = 1;
  41. }
  42. if($mode) {
  43. if($_ =~ /^}/) {
  44. last;
  45. }
  46. if($_ =~ /^ \{\"([^\"]*)/) {
  47. my $var = $1;
  48. $insrc{$var} = $srccount++;
  49. }
  50. }
  51. }
  52. close($f);
  53. }
  54. sub getdocsvars {
  55. open(my $f, "<", "$root/../docs/cmdline-opts/write-out.md");
  56. while(<$f>) {
  57. if($_ =~ /^\#\# \`([^\`]*)\`/) {
  58. $indocs{$1} = 1;
  59. }
  60. }
  61. close($f);
  62. }
  63. getsrcvars();
  64. getdocsvars();
  65. my $error = 0;
  66. if((scalar(keys %indocs) < 10) || (scalar(keys %insrc) < 10)) {
  67. print "problems to extract variables\n";
  68. $error++;
  69. }
  70. # also verify that the source code lists them alphabetically
  71. my $check = 1;
  72. for(sort keys %insrc) {
  73. if($insrc{$_} && !$indocs{$_}) {
  74. print "$_ is not mentioned in write.out.md\n";
  75. $error++;
  76. }
  77. if($insrc{$_} ne $check) {
  78. print "$_ is not in alphabetical order\n";
  79. $error++;
  80. }
  81. $check++;
  82. }
  83. for(sort keys %indocs) {
  84. if($indocs{$_} && !$insrc{$_}) {
  85. print "$_ documented, but not used in source code\n";
  86. $error++;
  87. }
  88. }
  89. print "OK\n" if(!$error);
  90. exit $error;