Commit 7f35d750 authored by Charles Ferguson's avatar Charles Ferguson
Browse files

Add 'output_filter' function to try to give consistent output.

The output from the lint and test might look a little different, but
it is possible to combine the output so that we get something
consistent being written out. The output_filter is hoped to do that.
parent 9299a45c
......@@ -27,6 +27,7 @@ function bool() {
return 1
}
##
# Read a configuration parameter from the project's config.
#
......@@ -199,6 +200,73 @@ function call_if_function() {
}
##
# Report that we have started processing a file.
#
# @param $1 filename being looked at
# @param $2 message to display
function report_file() {
local filename="$1"
local message="$2"
echo " $filename: $message"
}
##
# Report that we have failed for some reason.
#
# @param $1 filename being looked at
# @param $2 message to display
function report_failure() {
local filename="$1"
local message="$2"
echo " $filename: $message"
}
##
# Operation output filter - a pipe that reports the status of the operations.
#
# @param $1 message for starting output (or '+' to indent with no message)
# @param $2 message for ending output (when something printed)
# @param $3 message for ending output (when nothing printed)
function output_filter() {
local start="$1"
local end_failure="$2"
local end_success="$3"
local line
local nlines=0
local indent
if [[ "$start" == '' ]] ; then
indent=' '
else
indent=' '
fi
while read line ; do
if [[ "$nlines" == '0' ]] ; then
if [[ "$start" != '' && "$start" != '+' ]] ; then
echo " $start"
fi
fi
echo "$indent$line"
nlines=$(( nlines+1 ))
done
if [[ "$nlines" == '0' ]] ; then
if [[ "$end_success" != '' ]] ; then
echo " $end_success"
fi
else
if [[ "$end_failure" != '' ]] ; then
echo " $end_failure"
fi
fi
}
function all_setup_test() {
local running="${1:-tests}"
......
......@@ -119,8 +119,7 @@ function perl_setup_lint() {
function perl_run_test() {
for test in $(config -e test_perl_files '*-test.pl') ; do
echo " Test '$test'..."
if perl "$test" | sed 's/^/ /' ; then
if perl "$test" 2>&1 | output_filter "Test '$test'..." ; then
tests_passed=$(( tests_passed + 1 ))
else
echo " Test '$test' failed"
......@@ -136,18 +135,22 @@ function perl_run_coverage() {
}
function perl_run_lint() {
local file
local message="Compiling Perl files"
for file in $(config -e lint_perl_files '*.pl *.pm') ; do
if ! perl -c "$file" 2>&1 | sed 's/^/ /'; then
if ! perl -c "$file" 2>&1 | output_filter "$message" ; then
lint_failed=$(( lint_failed+1 ))
else
lint_passed=$(( lint_passed+1 ))
fi
message="+"
done
if ! perlcritic --profile perlcriticrc \
--color \
$(config -e lint_perl_files '*.pl *.pm') \
2>&1 | sed 's/^/ /'; then
2>&1 | output_filter "Linting Perl files"; then
lint_failed=$(( lint_failed+1 ))
else
lint_passed=$(( lint_passed+1 ))
......
......@@ -161,7 +161,7 @@ function python_setup_coverage() {
python_setup_test "$@"
# Clear out any previous coverage data.
if [ -f .coverage ]; then
if [[ -f .coverage ]] ; then
rm -f .coverage
fi
}
......@@ -180,9 +180,8 @@ function python_run_test() {
local switches="$*"
for test in $(config -e test_python_files '*_test.py') ; do
echo " Test '$test'..."
if "$PYTHON_TOOL" "$test" -v $switches \
2>&1 | sed 's/^/ /' ; then
if "$PYTHON_TOOL" "$test" -v $switches 2>&1 \
| output_filter "Test '$test'..." ; then
tests_passed=$(( tests_passed + 1 ))
else
echo " Test '$test' failed"
......@@ -197,7 +196,10 @@ function python_run_coverage() {
}
function python_run_lint() {
if ! pylint --reports no --rcfile pylintrc $(config -e lint_python_files '*.py') ; then
if ! pylint --reports no \
--rcfile pylintrc \
$(config -e lint_python_files '*.py') 2>&1 \
| output_filter "Linting Python files" ; then
lint_failed=$(( lint_failed+1 ))
else
lint_passed=$(( lint_passed+1 ))
......@@ -208,7 +210,8 @@ function python_run_lint() {
function python_run_docs() {
if ! "${scripts}/python-build-docs" --initial-tag "$(config version_git_tag none)" \
--major-version "$(config version 1.0)" \
--paths "$(config docs_python_files '*.py')" ; then
--paths "$(config docs_python_files '*.py')" \
| output_filter ; then
docs_failed=$(( docs_failed+1 ))
else
docs_passed=$(( docs_passed+1 ))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment