#!/usr/bin/bats
-tiff2pdf() {
- printf "$tiff2pdf_return"
- return "$tiff2pdf_exit"
-}
-
-ocrmypdf() {
- printf "$ocrmypdf_return"
- return "$ocrmypdf_exit"
-}
-
-qpdf() {
- printf "$qpdf_return"
- return "$qpdf_exit"
-}
-
-mv() {
- printf "$mv_return"
- return "$mv_exit"
-}
-
-rm() {
- printf "$rm_return"
- return "$rm_exit"
-}
-
-pdftk() {
- printf "$pdftk_return"
- return "$pdftk_exit"
-}
-
-zbarimg() {
- printf "$zbarimg_return"
- return "$zbarimg_exit"
-}
-
-scanimage() {
- printf "$scanimage_return"
- return "$scanimage_exit"
-}
-
setup() {
load "/usr/lib/bats/bats-assert/load"
load "/usr/lib/bats/bats-support/load"
source ./src/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
-
- export -f tiff2pdf
- tiff2pdf_return=
- tiff2pdf_exit=0
-
- export -f rm
- rm_return=
- rm_exit=0
-
- export -f pdftk
- pdftk_return=
- pdftk_exit=0
-
- export -f zbarimg
- zbarimg_return=
- zbarimg_exit=0
-
- export -f scanimage
- scanimage_return=
- scanimage_exit=0
-}
-
-teardown() {
- export -n qpdf
- export -n mv
- export -n ocrmypdf
- export -n tiff2pdf
- export -n rm
- export -n pdftk
- export -n zbarimg
- export -n scanimage
}
@test "should failure optimize input parameter is missing" {
}
@test "should failure optimize when qpdf failes" {
- qpdf_exit=1
+ qpdf() {
+ return 1
+ }
run optimize "testfile"
}
@test "should failure optimize when mv fails" {
- mv_exit=1
+ qpdf() {
+ :
+ }
+ mv() {
+ return 1
+ }
run optimize "testfile"
}
@test "should success optimize" {
+ qpdf() {
+ :
+ }
+ mv() {
+ :
+ }
+
run optimize "testfile"
assert_success
}
@test "should failure addocr ocrmypdf fails" {
- ocrmypdf_exit=1
+ ocrmypdf() {
+ return 1
+ }
run addocr "testfile"
}
@test "should success addocr" {
+ ocrmypdf() {
+ :
+ }
+
run addocr "testfile"
assert_success
}
@test "should failure createonepdf tiff2pdf fails" {
- tiff2pdf_exit=1
+ tiff2pdf() {
+ return 1
+ }
run createonepdf "testfile"
assert_failure
- assert_line --index 0 "❌ ERROR: could not convert tiff to pdf"
+ assert_line --index 0 "❌ ERROR: could not convert tiff to pdf"
}
@test "should failure createonepdf pdftk fails" {
- pdftk_exit=1
+ tiff2pdf() {
+ :
+ }
+ rm() {
+ :
+ }
+ pdftk() {
+ return 1
+ }
run createonepdf "testfile"
}
@test "should success createonepdf" {
+ tiff2pdf() {
+ :
+ }
+ rm() {
+ :
+ }
+ pdftk() {
+ :
+ }
+ addocr() {
+ :
+ }
+
run createonepdf "testfile"
assert_success
}
@test "should failure createpdf pdftk fails" {
- pdftk_exit=1
+ pdftk() {
+ return 1
+ }
run createpdf "1" "2"
}
@test "should success createpdf" {
+ pdftk() {
+ :
+ }
+ rm() {
+ :
+ }
+ addocr() {
+ :
+ }
+
run createpdf "1" "2"
assert_success
}
@test "should failure detectsplit zbarimg fails" {
- zbarimg_exit=1
+ zbarimg() {
+ return 1
+ }
run detectsplit "testfile.pdf"
}
@test "should success and false detectsplit zbarimg nothing find" {
+ zbarimg() {
+ :
+ }
+
run detectsplit "testfile.pdf"
assert_success
}
@test "should success and true detectsplit zbarimg find trennblatt" {
- zbarimg_return="Trennblatt"
+ zbarimg() {
+ echo "Trennblatt"
+ }
run detectsplit "testfile.pdf"
}
@test "should failure createmultipdfs tiff2pdf fails" {
- tiff2pdf_exit=1
+ tiff2pdf() {
+ return 1
+ }
run createmultipdfs
}
@test "should success createmutlipdfs" {
+ tiff2pdf() {
+ :
+ }
+ rm() {
+ :
+ }
+
run createmultipdfs
assert_success
}
@test "should failure scantopdf scanimage fails" {
- scanimage_exit=1
+ scanimage() {
+ return 1
+ }
run scantopdf "Color" "1" "test.pdf"
}
@test "should success scantopdf" {
+ scanimage() {
+ :
+ }
+ createonepdf() {
+ :
+ }
+
run scantopdf "Color" "1" "test.pdf"
assert_success