chiark / gitweb /
c905445ba033f24862c3101ce9f98cfba9160ea7
[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{^(?:$_)$} } <PATS>;
41                 }
42                 next if m{$re};
43                 print STDERR "unexpected: $_";
44                 $bad = 1;
45                 END { die "unexpected, re= $re\n" if $bad; }
46         ' "$@"
47 }
48
49 expected txt dgit.1 <<'END'
50 .* # table wider than line width
51 END
52
53 prep () {
54         fmt=$1
55         errs=$tmp/$roff.$fmt-errs
56 }
57
58 check () {
59         perl -0777 -i~ -pe 's/\n[ \t]+/ # /' $errs
60         not_egrep_vxPf $tmp/$roff.$fmt-expected $errs
61 }
62
63 for roff in $manpages; do
64         section=${roff##*.}
65         page=${roff%.*}
66
67         prep txt
68         run_man
69         check
70 done
71
72 t-ok