v / examples / readline / readline_test.v
26 lines · 22 sloc · 929 bytes · e2e5cf8db56f3562c7baa735061690be936bdf3e
Raw
1import os
2
3// Expect has to be installed for the test.
4const 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.
9const expect_tests_path = os.join_path(@VMODROOT, 'examples', 'readline', 'tests')
10
11fn 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