# BRINTOS-1 Expect self-test (reused verbatim for BRINTOS-6 on the glibc # machine). Reaching ALL-EXPECT-OK proves Expect's spawn/expect works over a # real pty: openpty, fork, execve, bidirectional tty I/O, glob and regexp # matching, and child exit-status reaping. R-labelled checks, env-var-free, # one line per check, an ALL-*-OK sentinel. exp_internal 0 log_user 0 set timeout 8 set pass 0 proc ok {t} { global pass; incr pass; puts "E-$t OK"; flush stdout } proc bad {t w} { puts "E-$t FAIL ($w)"; flush stdout } # E1 — interpreter up: Expect's own commands are loaded, i.e. Tcl_Init # succeeded inside the expect binary (else expect aborts before this runs). if {[catch {exp_version} v]} { set v "?"; bad E1ver "exp_version threw" } else { ok E1ver } puts "E1-ver $v"; flush stdout # E2 + E3 run over ONE spawned pty: spawn a cat, exchange two lines with it. # E2 is a literal glob match, E3 a regexp match with a capture — together a # two-turn send/expect dialogue (the prompt/response pattern Expect exists for). if {[catch {spawn /bin/cat} err]} { bad E2spawn "spawn threw: $err" bad E3regexp "no spawn" } else { # E2 — round-trip a literal marker over the pty (fork + execve + tty I/O). send "MARK-42\r" expect { "MARK-42" { ok E2spawn } timeout { bad E2spawn timeout } eof { bad E2spawn eof } } # E3 — regexp match with a capture (expect -re), Expect's signature feature. send "val=1234;\r" expect { -re {val=([0-9]+)} { if {$expect_out(1,string) eq "1234"} { ok E3regexp } else { bad E3regexp "cap=$expect_out(1,string)" } } timeout { bad E3regexp timeout } eof { bad E3regexp eof } } send "\004"; catch {expect eof}; catch {wait} } # E4 — child exit-status reaping: spawn a command that exits non-zero, wait, # check the code (SIGCHLD/waitpid propagate the real exit status through Expect). if {[catch {spawn /bin/false} err]} { bad E4wait "spawn threw: $err" } else { catch {expect eof} if {[catch {wait} st]} { bad E4wait "wait threw: $st" } elseif {[lindex $st 3] == 1} { ok E4wait } else { bad E4wait "status=$st" } } puts "E-SUMMARY pass=$pass/4" if {$pass == 4} { puts "ALL-EXPECT-OK" } flush stdout