summaryrefslogtreecommitdiff
path: root/test/RegressTests.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/RegressTests.py')
-rwxr-xr-xtest/RegressTests.py74
1 files changed, 55 insertions, 19 deletions
diff --git a/test/RegressTests.py b/test/RegressTests.py
index 13a0a113..2d8ef8e8 100755
--- a/test/RegressTests.py
+++ b/test/RegressTests.py
@@ -5,24 +5,42 @@ import os
import re
import tempfile
+multiproc = False
+try:
+ from multiprocessing import Pool
+ multiproc = True
+except:
+ pass
+
from string import join
from difflib import unified_diff
from LedgerHarness import LedgerHarness
-harness = LedgerHarness(sys.argv)
-tests = sys.argv[3]
+args = sys.argv
+jobs = 1
+match = re.match('-j([0-9]+)?', args[1])
+if match:
+ args = [args[0]] + args[2:]
+ if match.group(1):
+ jobs = int(match.group(1))
+if jobs == 1:
+ multiproc = False
+
+harness = LedgerHarness(args)
+tests = args[3]
if not os.path.isdir(tests) and not os.path.isfile(tests):
sys.exit(1)
-class RegressFile:
+class RegressFile(object):
def __init__(self, filename):
self.filename = filename
self.fd = open(self.filename)
def is_directive(self, line):
return line == "<<<\n" or \
+ line == ">>>\n" or \
line == ">>>1\n" or \
line == ">>>2\n" or \
line.startswith("===")
@@ -34,7 +52,7 @@ class RegressFile:
def read_section(self):
lines = []
line = self.fd.readline()
- while not self.is_directive(line):
+ while line and not self.is_directive(line):
lines.append(self.transform_line(line))
line = self.fd.readline()
return (lines, line)
@@ -42,10 +60,10 @@ class RegressFile:
def read_test(self, last_test = None):
test = {
'command': None,
- 'input': None,
- 'output': None,
- 'error': None,
- 'exitcode': None
+ 'input': "",
+ 'output': "",
+ 'error': "",
+ 'exitcode': 0
}
if last_test:
test['input'] = last_test['input']
@@ -54,7 +72,7 @@ class RegressFile:
while line:
if line == "<<<\n":
(test['input'], line) = self.read_section()
- elif line == ">>>1\n":
+ elif line == ">>>\n" or line == ">>>1\n":
(test['output'], line) = self.read_section()
elif line == ">>>2\n":
(test['error'], line) = self.read_section()
@@ -141,19 +159,37 @@ class RegressFile:
while test:
self.run_test(test)
test = self.read_test(test)
+ return harness.failed
def close(self):
self.fd.close()
-if os.path.isdir(tests):
- for test_file in os.listdir(tests):
- if re.search('\.test$', test_file):
- entry = RegressFile(os.path.join(tests, test_file))
- entry.run_tests()
- entry.close()
-else:
- entry = RegressFile(tests)
- entry.run_tests()
+def do_test(path):
+ entry = RegressFile(path)
+ failed = entry.run_tests()
entry.close()
+ return failed
+
+if __name__ == '__main__':
+ if multiproc:
+ pool = Pool(jobs*2)
+ else:
+ pool = None
+
+ if os.path.isdir(tests):
+ tests = [os.path.join(tests, x)
+ for x in os.listdir(tests) if x.endswith('.test')]
+ if pool:
+ harness.failed = sum(pool.map(do_test, tests, 1))
+ else:
+ harness.failed = sum(map(do_test, tests))
+ else:
+ entry = RegressFile(tests)
+ entry.run_tests()
+ entry.close()
+
+ if pool:
+ pool.close()
+ pool.join()
-harness.exit()
+ harness.exit()