[meta]
    title = "job script torture test"

    description = """Any task job script may fail regardless of user runtime
settings if changes to cylc re-order the job script sections badly: e.g.
"cylc task started" must be called after the CYLC_ environment variables
are exported. Additionally, users may rely on the order of variable
definition in each environment and script section: e.g. workflow
bin directory must go in PATH before the task runtime environment is
defined because workflow bin commands could be used in variable assignment
expressions."""

[scheduling]
    [[graph]]
        R1 = "foo"
[runtime]
    [[foo]]
        platform = localhost
        init-script = """
echo "HELLO FROM INIT-SCRIPT"
# define a variable
export VAR_IS=is"""
        pre-script = """
echo "HELLO FROM PRE-SCRIPT"
# init-script must be done:
echo VAR_IS is $VAR_IS
# user environment must be done:
echo E_ONE is $E_ONE
echo E_TWO is $E_TWO
echo E_THR is $E_THR
echo E_FOU is $E_FOU
echo E_FIV is $E_FIV
# define a variable
export VAR_PreCS=precs"""
        script = """
echo "HELLO FROM SCRIPT"
# init-script must be done:
echo VAR_IS is $VAR_IS
# pre-script must be done:
echo VAR_PreCS is $VAR_PreCS
# environment must be done:
echo E_ONE is $E_ONE
echo E_TWO is $E_TWO
echo E_THR is $E_THR
echo E_FOU is $E_FOU
echo E_FIV is $E_FIV
# define a variable
export VAR_CS=var_cs"""
        post-script = """
echo "HELLO FROM POST-SCRIPT"
# init-script must be done:
echo VAR_IS is $VAR_IS
# pre-script must be done:
echo VAR_PreCS is $VAR_PreCS
# script must be done:
echo VAR_CS is $VAR_CS
# environment must be done:
echo E_ONE is $E_ONE
echo E_TWO is $E_TWO
echo E_THR is $E_THR
echo E_FOU is $E_FOU
echo E_FIV is $E_FIV
echo VAR_IS is $VAR_IS
echo VAR_PreCS is $VAR_PreCS
echo VAR_CS is $VAR_CS
# define a variable
export VAR_PostCS=postcs"""
        [[[environment]]]
            # path to cylc must be available:
            E_ONE = $(( RANDOM % 10 ))
            # init-script must be done:
            E_TWO = $VAR_IS
            # cylc-defined variables must be done:
            E_THR = $CYLC_WORKFLOW_SHARE_DIR
            E_FOU = $CYLC_TASK_NAME
            # the workflow bin must be in $PATH already:
            E_FIV = $( foo.sh )
