Skip to content

Commit

Permalink
add template for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tgaspe committed Aug 29, 2024
1 parent 2e5e797 commit 1946874
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/bcftools/bcftools_concat/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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} \
Expand All @@ -43,4 +46,4 @@ bcftools concat \
${par_threads:+--threads "$par_threads"} \
${par_verbose:+-v "$par_verbose"} \
-o $par_output \
$par_input
${input[@]} \
70 changes: 70 additions & 0 deletions src/bcftools/bcftools_concat/test.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF > "$TMPDIR/example.vcf"
##fileformat=VCFv4.1
##contig=<ID=1,length=249250621,assembly=b37>
#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


0 comments on commit 1946874

Please sign in to comment.