From: Bastian Dehn Date: Sun, 6 Jul 2025 07:56:18 +0000 (+0200) Subject: change mocking into tests X-Git-Tag: v1.1.0~1^2~7 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=ddbeb8493330dc9c23952c01d65f41876a3f0e46;p=scantopdf.git change mocking into tests --- diff --git a/tests/scanbasic.bats b/tests/scanbasic.bats index c1c8a4b..54bc515 100755 --- a/tests/scanbasic.bats +++ b/tests/scanbasic.bats @@ -1,93 +1,10 @@ #!/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" { @@ -98,7 +15,9 @@ teardown() { } @test "should failure optimize when qpdf failes" { - qpdf_exit=1 + qpdf() { + return 1 + } run optimize "testfile" @@ -107,7 +26,12 @@ teardown() { } @test "should failure optimize when mv fails" { - mv_exit=1 + qpdf() { + : + } + mv() { + return 1 + } run optimize "testfile" @@ -117,6 +41,13 @@ teardown() { } @test "should success optimize" { + qpdf() { + : + } + mv() { + : + } + run optimize "testfile" assert_success @@ -130,7 +61,9 @@ teardown() { } @test "should failure addocr ocrmypdf fails" { - ocrmypdf_exit=1 + ocrmypdf() { + return 1 + } run addocr "testfile" @@ -140,6 +73,10 @@ teardown() { } @test "should success addocr" { + ocrmypdf() { + : + } + run addocr "testfile" assert_success @@ -154,16 +91,26 @@ teardown() { } @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" @@ -172,6 +119,19 @@ teardown() { } @test "should success createonepdf" { + tiff2pdf() { + : + } + rm() { + : + } + pdftk() { + : + } + addocr() { + : + } + run createonepdf "testfile" assert_success @@ -192,7 +152,9 @@ teardown() { } @test "should failure createpdf pdftk fails" { - pdftk_exit=1 + pdftk() { + return 1 + } run createpdf "1" "2" @@ -201,6 +163,16 @@ teardown() { } @test "should success createpdf" { + pdftk() { + : + } + rm() { + : + } + addocr() { + : + } + run createpdf "1" "2" assert_success @@ -214,7 +186,9 @@ teardown() { } @test "should failure detectsplit zbarimg fails" { - zbarimg_exit=1 + zbarimg() { + return 1 + } run detectsplit "testfile.pdf" @@ -223,6 +197,10 @@ teardown() { } @test "should success and false detectsplit zbarimg nothing find" { + zbarimg() { + : + } + run detectsplit "testfile.pdf" assert_success @@ -230,7 +208,9 @@ teardown() { } @test "should success and true detectsplit zbarimg find trennblatt" { - zbarimg_return="Trennblatt" + zbarimg() { + echo "Trennblatt" + } run detectsplit "testfile.pdf" @@ -239,7 +219,9 @@ teardown() { } @test "should failure createmultipdfs tiff2pdf fails" { - tiff2pdf_exit=1 + tiff2pdf() { + return 1 + } run createmultipdfs @@ -248,6 +230,13 @@ teardown() { } @test "should success createmutlipdfs" { + tiff2pdf() { + : + } + rm() { + : + } + run createmultipdfs assert_success @@ -275,7 +264,9 @@ teardown() { } @test "should failure scantopdf scanimage fails" { - scanimage_exit=1 + scanimage() { + return 1 + } run scantopdf "Color" "1" "test.pdf" @@ -284,6 +275,13 @@ teardown() { } @test "should success scantopdf" { + scanimage() { + : + } + createonepdf() { + : + } + run scantopdf "Color" "1" "test.pdf" assert_success