diff options
author | Erik Arvstedt <erik.arvstedt@gmail.com> | 2022-05-02 12:38:51 +0200 |
---|---|---|
committer | Erik Arvstedt <erik.arvstedt@gmail.com> | 2022-05-02 13:44:03 +0200 |
commit | 7d2cee008b636b2bb754bfbe43f09d8fbc460296 (patch) | |
tree | fc5d127a8dcda7de3894c30deb26c1c2cd0f2da0 /pkgs/applications/graphics | |
parent | 05325328358a960a7308ba37fd1094758059f297 (diff) |
tesseract: add wrapper test
Diffstat (limited to 'pkgs/applications/graphics')
-rw-r--r-- | pkgs/applications/graphics/tesseract/wrapper.nix | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/pkgs/applications/graphics/tesseract/wrapper.nix b/pkgs/applications/graphics/tesseract/wrapper.nix index 1dfc4393c46bd..59686e3251f26 100644 --- a/pkgs/applications/graphics/tesseract/wrapper.nix +++ b/pkgs/applications/graphics/tesseract/wrapper.nix @@ -1,4 +1,5 @@ { lib, makeWrapper, tesseractBase, languages +, runCommand, imagemagick # A list of languages like [ "eng" "spa" … ] or `null` for all available languages , enableLanguages ? null @@ -12,8 +13,6 @@ }: let - passthru = { inherit tesseractBase languages tessdata; }; - tesseractWithData = tesseractBase.overrideAttrs (_: { inherit tesseractBase tessdata; @@ -47,9 +46,36 @@ let exit 1 fi ''; + }); - tesseract = (if enableLanguages == [] then tesseractBase else tesseractWithData) // passthru; + passthru = { inherit tesseractBase languages tessdata; }; + + # Only run test when all languages are available + test = lib.optionalAttrs (enableLanguages == null) { + tests.default = runCommand "tesseract-test-ocr" { + buildInputs = [ + tesseractWithData + imagemagick + ]; + } '' + text="hello nix" + + convert -size 400x40 xc:white -font 'DejaVu-Sans' -pointsize 20 \ + -fill black -annotate +5+20 "$text" /tmp/test-img.png 2>/dev/null + ocrResult=$(tesseract /tmp/test-img.png - | tr -d "\f") + + if [[ $ocrResult != $text ]]; then + echo "OCR test failed" + echo "expected: '$text'" + echo "actual: '$ocrResult'" + exit 1 + fi + touch $out + ''; + }; + + tesseract = (if enableLanguages == [] then tesseractBase else tesseractWithData) // passthru // test; in if enableLanguagesHash == null then tesseract |