#!/usr/bin/bats
+ocrmypdf() {
+ echo "$ocrmypdf_return"
+ return "$ocrmypdf_exit"
+}
+
qpdf() {
echo "$qpdf_return"
return "$qpdf_exit"
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" {
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
+}
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()