assert_success
}
+
+@test "should failure createpdf missing start parameter" {
+ run createpdf
+
+ assert_failure
+ assert_line --index 0 "❌ ERROR: missing start"
+}
+
+@test "should failure createpdf missing end parameter" {
+ run createpdf "1"
+
+ assert_failure
+ assert_line --index 0 "❌ ERROR: missing end"
+}
+
+@test "should failure createpdf pdftk fails" {
+ pdftk_exit=1
+
+ run createpdf "1" "2"
+
+ assert_failure
+ assert_line --index 0 "❌ ERROR: could not create pdf"
+}
+
+@test "should failure pdf delete fails" {
+ rm_exit=1
+
+ run createpdf "1" "2"
+
+ assert_failure
+ assert_line --index 0 "❌ ERROR: could not delete scanned001.pdf"
+}
+
+@test "should success createpdf" {
+ run createpdf "1" "2"
+
+ assert_success
+}
|| errlog "missing output" \
|| return $?
- for i in scanned*.tiff; do
- tiff2pdf $i -o ${i/.tiff/.pdf} \
+ local output_pdf=
+ local tiff=
+ for tiff in scanned*.tiff; do
+ output_pdf=${tiff/.tiff/.pdf}
+ tiff2pdf $i -o $output_pdf \
|| errlog "could not convert tiff to pdf" \
|| return $?
- rm $i \
- || errlog "could not delete $i" \
+ rm $tiff \
+ || errlog "could not delete $tiff" \
|| return $?
done
createpdf()
{
- local start=$1
- local end=$2
- local basename=$3
+ local start="$1"
+ local end="$2"
+ local basename="$3"
local countno=
local pdfs=()
+ basename=${basename:="out"}
command -v pdftk > /dev/null \
|| errlog "command pdftk not found" \
|| return $?
+ [ -n "$start" ] \
+ || errlog "missing start" \
+ || return $?
+ [ -n "$end" ] \
+ || errlog "missing end" \
+ || return $?
- if [ -z "$basename" ]; then
- basename="out"
- fi
-
+ local i=
for i in $(seq $start $end); do
countno=$(printf "%03d" $i)
pdfs=$(echo $pdfs "scanned$countno.pdf")
done
- pdftk $pdfs output $basename$(printf "%03d" $start).pdf \
+ pdftk "$pdfs" output "$basename$(printf "%03d" $start).pdf" \
|| errlog "could not create pdf" \
|| return 1
- for i in $pdfs; do
- rm $i || errlog "could not delete $i" || return 1
+ for pdf in $pdfs; do
+ rm "$pdf" \
+ || errlog "could not delete $pdf" \
+ || return 1
done
- addocr $basename$(printf "%03d" $start).pdf || return 1
+ addocr "$basename$(printf "%03d" $start).pdf" \
+ || return $?
}
detectsplit()