all: test package
-test: $(BUILDDIR)/parts/scanbasic.sh
+test: $(BUILDDIR)/parts/scanbasic.sh \
+ $(SRCDIR)/errlog.sh \
+ $(SRCDIR)/addocr.sh
+
+ ./tests/addocr.bats
./tests/scanbasic.bats
build: $(PACKAGEDIR)/$(BINDIR)/scantopdf \
--- /dev/null
+#!/usr/bin/bats
+
+setup() {
+ load "/usr/lib/bats/bats-assert/load"
+ load "/usr/lib/bats/bats-support/load"
+
+ source ./src/errlog.sh
+ source ./src/addocr.sh
+}
+
+@test "should failure optimize input parameter is missing" {
+ run optimize
+
+ assert_failure
+ assert_line --index 0 "❌ ERROR: missing input"
+}
+
+@test "should failure optimize when qpdf failes" {
+ qpdf() {
+ return 1
+ }
+
+ run optimize "testfile"
+
+ assert_failure
+ assert_line --index 0 "❌ ERROR: could not linearize testfile"
+}
+
+@test "should failure optimize when mv fails" {
+ qpdf() {
+ :
+ }
+ mv() {
+ return 1
+ }
+
+ run optimize "testfile"
+
+ assert_failure
+ assert_line --index 0 \
+ "❌ ERROR: could not rename testfile-out to testfile"
+}
+
+@test "should success optimize" {
+ qpdf() {
+ :
+ }
+ mv() {
+ :
+ }
+
+ run optimize "testfile"
+
+ 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() {
+ return 1
+ }
+
+ run addocr "testfile"
+
+ assert_failure
+ assert_line --index 0 "ℹ️ INFO: adding ocr on file testfile"
+ assert_line --index 1 "❌ ERROR: could not add ocr on testfile"
+}
+
+@test "should success addocr" {
+ ocrmypdf() {
+ :
+ }
+
+ run addocr "testfile"
+
+ assert_success
+ assert_line --index 0 "ℹ️ INFO: adding ocr on file testfile"
+}
source ./build/parts/scanbasic.sh
}
-@test "should failure optimize input parameter is missing" {
- run optimize
-
- assert_failure
- assert_line --index 0 "❌ ERROR: missing input"
-}
-
-@test "should failure optimize when qpdf failes" {
- qpdf() {
- return 1
- }
-
- run optimize "testfile"
-
- assert_failure
- assert_line --index 0 "❌ ERROR: could not linearize testfile"
-}
-
-@test "should failure optimize when mv fails" {
- qpdf() {
- :
- }
- mv() {
- return 1
- }
-
- run optimize "testfile"
-
- assert_failure
- assert_line --index 0 \
- "❌ ERROR: could not rename testfile-out to testfile"
-}
-
-@test "should success optimize" {
- qpdf() {
- :
- }
- mv() {
- :
- }
-
- run optimize "testfile"
-
- 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() {
- return 1
- }
-
- run addocr "testfile"
-
- assert_failure
- assert_line --index 0 "ℹ️ INFO: adding ocr on file testfile"
- assert_line --index 1 "❌ ERROR: could not add ocr on testfile"
-}
-
-@test "should success addocr" {
- ocrmypdf() {
- :
- }
-
- run addocr "testfile"
-
- assert_success
- assert_line --index 0 "ℹ️ INFO: adding ocr on file testfile"
-}
-
@test "should failure createonepdf missing output parameter" {
run createonepdf