LEFT | RIGHT |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # coding: utf-8 | 2 # coding: utf-8 |
3 | 3 |
4 # This Source Code is subject to the terms of the Mozilla Public License | 4 # This Source Code is subject to the terms of the Mozilla Public License |
5 # version 2.0 (the "License"). You can obtain a copy of the License at | 5 # version 2.0 (the "License"). You can obtain a copy of the License at |
6 # http://mozilla.org/MPL/2.0/. | 6 # http://mozilla.org/MPL/2.0/. |
7 | 7 |
8 import sys, os, re, difflib, utils | 8 import sys, os, subprocess, re, difflib, utils |
9 | 9 |
10 def run_tests(): | 10 def run_tests(): |
11 application = utils.ensureJSShell() | 11 application = utils.ensureJSShell() |
12 env = { | 12 env = { |
13 'LD_LIBRARY_PATH': os.path.relpath(os.path.dirname(application)), | 13 'LD_LIBRARY_PATH': os.path.relpath(os.path.dirname(application)), |
14 } | 14 } |
15 | 15 |
16 baseDir = os.path.dirname(utils.__file__) | 16 baseDir = os.path.dirname(utils.__file__) |
17 testDir = os.path.join(baseDir, 'autotest') | 17 testDir = os.path.join(baseDir, 'autotest') |
18 for file in os.listdir(testDir): | 18 for file in os.listdir(testDir): |
19 if not re.search(r'^test_.*\.js$', file): | 19 if not re.search(r'^test_.*\.js$', file): |
20 continue | 20 continue |
21 | 21 |
22 file = os.path.join(testDir, file) | 22 file = os.path.join(testDir, file) |
23 handle = open(file, 'r') | 23 handle = open(file, 'r') |
24 name = None | 24 name = None |
25 arguments = None | 25 arguments = None |
26 for line in handle: | 26 for line in handle: |
27 match = re.search(r'^//\s*([A-Za-z]+):\s*(.*?)\s*$', line) | 27 match = re.search(r'^//\s*([A-Za-z]+):\s*(.*?)\s*$', line) |
28 if match and match.group(1).lower() == 'name': | 28 if match and match.group(1).lower() == 'name': |
29 name = match.group(2) | 29 name = match.group(2) |
30 elif match and match.group(1).lower() == 'arguments': | 30 elif match and match.group(1).lower() == 'arguments': |
31 arguments = match.group(2).split(' ') | 31 arguments = match.group(2).split(' ') |
32 handle.close() | 32 handle.close() |
33 | 33 |
34 if arguments == None: | 34 if arguments == None: |
35 continue | 35 continue |
36 | 36 |
37 command = [application, os.path.join(baseDir, 'jshydra.js'), file] + argumen
ts | 37 command = [application, os.path.join(baseDir, 'jshydra.js'), file] + argumen
ts |
38 out = utils.run(command, utils.STREAMS_STDOUT, env=env).replace('\r', '') | 38 out = subprocess.check_output(command, stderr=subprocess.STDOUT, env=env).re
place('\r', '') |
39 expected = open(file + '.expected', 'r').read().replace('\r', '') | 39 expected = open(file + '.expected', 'r').read().replace('\r', '') |
40 if out == expected: | 40 if out == expected: |
41 print '%s passed' % name | 41 print '%s passed' % name |
42 else: | 42 else: |
43 print '%s failed! Log:' % name | 43 print '%s failed! Log:' % name |
44 for line in difflib.unified_diff(expected.split('\n'), out.split('\n'), fr
omfile=file + '.expected', tofile=file + '.output'): | 44 for line in difflib.unified_diff(expected.split('\n'), out.split('\n'), fr
omfile=file + '.expected', tofile=file + '.output'): |
45 print line | 45 print line |
46 print | 46 print |
47 | 47 |
48 if __name__ == '__main__': | 48 if __name__ == '__main__': |
49 run_tests() | 49 run_tests() |
LEFT | RIGHT |