Merge Debian 3.0.33-2 (UNRELEASED) changes.
[privoxy.git] / debian / tests / conditional-defines.pl
1 #!/usr/bin/perl
2 #
3 # Check http://config.privoxy.org/show-status for Conditional #defines enabled
4 #
5 # (c) 2022 Roland Rosenfeld <roland@debian.org>
6
7 use strict;
8 use warnings;
9 use LWP::UserAgent ();
10 use HTML::TreeBuilder 5 -weak;
11
12 my $exitcode = 0;
13
14 my $ua = LWP::UserAgent->new(timeout => 10);
15 $ua->env_proxy;
16 my $response = $ua->get('http://config.privoxy.org/show-status');
17 if (!$response->is_success) {
18    die $response->status_line;
19 }
20 my $tree = HTML::TreeBuilder->new;
21 $tree->parse($response->decoded_content);
22
23 # Search for "Conditional #defines:" table:
24 my $summary = 'The state of some ./configure options and what they do.';
25 my $table = $tree->look_down('_tag' => 'table',
26                              'summary' => $summary);
27 unless (defined $table) {
28    die "summary '$summary' not found in tables";
29 }
30
31 # These features are intentionaly disabled, all others should be enabled:
32 my %disabled_features = ('FEATURE_ACCEPT_FILTER' => 1, # BSD only
33                          'FEATURE_STRPTIME_SANITY_CHECKS' =>1, # BSD libc only
34                          'FEATURE_GRACEFUL_TERMINATION' =>1, # devel only
35                         );
36
37 my $enabled = 0;
38 my $disabled_ok = 0;
39 my $disabled_nok = 0;
40 foreach my $tr ($table->look_down('_tag' => 'tr')) {
41    my $td2 = ($tr->look_down('_tag' => 'td')) [1];
42    next unless defined $td2;
43    my $code = $tr->look_down('_tag' => 'code');
44    my $feature = $code->detach_content;
45    my $value = $td2->detach_content;
46    if ($value !~ /Yes/) {
47       # feature disabled, check whitelist
48       if (! defined $disabled_features{$feature}) {
49          printf STDERR "%s is disabled, but should be enabled\n", $feature;
50          $exitcode = 1;
51          $disabled_nok++;
52       } else {
53          $disabled_ok++;
54       }
55    } else {
56       $enabled++;
57    }
58 }
59
60 printf "%d features enabled\n", $enabled;
61 printf "%d features intentionally disabled\n", $disabled_ok;
62 printf "%d features unintentionally disabled\n", $disabled_nok;
63
64 if ($enabled < 10) {
65    printf STDERR "Found only %d Conditional #defines, seems test ist broken\n",
66                  $enabled;
67    $exitcode = 1;
68 }
69
70 exit $exitcode;