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"
export -f pdftk
pdftk_return=
pdftk_exit=0
+
+ export -f zbarimg
+ zbarimg_return=
+ zbarimg_exit=0
}
teardown() {
export -n tiff2pdf
export -n rm
export -n pdftk
+ export -n zbarimg
}
@test "should failure optimize input parameter is missing" {
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"
+}
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"
}