From: Bastian Dehn Date: Sat, 5 Jul 2025 08:53:38 +0000 (+0200) Subject: add test addocr X-Git-Tag: v1.0.7^2~16 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=a3454052e5caf002ecb5504ac20e892d4240d7a2;p=scantopdf.git add test addocr --- diff --git a/scanbasic.bats b/scanbasic.bats index 075b3cf..aec0d11 100755 --- a/scanbasic.bats +++ b/scanbasic.bats @@ -1,5 +1,10 @@ #!/usr/bin/bats +ocrmypdf() { + echo "$ocrmypdf_return" + return "$ocrmypdf_exit" +} + qpdf() { echo "$qpdf_return" return "$qpdf_exit" @@ -15,10 +20,24 @@ setup() { load "/usr/lib/bats/bats-support/load" source ./scanbasic.sh + + export -f qpdf qpdf_return= qpdf_exit=0 + + export -f mv mv_return= mv_exit=0 + + export -f ocrmypdf + ocrmypdf_return= + ocrmypdf_exit=0 +} + +teardown() { + export -n qpdf + export -n mv + export -n ocrmypdf } @test "should failure optimize input parameter is missing" { @@ -52,3 +71,25 @@ setup() { assert_success } + +@test "should failure addocr missing input parameter" { + run addocr + + assert_failure + assert_line --index 0 "❌ ERROR: missing input" +} + +@test "should failure addocr ocrmypdf fails" { + ocrmypdf_exit=1 + + run addocr "testfile" + + assert_failure + assert_line --index 0 "❌ ERROR: could not add ocr on testfile" +} + +@test "should success addocr" { + run addocr "testfile" + + assert_success +} diff --git a/scanbasic.sh b/scanbasic.sh index 309ccb5..637a9c9 100644 --- a/scanbasic.sh +++ b/scanbasic.sh @@ -29,28 +29,26 @@ optimize() addocr() { - local input=$1 - local output=$input-out - local error="" + local input="$1" + local output="$input-out" command -v ocrmypdf > /dev/null \ || errlog "command ocrmypdf not found" \ || return $? - echo $input - error=$(ocrmypdf -l deu $input $output 2>&1) \ + [ -n "$input" ] \ + || errlog "missing input" \ + || return $? + + ocrmypdf -l deu $input $output 2>&1 \ || errlog "could not add ocr on $input" \ || return $? - if [ -n "$(echo $error | grep offset)" ]; then - printf "%s: %s\n" $input $error >> $HOME/addocr-error.log - fi + [ ! -f $output ] && return 0 - if [ -f $output ]; then - mv $output $input \ - || errlog "could not rename $output to $input" \ - || return $? - optimize $input || return $? - fi + mv $output $input \ + || errlog "could not rename $output to $input" \ + || return $? + optimize $input || return $? } createonepdf()