From 0933aa32146e0f98e312e964656a1413c55b13f9 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sat, 5 Jul 2025 11:59:50 +0200 Subject: [PATCH] add tests for detectsplit --- scanbasic.bats | 42 ++++++++++++++++++++++++++++++++++++++++++ scanbasic.sh | 17 ++++++++++++----- 2 files changed, 54 insertions(+), 5 deletions(-) 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" } -- 2.47.3