Skip to content

Commit

Permalink
add -h and --dfsg options to tests
Browse files Browse the repository at this point in the history
Use getopt(1) to provide -h, --help, and --dfsg options in
test/fetch-test-deps.sh and test/run-tests.sh

- -h or --help prints a usage message
- --dfsg skips repositories with non-free licenses (pokecrystal
  and pokered) in favor of ucity to support packaging RGBDS for
  Debian
- --dfsg can be combined with --get-hash or --get-paths

change --dfsg option to --only-free

I was told the `+dfsg.1` used in Debian's repacks of upstream repos
and tarballs that contain non-free software is too obscure.  ISSOtm
and Rangi42 suggested `--only-free` which carries no Debian baggage.
https://www.reddit.com/r/debian/comments/66094l/what_is_dfsg_in_package_version_numbers/

- change --dfsg option to --only-free
- temporarily enable logging (set -x) to troubleshoot build failure
  on macOS

don't depend on util-linux getopt

util-linux getopt has long option parsing functionality not
available in macOS getopt.  Instead, parse the options in pure
Bash, treating each option as a separate word.

remove tracing from test

The removal of getopt indeed fixed test scripts on macOS.
This means we no longer need set -x to trace execution.

Co-authored-by: Eldred Habert <[email protected]>

use true/false for booleans in test scripts

I haven't had a chance to read the `bash(1)` manual cover to cover
(reading 6600 lines in `less(1)` is an attention challenge to me)
but it appears `true` and `false` are preferred because `true(1)`
and `false(1)` run faster than `test(1)`, to which `[` is a link.

Co-authored-by: Eldred Habert <[email protected]>

act on stylistic nitpicks by Rangi42

- remove explanation of `set -e` even from run-tests.sh, which had
  previously included one
- visually distinguish explanations of sections of a script from
  explanations of individual functions within a section
- change variable names that refer to script names to match the
  capitalized default filename of the script minus any extension
- change variable names that do not refer to script names to
  lowercase

Apply suggestions from code review

Co-authored-by: Rangi <[email protected]>

remane with_nonfree variable in tests to nonfree

per @Rangi42's preference
  • Loading branch information
pinobatch committed Aug 19, 2023
1 parent 1689508 commit 360cf8f
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 11 deletions.
47 changes: 42 additions & 5 deletions test/fetch-test-deps.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,45 @@
#!/usr/bin/env bash

set -e

cd "$(dirname "$0")"

case "$1" in
usage() {
echo "Downloads source code of Game Boy programs used as RGBDS test cases."
echo "Options:"
echo " -h, --help show this help message"
echo " --only-free download only freely licensed codebases"
echo " --get-hash print programs' commit hashes instead of downloading them"
echo " --get-paths print programs' GitHub paths instead of downloading them"
}

# Parse options in pure Bash because macOS `getopt` is stuck
# in what util-linux `getopt` calls `GETOPT_COMPATIBLE` mode
nonfree=true
actionname=
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
usage
exit 0
;;
--only-free)
nonfree=false
;;
--get-hash|--get-paths)
actionname="$1"
;;
--)
break
;;
*)
echo "$(basename $0): unknown option "$1""
exit 1
;;
esac
shift
done

case "$actionname" in
--get-hash)
action() { # owner/repo shallow-since commit
printf "%s@%s-" "${1##*/}" "$3"
Expand Down Expand Up @@ -33,6 +68,8 @@ case "$1" in
}
esac

action pret/pokecrystal 2022-09-29 70a3ec1accb6de1c1c273470af0ddfa2edc1b0a9
action pret/pokered 2022-09-29 2b52ceb718b55dce038db24d177715ae4281d065
action AntonioND/ucity 2022-04-20 d8878233da7a6569f09f87b144cb5bf140146a0f
if "$nonfree"; then
action pret/pokecrystal 2022-09-29 70a3ec1accb6de1c1c273470af0ddfa2edc1b0a9
action pret/pokered 2022-09-29 2b52ceb718b55dce038db24d177715ae4281d065
fi
action AntonioND/ucity 2022-04-20 d8878233da7a6569f09f87b144cb5bf140146a0f
43 changes: 37 additions & 6 deletions test/run-tests.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,40 @@
#!/usr/bin/env bash

# Return failure as soon as a command fails to execute

set -e

cd "$(dirname "$0")"

usage() {
echo "Runs regression tests on RGBDS."
echo "Options:"
echo " -h, --help show this help message"
echo " --only-free skip tests that build nonfree codebases"
}

# Parse options in pure Bash because macOS `getopt` is stuck
# in what util-linux `getopt` calls `GETOPT_COMPATIBLE` mode
nonfree=true
FETCH_TEST_DEPS="fetch-test-deps.sh"
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
usage
exit 0
;;
--only-free)
nonfree=false
FETCH_TEST_DEPS="fetch-test-deps.sh --only-free"
;;
--)
break
;;
*)
echo "$(basename $0): internal error"
exit 1
;;
esac
shift
done

# Refuse to run if RGBDS isn't present
if [[ ! ( -x ../rgbasm && -x ../rgblink && -x ../rgbfix && -x ../rgbgfx ) ]]; then
echo "Please build RGBDS before running the tests"
Expand All @@ -27,14 +56,16 @@ done

test_downstream() { # owner/repo make-target
if ! pushd ${1##*/}; then
echo >&2 'Please run `fetch-test-deps.sh` before running the test suite'
echo >&2 'Please run `'"$FETCH_TEST_DEPS"'` before running the test suite'
return 1
fi
make clean
make -j4 $2 RGBDS=../../
popd
}

test_downstream pret/pokecrystal compare
test_downstream pret/pokered compare
if "$nonfree"; then
test_downstream pret/pokecrystal compare
test_downstream pret/pokered compare
fi
test_downstream AntonioND/ucity ''

0 comments on commit 360cf8f

Please sign in to comment.