From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH] test-lib: guard against being run as 'prove t*.sh'
Date: Thu, 11 Mar 2021 13:42:16 +0100 [thread overview]
Message-ID: <20210311124216.25036-1-avarab@gmail.com> (raw)
We have t/Makefile targets to properly run the tests with prove,
however it's also just as valid to run them as e.g.:
prove t[0-9]*.sh
But if they're run as:
prove t*.sh
The prove tool will optimistically try to parse and execute
test-lib.sh and test-lib-functions.sh as Perl code, currently there
are no bad results of doing this other than a wall of error messages,
but let's be helpful and bail out early in this case.
Note that the shebang being added here doesn't mean anything to a
POSIX OS because the files aren't executable, it's picked up by Perl's
TAP tools. If the shebang wasn't here this would still be considered a
Perl file for the purposes of those heuristics.
I could also use the "Bail out!" keyword here, see
614fe01521 (test-lib: bail out when "-v" used under "prove",
2016-10-22) for prior art. I think it's more gentle to just print a
SKIP notice.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
t/test-lib-functions.sh | 9 +++++++++
t/test-lib.sh | 9 +++++++++
2 files changed, 18 insertions(+)
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 6348e8d733..7ba04fe399 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1,3 +1,5 @@
+#!/bin/sh
+#
# Library of functions shared by all tests scripts, included by
# test-lib.sh.
#
@@ -16,6 +18,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/ .
+# Early bailing out on 'prove t*.sh'
+if test -n "$HARNESS_ACTIVE" -a "$0" = "test-lib-functions.sh"
+then
+ echo "1..0 # SKIP accidentally invoked 'prove t*.sh'?"
+ exit 0
+fi
+
# The semantics of the editor variables are that of invoking
# sh -c "$EDITOR \"$@\"" files ...
#
diff --git a/t/test-lib.sh b/t/test-lib.sh
index d3f6af6a65..7ceae9a38d 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1,3 +1,5 @@
+#!/bin/sh
+#
# Test framework for git. See t/README for usage.
#
# Copyright (c) 2005 Junio C Hamano
@@ -15,6 +17,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/ .
+# Early bailing out on 'prove t*.sh'
+if test -n "$HARNESS_ACTIVE" -a "$0" = "test-lib.sh"
+then
+ echo "1..0 # SKIP accidentally invoked 'prove t*.sh'?"
+ exit 0
+fi
+
# Test the binaries we have just built. The tests are kept in
# t/ subdirectory and are run in 'trash directory' subdirectory.
if test -z "$TEST_DIRECTORY"
--
2.31.0.rc2.211.g1d0b8788b3
next reply other threads:[~2021-03-11 12:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-11 12:42 Ævar Arnfjörð Bjarmason [this message]
2021-03-11 17:33 ` [PATCH] test-lib: guard against being run as 'prove t*.sh' Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210311124216.25036-1-avarab@gmail.com \
--to=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).