Skip to content

Commit

Permalink
WIP: Improve argument parsing in tools/invoke-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Martchus committed Jul 20, 2020
1 parent fe3e12a commit 107fd14
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions tools/invoke-tests
@@ -1,27 +1,44 @@
#!/bin/bash -e

# process arguments
if [[ $1 == --coverage ]]; then
WITH_COVER_OPTIONS=1
shift
fi
if [[ $# -lt 3 ]]; then
echo "usage: $0 [--coverage] prove-tool-path make-tool-path build-directory [test-file...]"
source_directory=$(dirname "$0")/..
source_directory=$(realpath "$source_directory")

usage() {
echo "usage: $0 [options] [test-file...]
options:
--coverage record test coverage
--prove-tool prove tool to use (defaults to prove)
--make-tool make tool to use (defaults to make)
--build-directory build directory (defaults to $source_directory)"
exit
fi
prove_path=$1 make_path=$2 build_dir=$3
shift 3
}

# parse arguments
opts=$(getopt -o h --long help --long coverage --long prove-tool --long make-tool --long build-directory -- "$@") || usage
prove_path=prove make_path=make build_directory=$source_directory
eval set -- "$opts"
while true; do
case "$1" in
-h | --help ) shift; usage; ;;
--coverage ) shift; WITH_COVER_OPTIONS=1 ;;
--prove-tool ) shift; prove_path=$1 ;;
--make-tool ) shift; make_path=$1 ;;
--build-directory ) shift; build_directory=$1 ;;
-- ) shift; break ;;
* ) break ;;
esac
done
test_files=("$@")

# set Perl module include path and coverage options
export PERL5LIB="$PWD:$PWD/ppmclibs:$PWD/ppmclibs/blib/arch/auto/tinycv:$PERL5LIB"
export PERL5LIB="$source_directory:$source_directory/ppmclibs:$source_directory/ppmclibs/blib/arch/auto/tinycv:$PERL5LIB"
if [[ $WITH_COVER_OPTIONS ]]; then
path_regex="^|$PWD/|\\.\\./"
export PERL5OPT="-MDevel::Cover=-db,$build_dir/cover_db,-select,($path_regex)(OpenQA|backend|consoles|ppmclibs)/|($path_regex)isotovideo|($path_regex)[^/]+\.pm,-ignore,\.t|data/tests/|fake/tests/|$prove_path,-coverage,statement"
path_regex="^|$source_directory/|\\.\\./"
export PERL5OPT="-MDevel::Cover=-db,$build_directory/cover_db,-select,($path_regex)(OpenQA|backend|consoles|ppmclibs)/|($path_regex)isotovideo|($path_regex)[^/]+\.pm,-ignore,\.t|data/tests/|fake/tests/|$prove_path,-coverage,statement"
fi

# set variables for tests which need to invoke the make tool
export OS_AUTOINST_BUILD_DIRECTORY=$build_dir
export OS_AUTOINST_BUILD_DIRECTORY=$build_directory
export OS_AUTOINST_MAKE_TOOL=$make_path

# allow specifying the list of tests via TESTS in consistency with openQA; otherwise run all tests
Expand Down

0 comments on commit 107fd14

Please sign in to comment.