Subject: Re: [PATCH v2 8/8] travis-ci: only print test failures if there are

From: SZEDER Gábor <[email-masked]>
Date: Sat, 16 Dec 2017 23:48:39 +0100

> On Sat, Dec 16, 2017 at 7:58 AM, SZEDER G=C3=A1bor <[email-masked]> w=
> rote:

> > +if test t/test-results/*.exit =3D "t/test-results/*.exit"
> 
> Isn't the above going to cause 'test' to error out?
>
>     $ mkdir -p t/test-results
>     $ >t/test-results/a.exit
>     $ >t/test-results/b.exit
>     $ test t/test-results/*.exit =3D 't/test-results/*.exit'
>     -bash: test: too many arguments

Indeed it does, though Travis CI's /bin/sh gives a different error
message.  Thanks for pointin it out, I didn't notice the error msg,
because the script as a whole still did the right thing and then I
didn't look close enough.

> I'd think you'd want to capture the result of the expansion of
> t/test-result/*.exit as a string and compare that instead.

I'm not sure how the result of the expansion could be captured in the
shell, because the shell performs the expansion only just before it
executes a command.  And if we do have to execute a command anyway,
then we can simply rely on the command exiting with an error code upon
not finding any files, and there's no need to capture the expansion or
for the comparison for that matter.

So I propose this updated patch, using 'ls' instead of 'test':

  -- >8 --

Subject: [PATCH v2.1 8/8] travis-ci: only print test failures if there are test results available

When a build job running the test suite fails, our
'ci/print-test-failures.sh' script scans all 't/test-results/*.exit'
files to find failed tests and prints their verbose output.  However,
if a build job were to fail before it ever gets to run the test suite,
then there will be no files to match the above pattern and the shell
will take the pattern literally, resulting in errors like this in the
trace log:

  cat: t/test-results/*.exit: No such file or directory
  ------------------------------------------------------------------------
  t/test-results/*.out...
  ------------------------------------------------------------------------
  cat: t/test-results/*.out: No such file or directory

Check upfront and proceed only if there are any such files present.

Signed-off-by: SZEDER Gábor <[email-masked]>
---
 ci/print-test-failures.sh | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/ci/print-test-failures.sh b/ci/print-test-failures.sh
index f757e616c..b4a62ef98 100755
--- a/ci/print-test-failures.sh
+++ b/ci/print-test-failures.sh
@@ -8,6 +8,12 @@
 # Tracing executed commands would produce too much noise in this script.
 set +x
 
+if ! ls t/test-results/*.exit >/dev/null 2>/dev/null
+then
+	echo "Build job failed before the tests could have been run"
+	exit
+fi
+
 for TEST_EXIT in t/test-results/*.exit
 do
 	if [ "$(cat "$TEST_EXIT")" != "0" ]
-- 
2.15.1.429.ga000dd9c7