. "$BST_LIB" # enca 1.19 (meta-oe recipes-support) -- charset analyser and converter. # # Two halves, deliberately kept apart because they exercise different things: # # DETECTION is pure computation inside libenca -- it reads bytes, scores them # against per-language charset tables compiled into the binary, and prints a # name. Nothing outside the process is involved, so every detection case below # must pass on any target the binary runs on at all. # # CONVERSION goes out through iconv(3), and this build HAS NO ICONV INTERFACE: # enca's own m4/libiconv.m4 settles the question by compiling and RUNNING # tools/iconvcap.c to generate the charset-alias table it is then built # against, and under cross-compilation that binary cannot execute on the build # host. configure falls back to an empty table, `enca --version` reports # -iconv-interface, and every -x fails. That is BRINTOS-603, not this port. # # SIX CASES BELOW ARE THEREFORE RED ON PURPOSE, and going green is the signal # BRINTOS-603 landed: version-iconv, koi8r-iconv, the three convert-* over 8-bit # charsets, and enconv-convert. They are NOT downgraded to skip -- the tool is # present and its converter half genuinely does not work, which is a `not ok` by # the packager guide's own rule. The two conversions that pass are the ones # needing no converter at all, which is what separates "enca cannot convert" # from "enca is broken". # # Every expectation is a value measured against a native x86_64 build of the # same 1.19 tarball, driven over the same fixtures. require enca enca/present D="$BST_DATA" tmp=${TMPDIR:-/tmp}/bst-enca.$$ mkdir -p "$tmp" # ---------------------------------------------------------------- identity --- check_out enca/version "enca 1.19" enca --version check_out enca/version-iconv "+iconv-interface" enca --version check_out enca/version-langs "+language-detection" enca --version check_out enca/help "Usage: enca" enca --help # enca refuses to guess without a language it understands: there is no locale on # this image, so a bare `enca FILE` is the documented rc-2 refusal, not a crash. check_rc enca/no-language 2 sh -c 'enca "$1" >/dev/null 2>&1' _ "$D/enca-ascii.txt" # Every error-path case below pairs a check_rc (the status) with a check_out (the # message). check_out also requires exit 0, so the message half runs the command # under `|| true` -- the status is already asserted by its own case, and folding # the two would only make a wrong rc fail twice under one name. check_out enca/no-language-msg "Cannot determine (or understand) your language preferences" \ sh -c 'enca "$1" 2>&1 || true' _ "$D/enca-ascii.txt" # ------------------------------------------------------------------- lists --- check_out enca/list-langs-ru "russian: KOI8-R CP1251" enca --list languages check_out enca/list-langs-cs "czech: ISO-8859-2 CP1250" enca --list languages check_eq enca/list-langs-n 15 "$(enca --list languages | wc -l)" check_eq enca/list-charsets-n 32 "$(enca --list charsets | wc -l)" check_eq enca/list-builtin-n 23 "$(enca --list built-in-charsets | wc -l)" check_out enca/list-surfaces "CRLF line terminators" enca --list surfaces check_out enca/list-names "rfc1345" enca --list names # --------------------------------------------------------------- detection --- # ASCII and UTF-8 are the two a language-less run can reach; the rest need -L. check_out enca/ascii-human "7bit ASCII characters" enca -L ru "$D/enca-ascii.txt" check_out enca/ascii-enca "ASCII" enca -L ru -e "$D/enca-ascii.txt" check_out enca/ascii-mime "US-ASCII" enca -L ru -m "$D/enca-ascii.txt" check_out enca/ascii-rfc "ANSI_X3.4-1968" enca -L ru -r "$D/enca-ascii.txt" check_out enca/utf8-human "Universal transformation format 8 bits; UTF-8" \ enca -L ru "$D/enca-ru-utf8.txt" check_out enca/utf8-enca "UTF-8" enca -L ru -e "$D/enca-ru-utf8.txt" check_out enca/utf8-nolang "UTF-8" enca -L none -e "$D/enca-ru-utf8.txt" # Russian: one fixture per charset in enca's own russian list, so a table that # goes wrong for one encoding is not masked by the others. check_out enca/koi8r-human "KOI8-R Cyrillic" enca -L ru "$D/enca-ru-koi8r.txt" check_out enca/koi8r-enca "KOI8-R/LF" enca -L ru -e "$D/enca-ru-koi8r.txt" check_out enca/koi8r-iconv "KOI8-R" enca -L ru -i "$D/enca-ru-koi8r.txt" check_out enca/koi8r-mime "KOI8-R" enca -L ru -m "$D/enca-ru-koi8r.txt" check_out enca/cp1251-human "MS-Windows code page 1251" enca -L ru "$D/enca-ru-cp1251.txt" check_out enca/cp1251-enca "CP1251/LF" enca -L ru -e "$D/enca-ru-cp1251.txt" check_out enca/cp1251-mime "windows-1251" enca -L ru -m "$D/enca-ru-cp1251.txt" check_out enca/iso88595-human "ISO 8859-5 standard; ISO Cyrillic" enca -L ru "$D/enca-ru-iso88595.txt" check_out enca/iso88595-enca "ISO-8859-5" enca -L ru -e "$D/enca-ru-iso88595.txt" check_out enca/iso88595-rfc "ISO_8859-5:1988" enca -L ru -r "$D/enca-ru-iso88595.txt" check_out enca/ibm866-human "IBM/MS code page 866" enca -L ru "$D/enca-ru-ibm866.txt" check_out enca/ibm866-enca "IBM866/LF" enca -L ru -e "$D/enca-ru-ibm866.txt" # Czech, on a second language's tables and a second name form (cstocs). check_out enca/cs-il2-human "ISO 8859-2 standard; ISO Latin 2" enca -L cs "$D/enca-cs-iso88592.txt" check_out enca/cs-il2-enca "ISO-8859-2" enca -L cs -e "$D/enca-cs-iso88592.txt" check_out enca/cs-il2-cstocs "il2" enca -L cs -s "$D/enca-cs-iso88592.txt" check_out enca/cs-1250-human "MS-Windows code page 1250" enca -L cs "$D/enca-cs-cp1250.txt" check_out enca/cs-1250-enca "CP1250/LF" enca -L cs -e "$D/enca-cs-cp1250.txt" check_out enca/cs-1250-mime "windows-1250" enca -L cs -m "$D/enca-cs-cp1250.txt" # Surfaces. enca's reference line terminator is CRLF, so a CRLF file reports NO # surface and an LF file reports one -- backwards from the Unix intuition, and # pinned here so a change to that convention is caught rather than shrugged at. check_out enca/surface-lf "LF line terminators" enca -L ru "$D/enca-ru-koi8r.txt" check_out enca/surface-crlf "KOI8-R Cyrillic" enca -L ru "$D/enca-ru-koi8r-crlf.txt" # stdout only: this case is an EXACT match on the name, and enca writes an # unrelated diagnostic to stderr on any image with no /usr/share/locale/ # locale.alias -- folding that in would make a surface assertion fail for a # reason that has nothing to do with surfaces. crlf=$(enca -L ru -e "$D/enca-ru-koi8r-crlf.txt" 2>/dev/null) check_eq enca/surface-crlf-bare "KOI8-R" "$crlf" # -L none reaches only the multibyte/ASCII cases: an 8-bit Cyrillic file is # genuinely unrecognizable without a language, and that is a result, not a bug. check_rc enca/nolang-8bit-rc 1 sh -c 'enca -L none "$1" >/dev/null 2>&1' _ "$D/enca-ru-koi8r.txt" check_out enca/nolang-8bit "Unrecognized encoding" sh -c 'enca -L none "$1" 2>&1 || true' _ "$D/enca-ru-koi8r.txt" # stdin, and the multi-file form that prefixes each result with its filename. check_out enca/stdin "KOI8-R Cyrillic" sh -c 'enca -L ru < "$1" 2>&1' _ "$D/enca-ru-koi8r.txt" check_out enca/multi-file "enca-ru-koi8r.txt: KOI8-R Cyrillic" \ sh -c 'cd "$1" && enca -L ru enca-ascii.txt enca-ru-koi8r.txt 2>&1' _ "$D" # ------------------------------------------------------------- error paths --- : > "$tmp/empty.txt" check_rc enca/empty-rc 1 sh -c 'enca -L ru "$1" >/dev/null 2>&1' _ "$tmp/empty.txt" check_out enca/empty "Unrecognized encoding" sh -c 'enca -L ru "$1" 2>&1 || true' _ "$tmp/empty.txt" check_out enca/empty-why "Failure reason: Sample is empty." sh -c 'enca -L ru -d "$1" 2>&1 || true' _ "$tmp/empty.txt" check_rc enca/nofile-rc 2 sh -c 'enca -L ru /nonexistent-enca-file >/dev/null 2>&1' check_out enca/nofile "No such file or directory" sh -c 'enca -L ru /nonexistent-enca-file 2>&1 || true' check_rc enca/badlang-rc 2 sh -c 'enca -L zzz "$1" >/dev/null 2>&1' _ "$D/enca-ascii.txt" check_rc enca/badopt-rc 2 sh -c 'enca -L ru --no-such-option "$1" >/dev/null 2>&1' _ "$D/enca-ascii.txt" check_out enca/badopt "Unknown option" sh -c 'enca -L ru --no-such-option "$1" 2>&1 || true' _ "$D/enca-ascii.txt" check_rc enca/badtarget-rc 1 sh -c 'enca -L ru -x NOSUCHCS "$1" >/dev/null 2>&1' _ "$D/enca-ascii.txt" check_out enca/badtarget "no converter is able/allowed to perform conversion" \ sh -c 'enca -L ru -x NOSUCHCS "$1" 2>&1 || true' _ "$D/enca-ascii.txt" # -------------------------------------------------------------- conversion --- # The strong form: enca's conversion is deterministic, so a converted file must # be byte-identical to the fixture already in the target charset. cmp, not a # content grep -- the native control confirmed each of these identical. # # The three 8-bit cases are the BRINTOS-603 reds; the two that follow them need # no converter at all and must stay green. The detail string carries enca's own # message so a NEW failure is told apart from the known one. conv() { # conv cp "$D/$2" "$tmp/c.txt" || { bst_notok "enca/$1" "fixture $2 unreadable"; return; } out=$(enca -L ru -x "$3" "$tmp/c.txt" 2>&1); rc=$? if [ "$rc" -ne 0 ]; then bst_notok "enca/$1" "rc=$rc $(_bst_1line "$out")" elif cmp -s "$tmp/c.txt" "$D/$4"; then bst_ok "enca/$1" else bst_notok "enca/$1" "converted output differs from $4" fi } conv convert-koi8r-utf8 enca-ru-koi8r.txt UTF-8 enca-ru-utf8.txt conv convert-cp1251-utf8 enca-ru-cp1251.txt UTF-8 enca-ru-utf8.txt conv convert-utf8-koi8r enca-ru-utf8.txt KOI8-R enca-ru-koi8r.txt # Both endpoints are converters glibc compiles into libc, so this one is # reachable with no gconv module at all -- it is what separates "iconv is # limited here" from "iconv is broken here". conv convert-ascii-utf8 enca-ascii.txt UTF-8 enca-ascii.txt conv convert-utf8-utf8 enca-ru-utf8.txt UTF-8 enca-ru-utf8.txt # ------------------------------------------------------------------ enconv --- # enconv is the same binary under a second name (a symlink), and argv[0] is what # flips it from guess mode to convert mode. check enca/enconv-present sh -c 'command -v enconv >/dev/null' check_out enca/enconv-help "enconv [-L LANGUAGE]" sh -c 'enconv --help 2>&1' cp "$D/enca-ru-koi8r.txt" "$tmp/e.txt" out=$(enconv -L ru -x UTF-8 "$tmp/e.txt" 2>&1); rc=$? if [ "$rc" -ne 0 ]; then bst_notok enca/enconv-convert "rc=$rc $(_bst_1line "$out")" elif cmp -s "$tmp/e.txt" "$D/enca-ru-utf8.txt"; then bst_ok enca/enconv-convert else bst_notok enca/enconv-convert "converted output differs from enca-ru-utf8.txt"; fi # --------------------------------------------------------------- packaging --- check enca/installed-enca test -x /usr/bin/enca check enca/installed-enconv test -L /usr/bin/enconv # The distro builds no shared objects, so a stray libenca.so here would mean the # blanket --disable-shared was lost for this recipe. check enca/no-shared-lib sh -c '! ls /usr/lib/libenca.so* >/dev/null 2>&1' rm -rf "$tmp"