Gentoo Archives: gentoo-dev

From: Mike Frysinger <vapier@g.o>
To: gentoo-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: Re: [gentoo-dev] eclass/tests/tests-common.sh: debug-print family of functions
Date: Sat, 09 Oct 2010 21:36:03
Message-Id: 201010091733.42001.vapier@gentoo.org
In Reply to: [gentoo-dev] eclass/tests/tests-common.sh: debug-print family of functions by "Michał Górny"
1 On Saturday, October 09, 2010 11:16:38 Michał Górny wrote:
2 > +debug-print() {
3 > + while [[ ${1} ]]; do
4
5 use explicit -n here, although this could give incorrect behavior. better to
6 use [[ $# -gt 0 ]].
7
8 > + if [[ ${ECLASS_DEBUG_OUTPUT} = on ]]; then
9
10 if you're going to use [[]], then also use ==
11
12 > + echo "debug: ${1}" >&2
13 > + elif [[ -n ${ECLASS_DEBUG_OUTPUT} ]]; then
14 > + echo "debug: ${1}" >> "${ECLASS_DEBUG_OUTPUT}"
15 > + fi
16
17 this whole func is overkill. just use a single printf:
18 [[ $# -eq 0 ]] && return 0
19 if [[ ${ECLASS_DEBUG_OUTPUT} == "on" ]] ; then
20 printf 'debug: %s\n' "$@" >&2
21 elif [[ -n ${ECLASS_DEBUG_OUTPUT} ]] ; then
22 printf 'debug: %s\n' "$@" >> "${ECLASS_DEBUG_OUTPUT}"
23 fi
24
25 > +debug-print-function() {
26 > + local f="${1}: entering function"
27 > + shift
28 > + debug-print "${f}, parameters: ${*}"
29 > +}
30
31 debug-print ${1}: entering function, parameters: ${*:2}"
32 -mike

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies