Debian Codegraph @

man/check-man

raw
1 #! /bin/sh
2 set -e
3
4 # Check that a manual page formats without errors. Lintian does something
5 # similar for Debian packages. Relies on top_builddir and LINGUA variables
6 # exported from 'make check', or you can set them manually.
7
8 if [ -z "$top_builddir" ]; then
9 echo "top_builddir unset; try 'make check' instead?"
10 exit 77
11 elif [ -z "$LINGUA" ]; then
12 echo "LINGUA unset; try 'make check' instead?"
13 exit 77
14 fi
15
16 [ -x "$top_builddir/src/man" ] || exit 77
17
18 if [ -z "$MAN_TEST_INSTALLED" ]; then
19 PATH="$top_builddir/src:$PATH"
20 fi
21
22 run () {
23 if [ "$MAN_TEST_INSTALLED" ]; then
24 "$@"
25 else
26 # Ideally we'd test the installed manual pages too, but
27 # repeating the install transformation is fiddly, and we get
28 # most of the testing value by running man(1) from the
29 # installed system over the pages from the build tree.
30 "$top_builddir/libtool" --mode=execute \
31 -dlopen "$top_builddir/lib/.libs/libman.la" \
32 -dlopen "$top_builddir/libdb/.libs/libmandb.la" \
33 "$@"
34 fi
35 }
36
37 warnings=mac
38 # Ignore wrapping failures for CJK manual pages; this should go away once
39 # groff supports these natively.
40 # Indeed, even for other languages we're going to get "cannot adjust line"
41 # if %manpath_config_file% expands to something long. Hmm. We'll just ignore
42 # this across the board for now.
43 warnings="$warnings,!break"
44
45 code=0
46 errors="$(LC_ALL=C MANWIDTH=80 MAN_KEEP_FORMATTING=1 run man \
47 --warnings="$warnings" -E UTF-8 \
48 -l "$1" \
49 2>&1 >/dev/null)" || code=$?
50
51 if [ "$code" != 0 ]; then
52 echo "man -E UTF-8 -l $1 failed with exit status $code and error output:"
53 echo "$errors"
54 exit $code
55 elif [ "$errors" ]; then
56 echo "man -E UTF-8 -l $1 produced error output:"
57 echo "$errors"
58 exit 1
59 else
60 exit 0
61 fi