public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Sami Kerola <kerolasa@iki.fi>
To: util-linux@vger.kernel.org
Cc: kerolasa@iki.fi, Peter Schiffer <pschiffe@redhat.com>
Subject: [PATCH 08/14] tools: add checks to manual page test script
Date: Mon,  8 Apr 2013 20:32:53 +0100	[thread overview]
Message-ID: <1365449579-13238-9-git-send-email-kerolasa@iki.fi> (raw)
In-Reply-To: <1365449579-13238-1-git-send-email-kerolasa@iki.fi>

This change includes

- better way to detect manual page inclusion
- man -k header test, which uses lexgrog
- repeated word detection
- static declaration to known repeated words

Most of the  changes are based on man-page-day-1.sh, that is in use at
RedHat Quality Assurance, and wrote by Peter Schiffer.

CC: Peter Schiffer <pschiffe@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 tools/checkmans.sh | 98 +++++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 74 insertions(+), 24 deletions(-)

diff --git a/tools/checkmans.sh b/tools/checkmans.sh
index 4b149d0..a987f41 100755
--- a/tools/checkmans.sh
+++ b/tools/checkmans.sh
@@ -13,15 +13,21 @@ SCRIPT_INVOCATION_SHORT_NAME=$(basename ${0})
 trap 'echo "${SCRIPT_INVOCATION_SHORT_NAME}: exit on error"; exit 1' ERR
 
 usage() {
-	echo "Usage: ${0} [-ph]"
-	echo " -p   print file names before checking"
+	echo "Usage: ${0} [-vVh]"
+	echo " -v  verbose messaging"
+	echo " -V  print version and exit"
+	echo " -h  print this help and exit"
 }
 
-PRINT_FILE_NAMES='false'
-while getopts ph OPTIONS; do
+VERBOSE='false'
+while getopts vVh OPTIONS; do
 	case ${OPTIONS} in
-		p)
-			PRINT_FILE_NAMES='true'
+		v)
+			VERBOSE='true'
+			;;
+		V)
+			echo "util-linux: ${SCRIPT_INVOCATION_SHORT_NAME}: 2"
+			exit 0
 			;;
 		h)
 			usage
@@ -37,39 +43,83 @@ ERROR_FILE=$(mktemp ${SCRIPT_INVOCATION_SHORT_NAME}.XXXXXXXXXX)
 # remove tmp file at exit
 trap "rm -f ${ERROR_FILE}" 0
 
+COUNT_ERRORS=0
+declare -a REPEATS
+declare -A KNOWN_REPEATS
+KNOWN_REPEATS[mount.8]='foo'
+KNOWN_REPEATS[sfdisk.8]="0 <c,h,s>"
+KNOWN_REPEATS[flock.1]='"$0"'
+KNOWN_REPEATS[switch_root.8]='$DIR'
+
+remove_repeats()
+{
+	set +u
+	for KN in ${KNOWN_REPEATS[${I##*/}]}; do
+		if [ "${KN}" = "${REPEATS[$1]}" ]; then
+			if $VERBOSE; then
+				echo "info: ${I} removing repeat: ${REPEATS[$1]}"
+			fi
+			unset REPEATS[$1]
+		fi
+	done
+	set -u
+}
+
 for I in $(
 	find $(git rev-parse --show-toplevel) -name '*.[1-8]' |
 	egrep -v '(Documentation|.git|/.libs/|autom4te.cache)'
 ); do
-	# FIXME: the determination whether a manual does include
-	# should probably be somewhat smarter.
-	IS_INCLUDE=$(wc -w ${I} | awk '{print $1}')
-	if [ ${IS_INCLUDE} -eq 2 ]; then
-		# Some manuals, such as x86_64, call include which
-		# will read system manual.  Testing what comes from
-		# package does not make much sense, so skip doing it.
-		if ${PRINT_FILE_NAMES}; then
-			echo "skipping: ${I}"
+	if awk '{if (1 < NR) {exit 1}; if ($1 ~ /^.so$/) {exit 0}}' ${I}; then
+		# Some manuals, such as x86_64, call inclusion and they
+		# should not be tested any further.
+		if ${VERBOSE}; then
+			printf "skipping: ${I}: includes "
+			awk '{print $2}' ${I}
 		fi
 		continue
 	fi
-	if ${PRINT_FILE_NAMES}; then
+	I_ERR=0
+	if ${VERBOSE}; then
 		echo "testing: ${I}"
-		man --warnings=all ${I} >/dev/null
-	else
-		man --warnings=all ${I} >/dev/null 2>> ${ERROR_FILE}
 	fi
+	MANWIDTH=80 man --warnings=all ${I} >/dev/null 2>| ${ERROR_FILE}
+	if [ -s ${ERROR_FILE} ]; then
+		echo "error: run: man --warnings=all ${I} >/dev/null" >&2
+		I_ERR=1
+	fi
+	if ! lexgrog ${I} >/dev/null; then
+		echo "error: run: lexgrog ${I}" >&2
+		I_ERR=1
+	fi
+	REPEATS=( $(MANWIDTH=2000 man -l ${I} |
+		col -b |
+		sed  -e 's/\s\+/\n/g; /^$/d' |
+		awk 'BEGIN { p="" } { if (0 < length($0)) { if (p == $0) { print } } p = $0 }') )
+	if [ 0 -lt "${#REPEATS[@]}" ]; then
+		ITER=${#REPEATS[@]}
+		while [ -1 -lt ${ITER} ]; do
+			remove_repeats ${ITER}
+			# The 'let' may cause exit on error.
+			# When ITER == 0 -> let returns 1, bash bug?
+			let ITER=${ITER}-1 || true
+		done
+		if [ 0 -lt "${#REPEATS[@]}" ]; then
+			echo "warning: ${I} has repeating words: ${REPEATS[@]}"
+		fi
+	fi
+	# The 'let' may cause exit on error.
+	# COUNT_ERRORS=0; let COUNT_ERRORS=$COUNT_ERRORS+0; echo $?
+	# Is this a bash bug?
+	let COUNT_ERRORS=$COUNT_ERRORS+$I_ERR || true
 done
 
-COUNT_ERRORS=$(awk 'END {print NR}' ${ERROR_FILE})
 if [ ${COUNT_ERRORS} -ne 0 ]; then
-	echo "${SCRIPT_INVOCATION_SHORT_NAME}: failed"
-	echo "use: $(readlink -f ${0}) -p"
-	echo "     to find where the problems are."
+	echo "error: ${SCRIPT_INVOCATION_SHORT_NAME}: ${COUNT_ERRORS} manuals failed" >&2
 	exit 1
 fi
 
-if ! ${PRINT_FILE_NAMES}; then
+if ! ${VERBOSE}; then
 	echo "${SCRIPT_INVOCATION_SHORT_NAME}: success"
 fi
+
 exit 0
-- 
1.8.2.1


  parent reply	other threads:[~2013-04-08 19:33 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-08 19:32 [PATCH 00/14] [pull] smatch scan, and manual tooling Sami Kerola
2013-04-08 19:32 ` [PATCH 01/14] setarch: clean up usage() Sami Kerola
2013-04-08 19:32 ` [PATCH 02/14] bash-completion: setarch: use correct list for architectures Sami Kerola
2013-04-08 19:32 ` [PATCH 03/14] bash-completion: swapon: add options and fix argument Sami Kerola
2013-04-08 19:32 ` [PATCH 04/14] various: fix variable and function declarations [smatch scan] Sami Kerola
2013-04-08 19:32 ` [PATCH 05/14] various: fix shadow " Sami Kerola
2013-04-08 19:32 ` [PATCH 06/14] libmount, col: remove redundant null checks " Sami Kerola
2013-04-08 19:32 ` [PATCH 07/14] libblkid: number of functions should not be declared extern " Sami Kerola
2013-04-08 19:32 ` Sami Kerola [this message]
2013-04-08 19:32 ` [PATCH 09/14] docs: mount.8: make propagation flags adjustable [checkmans.sh] Sami Kerola
2013-04-08 19:32 ` [PATCH 10/14] docs: col.1: fix manual page name section [checkmans.sh] Sami Kerola
2013-04-08 19:32 ` [PATCH 11/14] docs: remove repeated words [checkmans.sh] Sami Kerola
2013-04-08 19:32 ` [PATCH 12/14] tools: make checkmans.sh to find missing manuals Sami Kerola
2013-04-08 19:32 ` [PATCH 13/14] docs: add mkfs.cramfs manual page Sami Kerola
2013-04-08 19:32 ` [PATCH 14/14] docs: add fsck.cramfs " Sami Kerola
2013-04-09 10:30 ` [PATCH 00/14] [pull] smatch scan, and manual tooling Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1365449579-13238-9-git-send-email-kerolasa@iki.fi \
    --to=kerolasa@iki.fi \
    --cc=pschiffe@redhat.com \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox