From 0d95577efc305a56074c9157ecbd0a48a41c9ac0 Mon Sep 17 00:00:00 2001
From: Alex Kanitz <alexander.kanitz@unibas.ch>
Date: Tue, 18 Feb 2020 15:09:19 +0100
Subject: [PATCH] run tests in verbose mode

- trap call functionalized through cleanup() function
- function added to all test scripts
- function prints out exit status of last command before trap
- flag `--verbose` added to Snakemake calls in all test scripts
- script tests rename to follow naming convention 'test_script_<script_name>_<script_run_mode>
---
 .gitlab-ci.yml                                    |  4 ++--
 tests/test_create_dag_image/test.sh               |  9 ++++++++-
 tests/test_create_rule_graph/test.sh              |  9 ++++++++-
 tests/test_integration_workflow/test.local.sh     | 15 +++++++++++++--
 tests/test_integration_workflow/test.slurm.sh     | 15 +++++++++++++--
 .../expected_output.md5                           |  0
 .../test.sh                                       | 13 ++++++++++++-
 .../expected_output.md5                           |  0
 .../input_table.tsv                               |  0
 .../test.sh                                       | 11 ++++++++++-
 10 files changed, 66 insertions(+), 10 deletions(-)
 rename tests/{test_scripts_labkey_to_snakemake => test_scripts_labkey_to_snakemake_api}/expected_output.md5 (100%)
 rename tests/{test_scripts_labkey_to_snakemake => test_scripts_labkey_to_snakemake_api}/test.sh (84%)
 rename tests/{test_scripts_table_to_snakemake => test_scripts_labkey_to_snakemake_table}/expected_output.md5 (100%)
 rename tests/{test_scripts_table_to_snakemake => test_scripts_labkey_to_snakemake_table}/input_table.tsv (100%)
 rename tests/{test_scripts_table_to_snakemake => test_scripts_labkey_to_snakemake_table}/test.sh (84%)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index cf46e51..a1ce0b8 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -10,8 +10,8 @@ test:
     # add code quality tests here
     # add unit tests here
     # add script tests here
-    - bash tests/test_scripts_table_to_snakemake/test.sh
-    - bash tests/test_scripts_labkey_to_snakemake/test.sh
+    - bash tests/test_scripts_labkey_to_snakemake_table/test.sh
+    - bash tests/test_scripts_labkey_to_snakemake_api/test.sh
     # add integration tests here
     - bash tests/test_create_dag_image/test.sh
     - bash tests/test_create_rule_graph/test.sh
diff --git a/tests/test_create_dag_image/test.sh b/tests/test_create_dag_image/test.sh
index 67bf41c..0732292 100755
--- a/tests/test_create_dag_image/test.sh
+++ b/tests/test_create_dag_image/test.sh
@@ -1,7 +1,13 @@
 #!/bin/bash
 
 # Tear down test environment
-trap 'rm -rf .snakemake && cd $user_dir' EXIT  # quotes command is exected after script exits, regardless of exit status
+cleanup () {
+    rc=$?
+    rm -rf .snakemake
+    cd $user_dir
+    echo "Exit status: $rc"
+}
+trap cleanup EXIT
 
 # Set up test environment
 set -eo pipefail  # ensures that script exits at first command that exits with non-zero status
@@ -18,5 +24,6 @@ snakemake \
     --dag \
     --printshellcmds \
     --dryrun \
+    --verbose \
     | dot -Tsvg > "../../images/dag_test_workflow.svg"
 
diff --git a/tests/test_create_rule_graph/test.sh b/tests/test_create_rule_graph/test.sh
index 00637f5..b232a2e 100755
--- a/tests/test_create_rule_graph/test.sh
+++ b/tests/test_create_rule_graph/test.sh
@@ -1,7 +1,13 @@
 #!/bin/bash
 
 # Tear down test environment
-trap 'rm -rf .snakemake && cd $user_dir' EXIT  # quotes command is exected after script exits, regardless of exit status
+cleanup () {
+    rc=$?
+    rm -rf .snakemake
+    cd $user_dir
+    echo "Exit status: $rc"
+}
+trap cleanup EXIT
 
 # Set up test environment
 set -eo pipefail  # ensures that script exits at first command that exits with non-zero status
@@ -18,5 +24,6 @@ snakemake \
     --rulegraph \
     --printshellcmds \
     --dryrun \
+    --verbose \
     | dot -Tsvg > "../../images/rule_graph.svg"
 
diff --git a/tests/test_integration_workflow/test.local.sh b/tests/test_integration_workflow/test.local.sh
index 32923b4..42e02fa 100755
--- a/tests/test_integration_workflow/test.local.sh
+++ b/tests/test_integration_workflow/test.local.sh
@@ -1,7 +1,17 @@
 #!/bin/bash
 
 # Tear down test environment
-trap 'rm -rf logs/ results/ .snakemake/ .java/ local_log/ && cd $user_dir' EXIT  # quoted command is exected after script exits, regardless of exit status
+cleanup () {
+    rc=$?
+    rm -rf .java/
+    rm -rf .snakemake/
+    rm -rf local_log/
+    rm -rf logs/
+    rm -rf results/
+    cd $user_dir
+    echo "Exit status: $rc"
+}
+trap cleanup EXIT
 
 # Set up test environment
 set -eo pipefail  # ensures that script exits at first command that exits with non-zero status
@@ -20,7 +30,8 @@ snakemake \
     --printshellcmds \
     --rerun-incomplete \
     --use-singularity \
-    --singularity-args="--bind ${PWD}/../input_files"
+    --singularity-args="--bind ${PWD}/../input_files" \
+    --verbose
 
 # Check md5 sum of some output files
 find results/ -type f -name \*\.gz -exec gunzip '{}' \;
diff --git a/tests/test_integration_workflow/test.slurm.sh b/tests/test_integration_workflow/test.slurm.sh
index 7f773ee..67df1e9 100755
--- a/tests/test_integration_workflow/test.slurm.sh
+++ b/tests/test_integration_workflow/test.slurm.sh
@@ -1,7 +1,17 @@
 #!/bin/bash
 
 # Tear down test environment
-trap 'rm -rf logs/ results/ .snakemake/ .java/ local_log/ && cd $user_dir' EXIT  # quoted command is exected after script exits, regardless of exit status
+cleanup () {
+    rc=$?
+    rm -rf .java/
+    rm -rf .snakemake/
+    rm -rf local_log/
+    rm -rf logs/
+    rm -rf results/
+    cd $user_dir
+    echo "Exit status: $rc"
+}
+trap cleanup EXIT
 
 # Set up test environment
 set -eo pipefail  # ensures that script exits at first command that exits with non-zero status
@@ -23,7 +33,8 @@ snakemake \
     --printshellcmds \
     --rerun-incomplete \
     --use-singularity \
-    --singularity-args="--bind ${PWD}/../input_files"
+    --singularity-args="--bind ${PWD}/../input_files" \
+    --verbose
 
 # Check md5 sum of some output files
 find results/ -type f -name \*\.gz -exec gunzip '{}' \;
diff --git a/tests/test_scripts_labkey_to_snakemake/expected_output.md5 b/tests/test_scripts_labkey_to_snakemake_api/expected_output.md5
similarity index 100%
rename from tests/test_scripts_labkey_to_snakemake/expected_output.md5
rename to tests/test_scripts_labkey_to_snakemake_api/expected_output.md5
diff --git a/tests/test_scripts_labkey_to_snakemake/test.sh b/tests/test_scripts_labkey_to_snakemake_api/test.sh
similarity index 84%
rename from tests/test_scripts_labkey_to_snakemake/test.sh
rename to tests/test_scripts_labkey_to_snakemake_api/test.sh
index c9d1a27..5658fd6 100755
--- a/tests/test_scripts_labkey_to_snakemake/test.sh
+++ b/tests/test_scripts_labkey_to_snakemake_api/test.sh
@@ -4,7 +4,17 @@
 # 'LABKEY_PASS' to be set with the appropriate values
 
 # Tear down test environment
-trap 'rm -rf ${HOME}/.netrc .snakemake config.yaml samples.tsv input_table.tsv && cd $user_dir' EXIT  # quotes command is exected after script exits, regardless of exit status
+cleanup () {
+    rc=$?
+    rm -rf ${HOME}/.netrc
+    rm -rf .snakemake/
+    rm -rf config.yaml
+    rm -rf input_table.tsv
+    rm -rf samples.tsv
+    cd $user_dir
+    echo "Exit status: $rc"
+}
+trap cleanup EXIT
 
 # Set up test environment
 set -eo pipefail  # ensures that script exits at first command that exits with non-zero status
@@ -36,6 +46,7 @@ snakemake \
     --snakefile="../../Snakefile" \
     --configfile="config.yaml" \
     --dryrun \
+    --verbose
 
 md5sum --check "expected_output.md5"
 # MD5 sums obtained with command:
diff --git a/tests/test_scripts_table_to_snakemake/expected_output.md5 b/tests/test_scripts_labkey_to_snakemake_table/expected_output.md5
similarity index 100%
rename from tests/test_scripts_table_to_snakemake/expected_output.md5
rename to tests/test_scripts_labkey_to_snakemake_table/expected_output.md5
diff --git a/tests/test_scripts_table_to_snakemake/input_table.tsv b/tests/test_scripts_labkey_to_snakemake_table/input_table.tsv
similarity index 100%
rename from tests/test_scripts_table_to_snakemake/input_table.tsv
rename to tests/test_scripts_labkey_to_snakemake_table/input_table.tsv
diff --git a/tests/test_scripts_table_to_snakemake/test.sh b/tests/test_scripts_labkey_to_snakemake_table/test.sh
similarity index 84%
rename from tests/test_scripts_table_to_snakemake/test.sh
rename to tests/test_scripts_labkey_to_snakemake_table/test.sh
index 63632e0..37014ed 100755
--- a/tests/test_scripts_table_to_snakemake/test.sh
+++ b/tests/test_scripts_labkey_to_snakemake_table/test.sh
@@ -1,7 +1,15 @@
 #!/bin/bash
 
 # Tear down test environment
-trap 'rm -rf .snakemake config.yaml samples.tsv && cd $user_dir' EXIT  # quotes command is exected after script exits, regardless of exit status
+cleanup () {
+    rc=$?
+    rm -rf .snakemake/
+    rm -rf config.yaml
+    rm -rf samples.tsv
+    cd $user_dir
+    echo "Exit status: $rc"
+}
+trap cleanup EXIT
 
 # Set up test environment
 set -eo pipefail  # ensures that script exits at first command that exits with non-zero status
@@ -25,6 +33,7 @@ snakemake \
     --snakefile="../../Snakefile" \
     --configfile="config.yaml" \
     --dryrun \
+    --verbose
 
 md5sum --check "expected_output.md5"
 # MD5 sums obtained with command:
-- 
GitLab