Most of the time, test requirements can be checked without much setup.
However, in some cases, it's not possible to know if the test can be run
until we're halfway through the test. Allow setting SKIP_REASON from the
test function. This should only be used as a last resort.
_cleanup
- if ! diff "tests/${TEST_NAME}.out" "${seqres}.out" >/dev/null; then
+ if [[ -v SKIP_REASON ]]; then
+ TEST_RUN["status"]="not run"
+ elif ! diff "tests/${TEST_NAME}.out" "${seqres}.out" >/dev/null; then
mv "${seqres}.out" "${seqres}.out.bad"
TEST_RUN["status"]=fail
TEST_RUN["reason"]=output
# failure. You should prefer letting the test fail because of broken output
# over, say, checking the exit status of every command you run.
#
+# If the test cannot be run, this function may set the \$SKIP_REASON variable
+# and return. In that case, the return value and output are ignored, and the
+# test is considered skipped. This should only be done when the requirements
+# can only be detected with a non-trivial amount of setup; use
+# group_requires(), requires(), and/or device_requires() instead when possible.
+#
# Various variables are defined for the test:
# - \$TEST_NAME -- the full name of the test.
# - \$TMPDIR -- a temporary directory deleted after the test is run.
--- /dev/null
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2020 Omar Sandoval
+#
+# Test skipping from test().
+
+. tests/meta/rc
+
+DESCRIPTION="skip in test()"
+
+test() {
+ SKIP_REASON="(╯°□°)╯︵ ┻━┻"
+}
--- /dev/null
+Running meta/014
+Test complete
--- /dev/null
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2020 Omar Sandoval
+#
+# Test skipping from test_device().
+
+. tests/meta/rc
+
+DESCRIPTION="skip in test_device()"
+
+test_device() {
+ SKIP_REASON="(╯°□°)╯︵ ┻━┻"
+}
--- /dev/null
+Running meta/015
+Test complete