| 1 | import os |
| 2 | |
| 3 | // Expect has to be installed for the test. |
| 4 | const expect_exe = os.find_abs_path_of_executable('expect') or { |
| 5 | eprintln('skipping test, since expect is missing') |
| 6 | exit(0) |
| 7 | } |
| 8 | // Directory that contains the Expect scripts used in the test. |
| 9 | const expect_tests_path = os.join_path(@VMODROOT, 'examples', 'readline', 'tests') |
| 10 | |
| 11 | fn test_password_input() { |
| 12 | correct := os.execute(os.join_path(expect_tests_path, 'readline.expect')) |
| 13 | assert correct.exit_code == 0, correct.output |
| 14 | |
| 15 | send_a := 'a' |
| 16 | expect_a := 'got 97' // readline output for `a` |
| 17 | a_res := |
| 18 | os.execute('${os.join_path(expect_tests_path, 'readline_from_expect_arg.expect')} ${send_a} "${expect_a}"') |
| 19 | assert a_res.exit_code == 0, a_res.output |
| 20 | |
| 21 | send_b := 'b' |
| 22 | b_res := |
| 23 | os.execute('${os.join_path(expect_tests_path, 'readline_from_expect_arg.expect')} ${send_b} "${expect_a}"') |
| 24 | assert b_res.exit_code == 1, b_res.output |
| 25 | assert b_res.output.contains('got 98') |
| 26 | } |
| 27 | |