From: Bastian Dehn Date: Sat, 5 Jul 2025 10:17:26 +0000 (+0200) Subject: add tests for create multi pdfs X-Git-Tag: v1.0.7^2~12 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=a5f2e76c21cd2509114f96479e2fecf7f12d7a96;p=scantopdf.git add tests for create multi pdfs --- diff --git a/scanbasic.bats b/scanbasic.bats index fc5861d..bf75ac7 100755 --- a/scanbasic.bats +++ b/scanbasic.bats @@ -243,3 +243,34 @@ teardown() { assert_success assert_line --index 0 "true" } + +@test "should failure createmultipdfs missing basename paramter" { + run createmultipdfs + + assert_failure + assert_line --index 0 "❌ ERROR: missing basename" +} + +@test "should failure createmultipdfs tiff2pdf fails" { + tiff2pdf_exit=1 + + run createmultipdfs "base" + + assert_failure + assert_line --index 0 "❌ ERROR: could not convert scanned*.tiff to scanned*.pdf" +} + +@test "should failure createmultipdfs rm tiff fails" { + rm_exit=1 + + run createmultipdfs "base" + + assert_failure + assert_line --index 0 "❌ ERROR: could not delete scanned*.tiff" +} + +@test "should success createmutlipdfs" { + run createmultipdfs "base" + + assert_success +} diff --git a/scanbasic.sh b/scanbasic.sh index e20e2e5..4d0b7d8 100644 --- a/scanbasic.sh +++ b/scanbasic.sh @@ -154,28 +154,39 @@ detectsplit() createmultipdfs() { - local trenn=$1 - local basename=$2 + local basename=$1 local startcount=1 local endcount=1 - local pdf= command -v tiff2pdf > /dev/null \ || errlog "command tiff2pdf not found" \ || return $? - for i in scanned*.tiff; do - pdf=${i/.tiff/.pdf} - tiff2pdf $i -o $pdf \ - || errlog "could not convert $i to $pdf" \ - || return 1 - trenn=$(detectsplit $pdf) - rm $i + [ -n "$basename" ] \ + || errlog "missing basename" \ + || return $? + + local pdf= + local tiff= + for tiff in scanned*.tiff; do + pdf=${tiff/.tiff/.pdf} + tiff2pdf $tiff -o $pdf \ + || errlog "could not convert $tiff to $pdf" \ + || return $? + trenn=$(detectsplit $pdf) \ + || return $? + rm $tiff \ + || errlog "could not delete $tiff" \ + || return $? + if [ "$trenn" == "true" ]; then - rm $pdf + rm $pdf \ + || errlog "could not delete $pdf" \ + || return $? createpdf $startcount $((endcount - 1)) $basename \ - || return 1 + || return $? startcount=$((endcount + 1)) fi + ((endcount++)) done }