| 1 | #!/usr/bin/env python3
 | 
| 2 | """
 | 
| 3 | interactive.py
 | 
| 4 | """
 | 
| 5 | from __future__ import print_function
 | 
| 6 | 
 | 
| 7 | import sys
 | 
| 8 | import time
 | 
| 9 | 
 | 
| 10 | import harness
 | 
| 11 | from harness import register, expect_prompt
 | 
| 12 | 
 | 
| 13 | 
 | 
| 14 | @register()
 | 
| 15 | def syntax_error(sh):
 | 
| 16 |     'syntax error makes status=2'
 | 
| 17 | 
 | 
| 18 |     sh.sendline('syntax ) error')
 | 
| 19 | 
 | 
| 20 |     #time.sleep(0.1)
 | 
| 21 | 
 | 
| 22 |     expect_prompt(sh)
 | 
| 23 | 
 | 
| 24 |     sh.sendline('echo status=$?')
 | 
| 25 | 
 | 
| 26 |     if sh.shell_label == 'mksh':
 | 
| 27 |         # mksh gives status=1, and zsh doesn't give anything?
 | 
| 28 |         sh.expect('status=1')
 | 
| 29 |     else:
 | 
| 30 |         sh.expect('status=2')  # osh, bash, dash
 | 
| 31 | 
 | 
| 32 | 
 | 
| 33 | @register()
 | 
| 34 | def bg_proc_notify(sh):
 | 
| 35 |     'notification about background process (issue 1093)'
 | 
| 36 | 
 | 
| 37 |     expect_prompt(sh)
 | 
| 38 | 
 | 
| 39 |     sh.sendline('sleep 0.1 &')
 | 
| 40 |     if sh.shell_label == 'bash':
 | 
| 41 |         # e.g. [1] 12345
 | 
| 42 |         # not using trailing + because pexpect doc warns about that case
 | 
| 43 |         # dash doesn't print this
 | 
| 44 |         sh.expect(r'\[\d+\]')
 | 
| 45 | 
 | 
| 46 |     sh.sendline('sleep 0.2 &')
 | 
| 47 |     if sh.shell_label == 'bash':
 | 
| 48 |         # e.g. [1] 12345
 | 
| 49 |         # not using trailing + because pexpect doc warns about that case
 | 
| 50 |         # dash doesn't print this
 | 
| 51 |         sh.expect(r'\[\d+\]')
 | 
| 52 | 
 | 
| 53 |     expect_prompt(sh)
 | 
| 54 | 
 | 
| 55 |     # Wait until after it stops and then hit enter
 | 
| 56 |     time.sleep(0.4)
 | 
| 57 |     sh.sendline('')
 | 
| 58 |     sh.expect(r'.*Done.*Done.*')
 | 
| 59 | 
 | 
| 60 |     sh.sendline('echo status=$?')
 | 
| 61 |     sh.expect('status=0')
 | 
| 62 | 
 | 
| 63 | 
 | 
| 64 | @register()
 | 
| 65 | def bg_pipeline_notify(sh):
 | 
| 66 |     'notification about background pipeline (issue 1093)'
 | 
| 67 | 
 | 
| 68 |     expect_prompt(sh)
 | 
| 69 | 
 | 
| 70 |     sh.sendline('sleep 0.1 | cat &')
 | 
| 71 | 
 | 
| 72 |     if sh.shell_label == 'bash':
 | 
| 73 |         # e.g. [1] 12345
 | 
| 74 |         # not using trailing + because pexpect doc warns about that case
 | 
| 75 |         # dash doesn't print this
 | 
| 76 |         sh.expect(r'\[\d+\]')
 | 
| 77 | 
 | 
| 78 |     expect_prompt(sh)
 | 
| 79 | 
 | 
| 80 |     time.sleep(0.2)
 | 
| 81 |     sh.sendline('')
 | 
| 82 | 
 | 
| 83 |     sh.expect(r'.*Done.*')
 | 
| 84 | 
 | 
| 85 |     sh.sendline('echo status=$?')
 | 
| 86 |     sh.expect('status=0')
 | 
| 87 | 
 | 
| 88 | 
 | 
| 89 | if __name__ == '__main__':
 | 
| 90 |     try:
 | 
| 91 |         sys.exit(harness.main(sys.argv))
 | 
| 92 |     except RuntimeError as e:
 | 
| 93 |         print('FATAL: %s' % e, file=sys.stderr)
 | 
| 94 |         sys.exit(1)
 |