File: 05_docs.t

package info (click to toggle)
check-postgres 2.21.0-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 952 kB
  • ctags: 319
  • sloc: perl: 10,232; makefile: 13; sh: 13
file content (87 lines) | stat: -rw-r--r-- 2,157 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!perl

## Some basic checks on the documentation

use 5.006;
use strict;
use warnings;
use Data::Dumper;
use Test::More;

plan tests => 4;

## Make sure the POD actions are in the correct order (same as --help)
my $file = 'check_postgres.pl';
my ($fh, $slurp);
if (!open $fh, '<', $file) {
    if (!open $fh, '<', "../$file") {
        die "Could not find $file!\n";
    }
}
{
    local $/;
    $slurp = <$fh>;
}
close $fh or warn qq{Could not close "$file": $!\n};

if ($slurp !~ /\$action_info = (.+?)\}/s) {
  fail q{Could not find the 'action_info' section};
}
my $chunk = $1;
my @actions;
for my $line (split /\n/ => $chunk) {
  push @actions => $1 if $line =~ /^\s*(\w+)/;
}

## Make sure each of those still exists as a subroutine
for my $action (@actions) {
  next if $action =~ /last_auto/;

  my $match = $action;
  $match = 'pgb_pool' if $match =~ /pgb_pool/;

  if ($slurp !~ /\n\s*sub check_$match/) {
    fail qq{Could not find a check sub for the action '$action' ($match)!};
  }
}
pass 'Found matching check subroutines for each action inside of action_info';

## Make sure each check subroutine is documented
while ($slurp =~ /\n\s*sub check_(\w+)/g) {
  my $match = $1;

  ## Skip known exceptions:
  next if $match eq 'last_vacuum_analyze' or $match eq 'pgb_pool';

  if (! grep { $match eq $_ } @actions) {
    fail qq{The check subroutine check_$match was not found in the help!};
  }
}
pass 'Found matching help for each check subroutine';

## Make sure each item in the top help is in the POD
my @pods;
while ($slurp =~ /\n=head2 B<(\w+)>/g) {
  my $match = $1;

  ## Skip known exceptions:
  next if $match =~ /symlinks/;

  if (! grep { $match eq $_ } @actions) {
    fail qq{The check subroutine check_$match was not found in the POD!};
  }

  push @pods => $match;
}
pass 'Found matching POD for each check subroutine';

## Make sure things are in the same order for both top (--help) and bottom (POD)
for my $action (@actions) {
  my $pod = shift @pods;
  if ($action ne $pod) {
    fail qq{Docs out of order: expected $action in POD section, but got $pod instead!};
  }
}
pass 'POD actions appear in the correct order';

exit;