Rename gsh to polysh.
[polysh.git] / tests / tests / non_interactive.py
blobf0b41a2b75927527689a898ee8a691c2c64ea64c
1 # This program is free software; you can redistribute it and/or modify
2 # it under the terms of the GNU General Public License as published by
3 # the Free Software Foundation; either version 2 of the License, or
4 # (at your option) any later version.
6 # This program is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # GNU Library General Public License for more details.
11 # You should have received a copy of the GNU General Public License
12 # along with this program; if not, write to the Free Software
13 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 # See the COPYING file for license information.
17 # Copyright (c) 2007 Guillaume Chazarain <guichaz@gmail.com>
19 import os
20 import unittest
21 import pexpect
22 from polysh_tests import launch_polysh
24 class TestNonInteractive(unittest.TestCase):
25 def testCommandNormal(self):
26 child = launch_polysh(['--command=echo text', 'localhost'])
27 child.expect('\033\[1;36mlocalhost : \033\[1;mtext')
28 child.expect(pexpect.EOF)
30 def testCommandIntr(self):
31 child = launch_polysh(['--command=echo text; cat', 'localhost'])
32 child.expect('\033\[1;36mlocalhost : \033\[1;mtext')
33 child.sendintr()
34 child.expect(pexpect.EOF)
36 def testSimpleCommandStdin(self):
37 child = launch_polysh(['localhost'], input_data='echo line')
38 child.expect('localhost : line')
39 child.expect(pexpect.EOF)
41 def testMultipleCommandStdin(self):
42 commands = """
43 echo first
44 echo next
45 echo last
46 """
47 child = launch_polysh(['localhost'], input_data=commands)
48 child.expect('localhost : first')
49 child.expect('localhost : next')
50 child.expect('localhost : last')
51 child.expect(pexpect.EOF)
53 def testInvalidCommandStdin(self):
54 child = launch_polysh(['localhost', '--command=date'], input_data='uptime')
55 child.expect('--command and reading from stdin are incompatible')
56 child.expect(pexpect.EOF)
58 def testExitCode(self):
59 def CommandCode(command, code):
60 child = launch_polysh(['--command=%s' % command] + ['localhost'] * 5)
61 child.expect(pexpect.EOF)
62 while child.isalive():
63 child.wait()
64 self.assertEqual(child.exitstatus, code)
65 CommandCode('true', 0)
66 CommandCode('false', 1)