enh: tests: faster perl-check script

pull/336/head
Stéphane Lesimple 4 years ago committed by Stéphane Lesimple
parent ebebed7be0
commit 0c96df0a3d

@ -5,13 +5,17 @@ basedir=$(readlink -f "$(dirname "$0")"/../..)
# shellcheck source=lib/shell/functions.inc
. "$basedir"/lib/shell/functions.inc
cmdline='-Mstrict -Mwarnings'
(( fails=0 ))
# shellcheck disable=SC2064
trap "rm -f $resultfile" EXIT
resultfile=$(mktemp)
cmdline="-Mstrict -Mwarnings -I$basedir/lib/perl"
action_doing "Checking perl files syntax"
for i in $(find "$basedir"/bin -type f ! -name "*.orig") $(find "$basedir"/lib/perl -type f -name "*.pm") $(find "$basedir"/lib/perl -type f -name "*.inc")
do
i=$(readlink -f "$i")
if head -n1 "$i" | grep -Eq '/perl|/env perl' || head -n2 "$i" | grep -Eq '^package ' ; then
(
action_detail "${BLUE}$i${NOC}"
if grep -q -- 'perl -T' "$i"; then
# shellcheck disable=SC2086
@ -20,20 +24,33 @@ do
# shellcheck disable=SC2086
perl $cmdline -c "$i" 2>&1 | grep -v OK$
fi
[ "${PIPESTATUS[0]}" -ne 0 ] && (( fails++ ))
[ -n "$DEBUG" ] || continue
grep -q '^use warnings' "$i" && echo "(spurious use warnings in $i)"
grep -q '^use strict' "$i" && echo "(spurious use strict in $i)"
grep -q '^use common::sense;' "$i" || echo "(missing common::sense in $i)"
if [ "${PIPESTATUS[0]}" -ne 0 ]; then
# shellcheck disable=SC2094
flock "$resultfile" echo -n . >> "$resultfile"
exit 1
fi
if [ -n "$DEBUG" ]; then
grep -q '^use warnings' "$i" && echo "(spurious use warnings in $i)"
grep -q '^use strict' "$i" && echo "(spurious use strict in $i)"
grep -q '^use common::sense;' "$i" || echo "(missing common::sense in $i)"
fi
) &
fi
done
if [ -x "$basedir/bin/dev/perl-use-all.sh" ] ; then
"$basedir/bin/dev/perl-use-all.sh" || (( fails++ ))
fi
# wait for all parallel check processes to be done
wait
fails=$(wc -c < "$resultfile")
if [ "$fails" -ne 0 ] ; then
action_error "Got $fails errors"
exit "$fails"
else
action_done "success"
action_done ""
fi
if [ -x "$basedir/bin/dev/perl-use-all.sh" ] ; then
"$basedir/bin/dev/perl-use-all.sh"
exit $?
fi
exit "$fails"

@ -5,35 +5,36 @@ basedir=$(readlink -f "$(dirname "$0")"/../..)
# shellcheck source=lib/shell/functions.inc
. "$basedir"/lib/shell/functions.inc
action_doing "Checking list of needed Perl modules..."
missing=""
# shellcheck disable=SC2013
for module in $(grep -RhEw '(use|require) ([a-zA-Z][a-zA-Z0-9_:]+)' "$basedir/lib/perl/" "$basedir/bin/" | \
modules=$(
grep -RhEw '(use|require) ([a-zA-Z][a-zA-Z0-9_:]+)' "$basedir/lib/perl/" "$basedir/bin/" | \
grep -v -e '"' -e "'" -e '# pragma optional module' -e OVH:: | \
sed -re 's/#.*//' | \
grep -Eo '(use|require) ([a-zA-Z][a-zA-Z0-9_:]+)' | \
awk '{print $2}' | \
sort -u | \
grep -Ev '^[a-z0-9_]+$')
do
if [ "$1" != "corelist" ]; then
grep -Ev '^[a-z0-9_]+$'
)
if [ "$1" = "corelist" ]; then
action_doing "Computing list of non-CORE needed Perl modules..."
# shellcheck disable=SC2086
for module in $(corelist $modules | awk '/was not in CORE/ {print $1}' | sort); do
action_detail "$module"
done
else
action_doing "Checking whether all required modules are installed..."
perlcmdline="perl "
for module in $modules; do
action_detail "$module"
if ! perl -M"$module" -e 1; then
action_detail "... failed!"
missing="$missing $module"
fi
perlcmdline="$perlcmdline -M$module"
done
perlcmdline="$perlcmdline -e 1"
if ! $perlcmdline; then
action_error "Some modules are missing!"
exit 1
else
if corelist "$module" | grep -q 'not in CORE'; then
action_detail "$module"
fi
action_done ""
fi
done
if [ -n "$missing" ]; then
action_error "Missing modules:$missing"
else
# shellcheck disable=SC2119
action_done
fi

Loading…
Cancel
Save