From: Bastian Dehn Date: Sat, 4 Apr 2026 06:42:35 +0000 (+0200) Subject: add ocr tests in extra file X-Git-Tag: v1.1.4^2~5 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=3b226f81678d91be8344561441f8fced69c4bbc7;p=scantopdf.git add ocr tests in extra file --- diff --git a/Makefile b/Makefile index 4962ca8..9221bc6 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,11 @@ SHAREDIR = usr/local/share 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 \ diff --git a/tests/addocr.bats b/tests/addocr.bats new file mode 100755 index 0000000..d23f3bd --- /dev/null +++ b/tests/addocr.bats @@ -0,0 +1,85 @@ +#!/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" +} diff --git a/tests/scanbasic.bats b/tests/scanbasic.bats index 481c9d9..3114cd2 100755 --- a/tests/scanbasic.bats +++ b/tests/scanbasic.bats @@ -7,82 +7,6 @@ setup() { 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