Index: test/mjsunit/testcfg.py |
diff --git a/test/mjsunit/testcfg.py b/test/mjsunit/testcfg.py |
index 9c7e028078e3a2a510fe6d3b33cb435021520e33..96840f5cf82815179598ed4805c0296a7faf7b7e 100644 |
--- a/test/mjsunit/testcfg.py |
+++ b/test/mjsunit/testcfg.py |
@@ -29,10 +29,12 @@ import test |
import os |
from os.path import join, dirname, exists |
import re |
+import tempfile |
FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)") |
FILES_PATTERN = re.compile(r"//\s+Files:(.*)") |
+SELF_SCRIPT_PATTERN = re.compile(r"//\s+Env: TEST_FILE_NAME") |
class MjsunitTestCase(test.TestCase): |
@@ -42,6 +44,7 @@ class MjsunitTestCase(test.TestCase): |
self.file = file |
self.config = config |
self.mode = mode |
+ self.self_script = False |
def GetLabel(self): |
return "%s %s" % (self.mode, self.GetName()) |
@@ -55,19 +58,43 @@ class MjsunitTestCase(test.TestCase): |
flags_match = FLAGS_PATTERN.search(source) |
if flags_match: |
result += flags_match.group(1).strip().split() |
- files_match = FILES_PATTERN.search(source); |
additional_files = [] |
- if files_match: |
- additional_files += files_match.group(1).strip().split() |
+ files_match = FILES_PATTERN.search(source); |
+ # Accept several lines of 'Files:' |
+ while True: |
+ if files_match: |
+ additional_files += files_match.group(1).strip().split() |
+ files_match = FILES_PATTERN.search(source, files_match.end()) |
+ else: |
+ break |
for a_file in additional_files: |
result.append(join(dirname(self.config.root), '..', a_file)) |
framework = join(dirname(self.config.root), 'mjsunit', 'mjsunit.js') |
+ if SELF_SCRIPT_PATTERN.search(source): |
+ result.append(self.CreateSelfScript()) |
result += [framework, self.file] |
return result |
def GetSource(self): |
return open(self.file).read() |
+ def CreateSelfScript(self): |
+ (fd_self_script, self_script) = tempfile.mkstemp(suffix=".js") |
+ def MakeJsConst(name, value): |
+ return "var %(name)s=\'%(value)s\';\n" % \ |
+ {'name': name, \ |
+ 'value': value.replace('\\', '\\\\').replace('\'', '\\\'') } |
+ try: |
+ os.write(fd_self_script, MakeJsConst('TEST_FILE_NAME', self.file)) |
+ except IOError, e: |
+ test.PrintError("write() " + str(e)) |
+ os.close(fd_self_script) |
+ self.self_script = self_script |
+ return self_script |
+ |
+ def Cleanup(self): |
+ if self.self_script: |
+ test.CheckedUnlink(self.self_script) |
class MjsunitTestConfiguration(test.TestConfiguration): |