From 1946874ff917d5ce9602194befa62bd9ca3d7035 Mon Sep 17 00:00:00 2001 From: tgaspe Date: Thu, 29 Aug 2024 15:19:12 +0200 Subject: [PATCH] add template for tests --- src/bcftools/bcftools_concat/script.sh | 5 +- src/bcftools/bcftools_concat/test.sh | 70 ++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/src/bcftools/bcftools_concat/script.sh b/src/bcftools/bcftools_concat/script.sh index 6cd9d4db..d77e0615 100644 --- a/src/bcftools/bcftools_concat/script.sh +++ b/src/bcftools/bcftools_concat/script.sh @@ -23,6 +23,9 @@ for par in ${unset_if_false[@]}; do [[ "$test_val" == "false" ]] && unset $par done +# Create input array +IFS=";" read -ra input <<< $par_input + # Execute bcftools concat with the provided arguments bcftools concat \ ${par_allow_overlaps:+-a} \ @@ -43,4 +46,4 @@ bcftools concat \ ${par_threads:+--threads "$par_threads"} \ ${par_verbose:+-v "$par_verbose"} \ -o $par_output \ - $par_input \ No newline at end of file + ${input[@]} \ \ No newline at end of file diff --git a/src/bcftools/bcftools_concat/test.sh b/src/bcftools/bcftools_concat/test.sh index e69de29b..e07b8250 100644 --- a/src/bcftools/bcftools_concat/test.sh +++ b/src/bcftools/bcftools_concat/test.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +## VIASH START +## VIASH END + +# Exit on error +set -eo pipefail + +#test_data="$meta_resources_dir/test_data" + +############################################# +# helper functions +assert_file_exists() { + [ -f "$1" ] || { echo "File '$1' does not exist" && exit 1; } +} +assert_file_not_empty() { + [ -s "$1" ] || { echo "File '$1' is empty but shouldn't be" && exit 1; } +} +assert_file_contains() { + grep -q "$2" "$1" || { echo "File '$1' does not contain '$2'" && exit 1; } +} +assert_identical_content() { + diff -a "$2" "$1" \ + || (echo "Files are not identical!" && exit 1) +} +############################################# + +# Create directories for tests +echo "Creating Test Data..." +TMPDIR=$(mktemp -d "$meta_temp_dir/XXXXXX") +function clean_up { + [[ -d "$TMPDIR" ]] && rm -r "$TMPDIR" +} +trap clean_up EXIT + +# Create test data +cat < "$TMPDIR/example.vcf" +##fileformat=VCFv4.1 +##contig= +#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT SAMPLE1 +1 752567 llama G C,A . . . . 1/2 +1 752722 . G A,AAA . . . . ./. +EOF + +bgzip -c $TMPDIR/example.vcf > $TMPDIR/example.vcf.gz +tabix -p vcf $TMPDIR/example.vcf.gz + +# Test 1: Remove ID annotations +mkdir "$TMPDIR/test1" && pushd "$TMPDIR/test1" > /dev/null + +echo "> Run bcftools_norm" +"$meta_executable" \ + --input "../example.vcf" \ + --output "normalized.vcf" \ + --atomize \ + --atom_overlaps "." \ + &> /dev/null + +# checks +assert_file_exists "normalized.vcf" +assert_file_not_empty "normalized.vcf" +assert_file_contains "normalized.vcf" "bcftools_normCommand=norm --atomize --atom-overlaps . -o normalized.vcf ../example.vcf" +echo "- test1 succeeded -" + +popd > /dev/null + +echo "---- All tests succeeded! ----" +exit 0 + +