From: Bastian Dehn Date: Sat, 5 Jul 2025 09:42:54 +0000 (+0200) Subject: add createpdf test X-Git-Tag: v1.0.7^2~14 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=7a0bceb9a773672688d9a78115a36d0c990dd745;p=scantopdf.git add createpdf test --- diff --git a/scanbasic.bats b/scanbasic.bats index 5e57ad1..44cf3ef 100755 --- a/scanbasic.bats +++ b/scanbasic.bats @@ -163,3 +163,41 @@ teardown() { assert_success } + +@test "should failure createpdf missing start parameter" { + run createpdf + + assert_failure + assert_line --index 0 "❌ ERROR: missing start" +} + +@test "should failure createpdf missing end parameter" { + run createpdf "1" + + assert_failure + assert_line --index 0 "❌ ERROR: missing end" +} + +@test "should failure createpdf pdftk fails" { + pdftk_exit=1 + + run createpdf "1" "2" + + assert_failure + assert_line --index 0 "❌ ERROR: could not create pdf" +} + +@test "should failure pdf delete fails" { + rm_exit=1 + + run createpdf "1" "2" + + assert_failure + assert_line --index 0 "❌ ERROR: could not delete scanned001.pdf" +} + +@test "should success createpdf" { + run createpdf "1" "2" + + assert_success +} diff --git a/scanbasic.sh b/scanbasic.sh index 69b541a..d781510 100644 --- a/scanbasic.sh +++ b/scanbasic.sh @@ -66,12 +66,15 @@ createonepdf() || errlog "missing output" \ || return $? - for i in scanned*.tiff; do - tiff2pdf $i -o ${i/.tiff/.pdf} \ + local output_pdf= + local tiff= + for tiff in scanned*.tiff; do + output_pdf=${tiff/.tiff/.pdf} + tiff2pdf $i -o $output_pdf \ || errlog "could not convert tiff to pdf" \ || return $? - rm $i \ - || errlog "could not delete $i" \ + rm $tiff \ + || errlog "could not delete $tiff" \ || return $? done @@ -89,34 +92,41 @@ createonepdf() createpdf() { - local start=$1 - local end=$2 - local basename=$3 + local start="$1" + local end="$2" + local basename="$3" local countno= local pdfs=() + basename=${basename:="out"} command -v pdftk > /dev/null \ || errlog "command pdftk not found" \ || return $? + [ -n "$start" ] \ + || errlog "missing start" \ + || return $? + [ -n "$end" ] \ + || errlog "missing end" \ + || return $? - if [ -z "$basename" ]; then - basename="out" - fi - + local i= for i in $(seq $start $end); do countno=$(printf "%03d" $i) pdfs=$(echo $pdfs "scanned$countno.pdf") done - pdftk $pdfs output $basename$(printf "%03d" $start).pdf \ + pdftk "$pdfs" output "$basename$(printf "%03d" $start).pdf" \ || errlog "could not create pdf" \ || return 1 - for i in $pdfs; do - rm $i || errlog "could not delete $i" || return 1 + for pdf in $pdfs; do + rm "$pdf" \ + || errlog "could not delete $pdf" \ + || return 1 done - addocr $basename$(printf "%03d" $start).pdf || return 1 + addocr "$basename$(printf "%03d" $start).pdf" \ + || return $? } detectsplit()