Support #17234

Unit test scripts can't use bash in Ubuntu

Added by Gianluca Petrillo over 3 years ago. Updated about 3 years ago.

Target version:
Start date:
Due date:
% Done:


Estimated time:


The unit test MathFunctor_workaround from larcorealg/test/CoreUtils/ fails on Ubuntu 16 with the message: 9: declare: not found 11: Syntax error: "(" unexpected (expecting "done")
<end of output>

The execution environment was obtained by following the instruction in Ubuntu VM, and pulling

./pullProducts $(pwd) u16 larsoftobj-v1_23_01 e14 prof

The same test succeeds on Linux and OSX environment.


#1 Updated by Gianluca Petrillo over 3 years ago

My explanation follows.

Ubuntu has opted to have Debian Almquist Shell (dash) as default system shell (/bin/sh). That is an almost-POSIX-compliant shell, which does not support most of the shine of Bash.
A way to distinguish the two shells is via the set builtin command, which both support. In dash, no BASH_XXX variables are present, and the values of the variables in the printout are always enclosed in single quotes (bash does that only if required by special characters in the content).
A simple script (

#!/usr/bin/env bash

shows the output when running:

  • bash bash style
  • dash dash style
  • sh dash style
  • ./ bash style (honors the shebang)

(this regardless the shell the test is started from is bash or dash).

Back to the larcorealg test (larcorealg:source:larcorealg/test/CoreUtils/ it also uses a #!/usr/bin/env bash shebang (replacing it with /bin/bash does not help).
My guess is that ctest somehow forces the use of /bin/sh or so.
I wonder if there is a solution to this riddle, or if we are required to write all shell scripts for a POSIX shell.

#2 Updated by Kyle Knoepfel about 3 years ago

  • Status changed from New to Feedback

We believe the behavior you have encountered can be resolved by the following changes in your CMakeLists.txt file:

cet_test(MathFunctor_workaround HANDBUILT
-  TEST_ARGS ${IncludeDirectories}
cet_test(MathFunctor_workaround HANDBUILT
+  TEST_EXEC ./ 
+  TEST_ARGS ${IncludeDirectories}

#3 Updated by Gianluca Petrillo about 3 years ago

(comment removed by the author because probably wrong)

#4 Updated by Gianluca Petrillo about 3 years ago

I confirm that works.
I am not even sure why I did not do that in the first place.

#5 Updated by Kyle Knoepfel about 3 years ago

  • Tracker changed from Bug to Support
  • Project changed from art to cetbuildtools
  • Category deleted (Build System)
  • Status changed from Feedback to Closed
  • % Done changed from 0 to 100

Also available in: Atom PDF