dimanche 22 novembre 2020

Make Expect throw error on unexpected output

I'm using the following expect script test.exp to test a CLI application I'm developing:

spawn ./note_trainer.exe --seed 0

expect "note_trainer using seed 0"
expect "Note G# transposed down 6 semi-tones gives what? "
send "D\r"
expect "Correct!\r"
send "\004"

The script works as intended: it waits for the appropriate output from the process, sends a string, and obtains the correct result. However, I would like the expect script to fail if note_trainer.exe does not behave intended.

Specifically, if the ./note_trainer.exe returns "Incorrect!" instead "Correct!", I want expect test.exp to fail in someway, and return an error code.

Currently, all it does is wait until a timeout is reached, and then exit with error code 0.

Aucun commentaire:

Enregistrer un commentaire