# selftest_bitwise.exp — drives bitwise's interactive half over a REAL pty. # # WHY THIS FILE EXISTS. bitwise is two programs sharing a binary. The one the # piped runner can reach is the converter: `bitwise ` prints the value in # every base and exits, and 61-bitwise.test covers it directly and thoroughly. # The other is the reason the package depends on ncurses AND readline — a # full-screen form, width hotkeys read through wgetch(), and a ':' command line # that is readline. On a pipe, initscr() has no terminal and readline() has no # input, so NONE of that is observable: a build in which both libraries were # stubs would pass every non-interactive case in the suite. These four cases are # the only thing that says the two libraries this port is built on actually work # on target. # # EVERY SESSION SIZES ITS OWN TERMINAL. expect's stty_init is not applied to the # pty it allocates on this target — a fresh spawn reports the controlling # console's geometry instead — so the `stty rows 24 columns 80` prefix below is # load-bearing: the bit ruler and the field row are laid out from COLS, and # without it the geometry-dependent strings this file matches on are a property # of whoever ran the suite. 59-dialog.test carries the same prologue, measured # the same way. # # THE MATCH STRINGS ARE SINGLE mvwprintw WRITES, deliberately. "Hexdecimal:" # (upstream's spelling), "64Bit" and "63 - 56" each land in the pty as one # contiguous run of bytes; a needle spanning two of ncurses' writes would have # cursor-motion escapes spliced through it and would never match. Verified # against the byte stream, not assumed. # # Emits BWX-OK/BWX-FAIL lines for 61-bitwise.test to grade. log_user 0 set env(TERM) "xterm" set timeout 20 set SIZE "stty rows 24 columns 80;" proc emit {verdict case detail} { puts "BWX-$verdict $case $detail" } # --- session 1: the form renders, a width hotkey repaints it, 'q' exits ------- spawn -noecho sh -c "$SIZE exec bitwise -i 255" set seen 0 expect { "Hexdecimal:" { set seen 1 } timeout { } eof { } } if {$seen} { emit OK tui-render "" } else { emit FAIL tui-render "no Hexdecimal: field label — initscr() screen never painted" } # '*' selects the 64-bit width. The header repaints from "8Bit" to "64Bit" and # the ruler grows to 63 - 56; either proves the keystroke reached wgetch() and # the form was rebuilt. send -- "*" set wide 0 expect { "64Bit" { set wide 1 } "63 - 56" { set wide 1 } timeout { } eof { } } if {$wide} { emit OK tui-width-key "" } else { emit FAIL tui-width-key "'*' did not repaint the form at 64-bit width" } send -- "q" expect { eof {} timeout {} } lassign [wait] _p _s _oserr _rc if {$_oserr == 0 && $_rc == 0} { emit OK tui-quit-key "" } else { emit FAIL tui-quit-key "oserr=$_oserr rc=$_rc" } # --- session 2: the readline command line ------------------------------------ # ':' hands the bottom window to readline and redisplays its prompt; "q\r" is # cmd_quit read back through it. Every keystroke above came from wgetch(); this # is the only case in the whole suite that exercises readline at all. spawn -noecho sh -c "$SIZE exec bitwise -i 4660" set seen 0 expect { "Hexdecimal:" { set seen 1 } timeout { } eof { } } if {!$seen} { emit FAIL tui-readline-quit "form never rendered; ':' not reachable" catch { exp_close } catch { wait } } else { send -- ":" sleep 1 send -- "q\r" expect { eof {} timeout {} } lassign [wait] _p2 _s2 _oserr2 _rc2 if {$_oserr2 == 0 && $_rc2 == 0} { emit OK tui-readline-quit "" } else { emit FAIL tui-readline-quit "oserr=$_oserr2 rc=$_rc2" } }