| OLD | NEW |
| 1 # Copyright (C) 2010 Google Inc. All rights reserved. | 1 # Copyright (C) 2010 Google Inc. All rights reserved. |
| 2 # Copyright (C) 2009 Daniel Bates (dbates@intudata.com). All rights reserved. | 2 # Copyright (C) 2009 Daniel Bates (dbates@intudata.com). All rights reserved. |
| 3 # | 3 # |
| 4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
| 5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
| 6 # met: | 6 # met: |
| 7 # | 7 # |
| 8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
| 9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
| 10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 script_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.
path.abspath(__file__))))) | 40 script_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.
path.abspath(__file__))))) |
| 41 if script_dir not in sys.path: | 41 if script_dir not in sys.path: |
| 42 sys.path.append(script_dir) | 42 sys.path.append(script_dir) |
| 43 | 43 |
| 44 | 44 |
| 45 from webkitpy.common.system.executive import Executive, ScriptError | 45 from webkitpy.common.system.executive import Executive, ScriptError |
| 46 from webkitpy.common.system.filesystem_mock import MockFileSystem | 46 from webkitpy.common.system.filesystem_mock import MockFileSystem |
| 47 | 47 |
| 48 | 48 |
| 49 class ScriptErrorTest(unittest.TestCase): | 49 class ScriptErrorTest(unittest.TestCase): |
| 50 |
| 50 def test_message_with_output(self): | 51 def test_message_with_output(self): |
| 51 error = ScriptError('My custom message!', '', -1) | 52 error = ScriptError('My custom message!', '', -1) |
| 52 self.assertEqual(error.message_with_output(), 'My custom message!') | 53 self.assertEqual(error.message_with_output(), 'My custom message!') |
| 53 error = ScriptError('My custom message!', '', -1, 'My output.') | 54 error = ScriptError('My custom message!', '', -1, 'My output.') |
| 54 self.assertEqual(error.message_with_output(), 'My custom message!\n\nout
put: My output.') | 55 self.assertEqual(error.message_with_output(), 'My custom message!\n\nout
put: My output.') |
| 55 error = ScriptError('', 'my_command!', -1, 'My output.', '/Users/usernam
e/blah') | 56 error = ScriptError('', 'my_command!', -1, 'My output.', '/Users/usernam
e/blah') |
| 56 self.assertEqual(error.message_with_output(), 'Failed to run "\'my_comma
nd!\'" exit_code: -1 cwd: /Users/username/blah\n\noutput: My output.') | 57 self.assertEqual(error.message_with_output(), |
| 58 'Failed to run "\'my_command!\'" exit_code: -1 cwd: /Us
ers/username/blah\n\noutput: My output.') |
| 57 error = ScriptError('', 'my_command!', -1, 'ab' + '1' * 499) | 59 error = ScriptError('', 'my_command!', -1, 'ab' + '1' * 499) |
| 58 self.assertEqual(error.message_with_output(), 'Failed to run "\'my_comma
nd!\'" exit_code: -1\n\noutput: Last 500 characters of output:\nb' + '1' * 499) | 60 self.assertEqual(error.message_with_output(), |
| 61 'Failed to run "\'my_command!\'" exit_code: -1\n\noutpu
t: Last 500 characters of output:\nb' + '1' * 499) |
| 59 | 62 |
| 60 def test_message_with_tuple(self): | 63 def test_message_with_tuple(self): |
| 61 error = ScriptError('', ('my', 'command'), -1, 'My output.', '/Users/use
rname/blah') | 64 error = ScriptError('', ('my', 'command'), -1, 'My output.', '/Users/use
rname/blah') |
| 62 self.assertEqual(error.message_with_output(), 'Failed to run "(\'my\', \
'command\')" exit_code: -1 cwd: /Users/username/blah\n\noutput: My output.') | 65 self.assertEqual(error.message_with_output(), |
| 66 'Failed to run "(\'my\', \'command\')" exit_code: -1 cw
d: /Users/username/blah\n\noutput: My output.') |
| 67 |
| 63 | 68 |
| 64 def never_ending_command(): | 69 def never_ending_command(): |
| 65 """Arguments for a command that will never end (useful for testing process | 70 """Arguments for a command that will never end (useful for testing process |
| 66 killing). It should be a process that is unlikely to already be running | 71 killing). It should be a process that is unlikely to already be running |
| 67 because all instances will be killed.""" | 72 because all instances will be killed.""" |
| 68 if sys.platform == 'win32': | 73 if sys.platform == 'win32': |
| 69 return ['wmic'] | 74 return ['wmic'] |
| 70 return ['yes'] | 75 return ['yes'] |
| 71 | 76 |
| 72 | 77 |
| 73 def command_line(cmd, *args): | 78 def command_line(cmd, *args): |
| 74 return [sys.executable, __file__, '--' + cmd] + list(args) | 79 return [sys.executable, __file__, '--' + cmd] + list(args) |
| 75 | 80 |
| 76 | 81 |
| 77 class ExecutiveTest(unittest.TestCase): | 82 class ExecutiveTest(unittest.TestCase): |
| 83 |
| 78 def assert_interpreter_for_content(self, intepreter, content): | 84 def assert_interpreter_for_content(self, intepreter, content): |
| 79 fs = MockFileSystem() | 85 fs = MockFileSystem() |
| 80 | 86 |
| 81 tempfile, temp_name = fs.open_binary_tempfile('') | 87 tempfile, temp_name = fs.open_binary_tempfile('') |
| 82 tempfile.write(content) | 88 tempfile.write(content) |
| 83 tempfile.close() | 89 tempfile.close() |
| 84 file_interpreter = Executive.interpreter_for_script(temp_name, fs) | 90 file_interpreter = Executive.interpreter_for_script(temp_name, fs) |
| 85 | 91 |
| 86 self.assertEqual(file_interpreter, intepreter) | 92 self.assertEqual(file_interpreter, intepreter) |
| 87 | 93 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 import msvcrt | 200 import msvcrt |
| 195 msvcrt.setmode(stdout.fileno(), os.O_BINARY) | 201 msvcrt.setmode(stdout.fileno(), os.O_BINARY) |
| 196 if cmd == '--cat': | 202 if cmd == '--cat': |
| 197 stdout.write(stdin.read()) | 203 stdout.write(stdin.read()) |
| 198 elif cmd == '--echo': | 204 elif cmd == '--echo': |
| 199 stdout.write(' '.join(args)) | 205 stdout.write(' '.join(args)) |
| 200 return 0 | 206 return 0 |
| 201 | 207 |
| 202 if __name__ == '__main__' and len(sys.argv) > 1 and sys.argv[1] in ('--cat', '--
echo'): | 208 if __name__ == '__main__' and len(sys.argv) > 1 and sys.argv[1] in ('--cat', '--
echo'): |
| 203 sys.exit(main(sys.platform, sys.stdin, sys.stdout, sys.argv[1], sys.argv[2:]
)) | 209 sys.exit(main(sys.platform, sys.stdin, sys.stdout, sys.argv[1], sys.argv[2:]
)) |
| OLD | NEW |