From 705e72795c3798ac4693c4393d526f21c1ba919f Mon Sep 17 00:00:00 2001 From: Leila011 Date: Mon, 19 Aug 2024 14:05:48 +0200 Subject: [PATCH] create temporary directory and clean up on exit --- src/agat/agat_sp_statistics/test.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/agat/agat_sp_statistics/test.sh b/src/agat/agat_sp_statistics/test.sh index caefcbe0..8d653c81 100644 --- a/src/agat/agat_sp_statistics/test.sh +++ b/src/agat/agat_sp_statistics/test.sh @@ -6,21 +6,27 @@ 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 --emblmygff3" "$meta_executable" \ --gff "$test_dir/1.gff" \ - --output "$out_dir/output.txt" \ + --output "$TMPDIR/output.txt" \ echo ">> Checking output" -[ ! -f "$out_dir/output.txt" ] && echo "Output file output.txt does not exist" && exit 1 +[ ! -f "$TMPDIR/output.txt" ] && echo "Output file output.txt does not exist" && exit 1 echo ">> Check if output is empty" -[ ! -s "$out_dir/output.txt" ] && echo "Output file output.txt is empty" && exit 1 +[ ! -s "$TMPDIR/output.txt" ] && echo "Output file output.txt is empty" && exit 1 echo ">> Check if output matches expected output" -diff "$out_dir/output.txt" "$test_dir/agat_sp_statistics_1.txt" +diff "$TMPDIR/output.txt" "$test_dir/agat_sp_statistics_1.txt" if [ $? -ne 0 ]; then echo "Output file output.txt does not match expected output" exit 1