1#!/bin/bash
2# Tests man pages.
3#
4# Version: 20190302
5
6EXIT_SUCCESS=0;
7EXIT_FAILURE=1;
8EXIT_IGNORE=77;
9
10run_test()
11{
12	local INPUT_FILE=$1;
13	local RESULT=0
14
15	TEST_NAME=`basename ${INPUT_FILE}`;
16	echo -n "Testing man with input: ${TEST_NAME}";
17
18	LC_ALL=en_US.UTF-8 MANROFFSEQ='' MANWIDTH=80 man --warnings -E UTF-8 -l -Tutf8 -Z ${INPUT_FILE} > /dev/null 2> ${TMPDIR}/${TEST_NAME}.warnings;
19	RESULT=$?;
20
21	# For now line break warnings are ignored.
22	if test -f ${TMPDIR}/${TEST_NAME}.warnings;
23	then
24		sed "/can't break line/ d" -i ${TMPDIR}/${TEST_NAME}.warnings;
25	fi
26	if test -s ${TMPDIR}/${TEST_NAME}.warnings;
27	then
28		RESULT=${EXIT_FAILURE};
29	fi
30	if test ${RESULT} -ne ${EXIT_SUCCESS};
31	then
32		echo " (FAIL)";
33	else
34		echo " (PASS)";
35	fi
36	if test -s ${TMPDIR}/${TEST_NAME}.warnings;
37	then
38		cat ${TMPDIR}/${TEST_NAME}.warnings;
39	fi
40	return ${RESULT};
41}
42
43if test "${OSTYPE}" = "msys";
44then
45	exit ${EXIT_IGNORE};
46fi
47
48TEST_RUNNER="tests/test_runner.sh";
49
50if ! test -f "${TEST_RUNNER}";
51then
52	TEST_RUNNER="./test_runner.sh";
53fi
54
55if ! test -f "${TEST_RUNNER}";
56then
57	echo "Missing test runner: ${TEST_RUNNER}";
58
59	exit ${EXIT_FAILURE};
60fi
61
62source ${TEST_RUNNER};
63
64assert_availability_binary man;
65
66RESULT=${EXIT_IGNORE};
67
68TMPDIR="tmp$$";
69
70rm -rf ${TMPDIR};
71mkdir ${TMPDIR};
72
73MANUALS_PATH="../manuals";
74
75if ! test -d ${MANUALS_PATH};
76then
77	MANUALS_PATH="manuals";
78fi
79
80if ! test -d ${MANUALS_PATH};
81then
82	echo "Manuals directory not found.";
83
84	exit ${EXIT_IGNORE};
85fi
86
87for INPUT_FILE in ${MANUALS_PATH}/*.[13];
88do
89	run_test "${INPUT_FILE}";
90	RESULT=$?;
91
92	if test ${RESULT} -ne ${EXIT_SUCCESS};
93	then
94		break;
95	fi
96done
97
98rm -rf ${TMPDIR};
99
100exit ${RESULT};
101
102