git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Brandon Williams" <bmwill@google.com>,
	"Jeff King" <peff@peff.net>,
	"Joachim Durchholz" <jo@durchholz.org>,
	"Stefan Beller" <sbeller@google.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH 2/2] test-lib: exhaustively insert non-alnum ASCII into the TRASH_DIRECTORY name
Date: Sun,  9 Apr 2017 19:11:17 +0000	[thread overview]
Message-ID: <20170409191117.25175-3-avarab@gmail.com> (raw)
In-Reply-To: <20170409191117.25175-1-avarab@gmail.com>

Change the test library to insert non-alphanumeric ASCII characters
into the TRASH_DIRECTORY name, that's the directory the test library
creates, chdirs to and runs each individual test from.

Unless test_fails_on_unusual_directory_names=1 is declared before
importing test-lib.sh (and if perl isn't available on the system), the
trash directory will contain every non-alphanumeric character in
ASCII, in order.

This includes all the control characters, !, [], {} etc. the "."
character isn't included because it's already in the directory name,
and nor is "/" for obvious reasons, although that would actually work,
we'd just create a subdirectory, which would make the tests harder to
inspect when they fail.i

This change is inspired by the "submodule: prevent backslash expantion
in submodule names" patch[1]. If we'd had backslashes in the
TRASH_DIRECTORY all along that bug would have been fixed a long time
ago. This will flag such issues by marking tests that currently fail
with "test_fails_on_unusual_directory_names=1", ensure that new tests
aren't added unless a discussion is had about why the code can't
handle unusual pathnames, and prevent future regressions.

1. <20170407172306.172673-1-bmwill@google.com>
---
 t/README      | 12 ++++++++++++
 t/test-lib.sh |  4 ++++
 2 files changed, 16 insertions(+)

diff --git a/t/README b/t/README
index ab386c3681..314dd40221 100644
--- a/t/README
+++ b/t/README
@@ -345,6 +345,18 @@ assignment to variable 'test_description', like this:
 	This test registers the following structure in the cache
 	and tries to run git-ls-files with option --frotz.'
 
+By default the tests will be run from a directory with a highly
+unusual filename that includes control characters, a newline, various
+punctuation etc., this is done to smoke out any bugs related to path
+handling. If for whatever reason the tests can't deal with such
+unusual path names, set:
+
+    test_fails_on_unusual_directory_names=1
+
+Before sourcing 'test-lib.sh' as described below. This option is
+mainly intended to grandfather in existing broken tests & code, and
+should usually not be used in new code, instead your tests or code
+probably need fixing.
 
 Source 'test-lib.sh'
 --------------------
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 13b5696822..089ff5ac7d 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -914,6 +914,10 @@ fi
 
 # Test repository
 TRASH_DIRECTORY="trash directory.$(basename "$0" .sh)"
+if test -z "$test_fails_on_unusual_directory_names" -a "$(perl -e 'print 1+1' 2>/dev/null)" = "2"
+then
+   TRASH_DIRECTORY="$TRASH_DIRECTORY.$(perl -e 'print join q[], grep { /[^[:alnum:]]/ and !m<[./]> } map chr, 0x01..0x7f')"
+fi
 test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY"
 case "$TRASH_DIRECTORY" in
 /*) ;; # absolute path is good
-- 
2.11.0


  parent reply	other threads:[~2017-04-09 19:11 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-09 19:11 [PATCH 0/2] test: Detect *lots* of bugs by adding non-alnum to trash dir names Ævar Arnfjörð Bjarmason
2017-04-09 19:11 ` [PATCH 1/2] tests: mark tests that fail when the TEST_DIRECTORY is unusual Ævar Arnfjörð Bjarmason
2017-04-09 19:11 ` Ævar Arnfjörð Bjarmason [this message]
2017-04-10  1:47   ` [PATCH 2/2] test-lib: exhaustively insert non-alnum ASCII into the TRASH_DIRECTORY name SZEDER Gábor
2017-04-10  8:02     ` Ævar Arnfjörð Bjarmason
2017-04-10 11:19       ` SZEDER Gábor
2017-04-10 11:40         ` Ævar Arnfjörð Bjarmason
2017-04-10 13:38           ` Jeff King
2017-04-10 14:59             ` Joachim Durchholz
2017-04-10 16:57               ` Jeff King
2017-04-10 18:19                 ` Joachim Durchholz
2017-04-10 19:22                   ` Jeff King
2017-04-10 13:43           ` SZEDER Gábor
2017-04-10 23:23   ` Ævar Arnfjörð Bjarmason
2017-04-11  0:30     ` [PATCH] connect.c: handle errors from split_cmdline Jeff King
2017-04-11  0:35       ` Jeff King
2017-04-11  9:27         ` Ævar Arnfjörð Bjarmason
2017-04-11 10:54           ` Jeff King
2017-04-11 11:06             ` Ævar Arnfjörð Bjarmason
2017-04-17  0:51               ` Junio C Hamano
2017-04-17  0:54               ` Junio C Hamano
2017-04-19 10:59                 ` Ævar Arnfjörð Bjarmason
2017-04-11  1:14     ` [PATCH 2/2] test-lib: exhaustively insert non-alnum ASCII into the TRASH_DIRECTORY name Jeff King
2017-04-11  6:28     ` Joachim Durchholz
2017-04-09 20:37 ` [PATCH 0/2] test: Detect *lots* of bugs by adding non-alnum to trash dir names Joachim Durchholz

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=20170409191117.25175-3-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=bmwill@google.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jo@durchholz.org \
    --cc=peff@peff.net \
    --cc=sbeller@google.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).