From: Bastian Dehn Date: Sat, 5 Jul 2025 09:59:50 +0000 (+0200) Subject: add tests for detectsplit X-Git-Tag: v1.0.7^2~13 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=0933aa32146e0f98e312e964656a1413c55b13f9;p=scantopdf.git add tests for detectsplit --- diff --git a/scanbasic.bats b/scanbasic.bats index 44cf3ef..fc5861d 100755 --- a/scanbasic.bats +++ b/scanbasic.bats @@ -30,6 +30,11 @@ pdftk() { return "$pdftk_exit" } +zbarimg() { + echo "$zbarimg_return" + return "$zbarimg_exit" +} + setup() { load "/usr/lib/bats/bats-assert/load" load "/usr/lib/bats/bats-support/load" @@ -59,6 +64,10 @@ setup() { export -f pdftk pdftk_return= pdftk_exit=0 + + export -f zbarimg + zbarimg_return= + zbarimg_exit=0 } teardown() { @@ -68,6 +77,7 @@ teardown() { export -n tiff2pdf export -n rm export -n pdftk + export -n zbarimg } @test "should failure optimize input parameter is missing" { @@ -201,3 +211,35 @@ teardown() { assert_success } + +@test "should failure detectsplit missing parameter" { + run detectsplit + + assert_failure + assert_line --index 0 "❌ ERROR: missing pdf" +} + +@test "should failure detectsplit zbarimg fails" { + zbarimg_exit=1 + + run detectsplit "testfile.pdf" + + assert_failure + assert_line --index 0 "❌ ERROR: could not read cut page" +} + +@test "should success and false detectsplit zbarimg nothing find" { + run detectsplit "testfile.pdf" + + assert_success + assert_line --index 0 "false" +} + +@test "should success and true detectsplit zbarimg find trennblatt" { + zbarimg_return="Trennblatt" + + run detectsplit "testfile.pdf" + + assert_success + assert_line --index 0 "true" +} diff --git a/scanbasic.sh b/scanbasic.sh index d781510..e20e2e5 100644 --- a/scanbasic.sh +++ b/scanbasic.sh @@ -134,13 +134,20 @@ detectsplit() local pdf=$1 local trenn= + command -v zbarimg > /dev/null \ + || errlog "command zbarimg not found" \ + || return $? + [ -n "$pdf" ] \ + || errlog "missing pdf" \ + || return $? + trenn=$(zbarimg --raw --quiet $pdf) \ || errlog "could not read cut page" \ - || return 1 - if [ "$trenn" == "Trennblatt" ]; then - echo "true" - return - fi + || return $? + + [ "$trenn" == "Trennblatt" ] \ + && echo "true" \ + && return 0 echo "false" }