. "$BST_LIB" require nano nano/present # --- the surface that needs no terminal ------------------------------------- # These run before the pty leg on purpose: if expect is ever absent, the `require` # below ends the file, and these have already reported. check_out nano/version "GNU nano, version 7.2" nano --version check_out nano/help "--constantshow" nano --help # libmagic is linked in (nano uses it to pick a syntax by file type) and is what # drags the bz2/xz decompressors behind it — the whole reason this port needed a # bbappend. This build is full, not --enable-tiny, and a full build's "Compiled # options:" line lists what is *disabled*: so libmagic being present means # --disable-libmagic is ABSENT. Assert that sense, not its opposite. if nano --version 2>&1 | grep -q -- '--disable-libmagic'; then bst_notok nano/libmagic "nano --version reports --disable-libmagic — the libmagic link was lost" else bst_ok nano/libmagic fi # ...and that this is the full editor rather than the cut-down one. if nano --version 2>&1 | grep -q -- '--enable-tiny'; then bst_notok nano/full-build "nano is built --enable-tiny; the image expects the full editor" else bst_ok nano/full-build fi # --- the real test: a full-screen editor, driven over a real pty -------------- # nano has no batch mode, so everything above is preamble. expect supplies the # pty; 45-expect.test covers whether that machinery works at all. The payload # types blind and the verdicts below read the DISK — see its header for why that # is both necessary here and the stronger assertion. require expect nano/expect-present work=${TMPDIR:-/tmp}/bst-nano.$$ mkdir -p "$work" printf '%s\n' alpha bravo charlie > "$work/cut.txt" printf '%s\n' alpha bravo charlie > "$work/arrow.txt" out=$(expect "$BST_DATA/selftest_nano.exp" "$work" 2>&1); rc=$? case "$out" in *ALL-NANO-OK*) all=1 ;; *) all=0 ;; esac if [ "$rc" -eq 0 ] && [ "$all" -eq 1 ]; then bst_ok nano/all-ok else bst_notok nano/all-ok "rc=$rc $(_bst_1line "$out")"; fi # nano started under a real terminal (curses init + $TERM resolved out of # /etc/terminfo + first repaint), and each session exited 0 of its own accord. for tag in N1start N2exit N3cutexit N4arrowexit; do case "$out" in *"N-$tag OK"*) bst_ok "nano/$tag" ;; *) bst_notok "nano/$tag" "not OK in payload output (rc=$rc)" ;; esac done # --- what actually reached the disk (the verdicts that count) ---------------- # S1: text typed at the editor, saved with ^O, in the right order and nothing else. check_out nano/typed-first "hello from nano" sh -c "cat '$work/typed.txt'" check_out nano/typed-second "second line" sh -c "cat '$work/typed.txt'" check_eq nano/typed-lines 2 "$(wc -l < "$work/typed.txt" 2>/dev/null | tr -d ' ')" # S2: ^K on line 1 removed exactly that line and left the rest intact. check_eq nano/cut-lines 2 "$(wc -l < "$work/cut.txt" 2>/dev/null | tr -d ' ')" if grep -q '^alpha$' "$work/cut.txt" 2>/dev/null; then bst_notok nano/cut-removed "alpha still present after ^K + ^O" else bst_ok nano/cut-removed fi check_out nano/cut-kept "charlie" sh -c "cat '$work/cut.txt'" # S3: THE ESCAPE-SEQUENCE VERDICT. Down arrow (ESC [ B) then ^K must take line 2. # alpha kept + charlie kept + bravo gone == the sequence decoded as one key. # bravo present (and alpha gone) would mean the ESC never joined its bracket, and # a stray "[B" in the file would mean it was typed as literal text instead. check_eq nano/arrow-lines 2 "$(wc -l < "$work/arrow.txt" 2>/dev/null | tr -d ' ')" if grep -q '^bravo$' "$work/arrow.txt" 2>/dev/null; then bst_notok nano/arrow-decoded "bravo survived: Down (ESC [ B) did not move the cursor to line 2" else bst_ok nano/arrow-decoded fi check_out nano/arrow-kept-first "alpha" sh -c "cat '$work/arrow.txt'" check_out nano/arrow-kept-last "charlie" sh -c "cat '$work/arrow.txt'" if grep -q '\[B' "$work/arrow.txt" 2>/dev/null; then bst_notok nano/arrow-not-literal "the escape sequence was inserted as literal text" else bst_ok nano/arrow-not-literal fi rm -rf "$work"