chiark / gitweb /
79efb87581af18278bff959c6ec5ab60a577ba07
[dgit.git] / tests / tests / manpages-format
1 #!/bin/bash
2 set -e
3 autoimport=
4 . tests/lib
5
6 t-dependencies man-db make groff git-debrebase
7
8 cd $root
9
10 printenv |grep MAKE ||: |sort
11 manpages=$(MAKEFLAGS= MAKELEVEL= make list-manpages)
12
13 export MANWIDTH=80
14
15 run_man () {
16         if [ "x${DGIT_MANPAGES_SOURCE_DIR}" = x ]; then
17                 cmd='man "$@" $section $page'
18         else
19                 make $roff >&2
20                 cmd='man "$@" -l $roff'
21         fi
22         eval "$cmd 2>&1 >/dev/null |tee $errs"
23 }
24
25 for roff in $manpages; do
26         for fmt in txt; do
27                 >$tmp/$roff.$fmt-expected
28         done
29 done
30
31 expected () {
32         cat >$tmp/$2.$1-expected
33 }
34
35 not_egrep_vxPf () {
36         # egrep -vxPf does not work, so we reimplement it
37         perl -ne '
38                 BEGIN () {
39                         open PATS, shift @ARGV or die $!;
40                         $re = join "|", map { chomp; qr{^(?:$_)$} }
41                                 qr{^(?=a)b}, <PATS>;
42                         print STDERR "RE $re\n";
43                 }
44                 next if m{$re};
45                 print STDERR "unexpected: $_";
46                 $bad = 1;
47                 END { die "unexpected errors\n" if $bad; }
48         ' "$@"
49 }
50
51 expected txt dgit.1 <<'END'
52 .* # table wider than line width
53 END
54
55 prep () {
56         fmt=$1
57         errs=$tmp/$roff.$fmt-errs
58 }
59
60 check () {
61         perl -0777 -i~ -pe 's/\n[ \t]+/ # /' $errs
62         not_egrep_vxPf $tmp/$roff.$fmt-expected $errs
63 }
64
65 for roff in $manpages; do
66         section=${roff##*.}
67         page=${roff%.*}
68
69         prep txt
70         run_man
71         check
72 done
73
74 t-ok