From 33fb44edb657a5608ee1de197ab9307f1c3a7bf2 Mon Sep 17 00:00:00 2001 From: Leila011 Date: Mon, 19 Aug 2024 16:33:10 +0200 Subject: [PATCH] create temporary directory and clean up on exit --- src/agat/agat_sp_add_start_and_stop/test.sh | 28 +++++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/agat/agat_sp_add_start_and_stop/test.sh b/src/agat/agat_sp_add_start_and_stop/test.sh index 824a3006..0c8f3676 100644 --- a/src/agat/agat_sp_add_start_and_stop/test.sh +++ b/src/agat/agat_sp_add_start_and_stop/test.sh @@ -6,52 +6,58 @@ set -eo pipefail ## VIASH END test_dir="${meta_resources_dir}/test_data" -out_dir="${meta_resources_dir}/out_data" + +# create temporary directory and clean up on exit +TMPDIR=$(mktemp -d "$meta_temp_dir/$meta_functionality_name-XXXXXX") +function clean_up { + [[ -d "$TMPDIR" ]] && rm -rf "$TMPDIR" +} +trap clean_up EXIT echo "> Run $meta_name with test data and ni flag" "$meta_executable" \ --gff "$test_dir/agat_sp_add_start_and_stop.gff" \ --fasta "$test_dir/1.fa" \ - --output "$out_dir/output.gff" \ + --output "$TMPDIR/output.gff" \ --ni echo ">> Checking output" -[ ! -f "$out_dir/output.gff" ] && echo "Output file output.gff does not exist" && exit 1 +[ ! -f "$TMPDIR/output.gff" ] && echo "Output file output.gff does not exist" && exit 1 echo ">> Check if output is empty" -[ ! -s "$out_dir/output.gff" ] && echo "Output file output.gff is empty" && exit 1 +[ ! -s "$TMPDIR/output.gff" ] && echo "Output file output.gff is empty" && exit 1 echo ">> Check if output matches expected output" -diff "$out_dir/output.gff" "$test_dir/agat_sp_add_start_and_stop_1.gff" +diff "$TMPDIR/output.gff" "$test_dir/agat_sp_add_start_and_stop_1.gff" if [ $? -ne 0 ]; then echo "Output file output.gff does not match expected output" exit 1 fi -rm -f "$out_dir/output.gff" +rm -f "$TMPDIR/output.gff" echo "> Run $meta_name with test data and ni flag" "$meta_executable" \ --gff "$test_dir/agat_sp_add_start_and_stop.gff" \ --fasta "$test_dir/1.fa" \ - --output "$out_dir/output.gff" \ + --output "$TMPDIR/output.gff" \ --ni \ --extend echo ">> Checking output" -[ ! -f "$out_dir/output.gff" ] && echo "Output file output.gff does not exist" && exit 1 +[ ! -f "$TMPDIR/output.gff" ] && echo "Output file output.gff does not exist" && exit 1 echo ">> Check if output is empty" -[ ! -s "$out_dir/output.gff" ] && echo "Output file output.gff is empty" && exit 1 +[ ! -s "$TMPDIR/output.gff" ] && echo "Output file output.gff is empty" && exit 1 echo ">> Check if output matches expected output" -diff "$out_dir/output.gff" "$test_dir/agat_sp_add_start_and_stop_2.gff" +diff "$TMPDIR/output.gff" "$test_dir/agat_sp_add_start_and_stop_2.gff" if [ $? -ne 0 ]; then echo "Output file output.gff does not match expected output" exit 1 fi -rm -f "$out_dir/output.gff" +rm -f "$TMPDIR/output.gff" echo "> Test successful" \ No newline at end of file