v / examples / password / password_test.v
27 lines · 22 sloc · 1007 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', 'password', 'tests')
10
11fn test_password_input() {
12 correct := os.execute(os.join_path(expect_tests_path, 'correct.expect'))
13 assert correct.exit_code == 0, correct.output
14
15 incorrect := os.execute(os.join_path(expect_tests_path, 'incorrect.expect'))
16 assert incorrect.exit_code == 0, incorrect.output
17
18 expected_out := 'Enter your password : '
19 mut res :=
20 os.execute('${os.join_path(expect_tests_path, 'output_from_expect_arg.expect')} "${expected_out}"')
21 assert res.exit_code == 0, res.output
22
23 not_exptectd_out := 'Enter your passwords : '
24 res =
25 os.execute('${os.join_path(expect_tests_path, 'output_from_expect_arg.expect')} "${not_exptectd_out}"')
26 assert res.exit_code == 1, res.output
27}
28