TESTS="job_name_basic job_name_truncate "\
"job_name_replace_underscore job_name_prefix_N"

simulate_cmds="sbatch rm" # Simulate rm in order not to get job script deleted
read -r -d '' simulator_output <<'EOF'
rargs="/sbatch .*/"
output="Submitted batch job 1"

rargs="/rm .*/"
output=""
EOF

read -r -d '' general_arc_test_configuration <<EOF
[lrms]
slurm_bin_path=@PWD@/bin
EOF

function test_job_name_basic()
{
read -r -d '' job_description_input <<'EOF'
&(jobname = "job")
 (executable = "/bin/true")
EOF

read -r -d '' expected_lrms_job_script <<'EOF'
#!/bin/bash -l
# SLURM batch job script built by arex
#SBATCH --no-requeue
#SBATCH -e /my/session/directory.comment
#SBATCH -o /my/session/directory.comment

#SBATCH --nice=50
#SBATCH -J 'job'
#SBATCH --get-user-env=10L
#SBATCH -n 1
#SBATCH 

EOF
cat "${SRCDIR}/job-name-test-job_name_basic.patch" | patch -sf -p1 -d ${SRCDIR} -o ${testdir}/expected_lrms_job_script.tmpl
}

# Job name is truncated to 15 characters
function test_job_name_truncate()
{
read -r -d '' job_description_input <<'EOF'
&(jobname = "abcdefghijklmnopq")
 (executable = "/bin/true")
EOF

cat "${SRCDIR}/job-name-test-job_name_truncate.patch" | patch -sf -p1 -d ${SRCDIR} -o ${testdir}/expected_lrms_job_script.tmpl
}

# Any non-alphabetic and numeric character is replaced by an underscore '_'.
function test_job_name_replace_underscore()
{
read -r -d '' job_description_input <<'EOF'
&(jobname = "job !@#$%^&*()~")
 (executable = "/bin/true")
EOF

cat "${SRCDIR}/job-name-test-job_name_replace_underscore.patch" | patch -sf -p1 -d ${SRCDIR} -o ${testdir}/expected_lrms_job_script.tmpl
}

# If job name starts with a non-alphabetic character it is prefix with 'N'.
function test_job_name_prefix_N()
{
read -r -d '' job_description_input <<'EOF'
&(jobname = "123456789012345")
 (executable = "/bin/true")
EOF

cat "${SRCDIR}/job-name-test-job_name_prefix_N.patch" | patch -sf -p1 -d ${SRCDIR} -o ${testdir}/expected_lrms_job_script.tmpl
}
