Project

General

Profile

Support #17234

Unit test scripts can't use bash in Ubuntu

Added by Gianluca Petrillo about 2 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
07/19/2017
Due date:
% Done:

100%

Estimated time:
Duration:

Description

The unit test MathFunctor_workaround from larcorealg/test/CoreUtils/quiet_Math_Functor_test.sh fails on Ubuntu 16 with the message:

quiet_Math_Functor_test.sh: 9: quiet_Math_Functor_test.sh: declare: not found
quiet_Math_Functor_test.sh: 11: quiet_Math_Functor_test.sh: 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.

History

#1 Updated by Gianluca Petrillo about 2 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 (dumpenv.sh):

#!/usr/bin/env bash

set
shows the output when running:

  • bash dumpenv.sh: bash style
  • dash dumpenv.sh: dash style
  • sh dumpenv.sh: dash style
  • ./dumpenv.sh: 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/quiet_Math_Functor_test.sh): 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 2 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_EXEC sh
-  TEST_ARGS quiet_Math_Functor_test.sh ${IncludeDirectories}
   DATAFILES quiet_Math_Functor_test.sh)
cet_test(MathFunctor_workaround HANDBUILT
+  TEST_EXEC ./quiet_Math_Functor_test.sh 
+  TEST_ARGS ${IncludeDirectories}
   DATAFILES quiet_Math_Functor_test.sh)

#3 Updated by Gianluca Petrillo about 2 years ago

(comment removed by the author because probably wrong)

#4 Updated by Gianluca Petrillo about 2 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 2 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