Index: test/mjsunit/testcfg.py |
diff --git a/test/mjsunit/testcfg.py b/test/mjsunit/testcfg.py |
index 7c6311b1a722e58f1ac6ccaf184d73b50a83e823..7c40a4cc73e6188d3b92eea7817b04020e4a358b 100644 |
--- a/test/mjsunit/testcfg.py |
+++ b/test/mjsunit/testcfg.py |
@@ -33,7 +33,9 @@ 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") |
+ENV_VARS_PATTERN = re.compile(r"//\s+Env:(.*)") |
+SELF_SCRIPT_PATTERN = re.compile("TEST_FILE_NAME") |
+LOG_FILE_PATTERN = re.compile("LOG_FILE_NAME") |
class MjsunitTestCase(test.TestCase): |
@@ -43,6 +45,7 @@ class MjsunitTestCase(test.TestCase): |
self.file = file |
self.config = config |
self.self_script = False |
+ self.log_file = False |
self.isolates = isolates |
def GetLabel(self): |
@@ -61,6 +64,23 @@ class MjsunitTestCase(test.TestCase): |
result += flags_match.group(1).strip().split() |
return result |
+ def GetEnvArguments(self, source): |
+ result = [] |
+ env_vars_match = ENV_VARS_PATTERN.search(source) |
+ if env_vars_match: |
+ env_vars = env_vars_match.group(1) |
+ provide_test_file_name = SELF_SCRIPT_PATTERN.search(env_vars) |
+ provide_log_file_name = LOG_FILE_PATTERN.search(env_vars) |
+ else: |
+ return result |
+ if provide_test_file_name or provide_log_file_name: |
+ self_script_file = self.CreateSelfScript( |
+ provide_test_file_name, provide_log_file_name) |
+ if self.log_file: |
+ result.append("--logfile=" + self.log_file) |
+ result.append(self_script_file) |
+ return result |
+ |
def GetVmArguments(self, source): |
result = [] |
additional_files = [] |
@@ -75,14 +95,13 @@ class MjsunitTestCase(test.TestCase): |
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 GetCommand(self): |
source = open(self.file).read() |
result = self.GetVmCommand(source) |
+ result += self.GetEnvArguments(source) |
result += self.GetVmArguments(source) |
if self.isolates: |
result.append("--isolate") |
@@ -92,14 +111,21 @@ class MjsunitTestCase(test.TestCase): |
def GetSource(self): |
return open(self.file).read() |
- def CreateSelfScript(self): |
+ def CreateSelfScript(self, provide_test_file_name, provide_log_file_name): |
(fd_self_script, self_script) = tempfile.mkstemp(suffix=".js") |
+ if provide_log_file_name: |
+ (fd_log_file, log_file) = tempfile.mkstemp(suffix=".log") |
+ os.close(fd_log_file) |
+ self.log_file = log_file |
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)) |
+ if provide_test_file_name: |
+ os.write(fd_self_script, MakeJsConst('TEST_FILE_NAME', self.file)) |
+ if provide_log_file_name: |
+ os.write(fd_self_script, MakeJsConst('LOG_FILE_NAME', log_file)) |
except IOError, e: |
test.PrintError("write() " + str(e)) |
os.close(fd_self_script) |
@@ -107,8 +133,11 @@ class MjsunitTestCase(test.TestCase): |
return self_script |
def AfterRun(self, result): |
- if self.self_script and (not result or (not result.HasPreciousOutput())): |
- test.CheckedUnlink(self.self_script) |
+ if not result or (not result.HasPreciousOutput()): |
+ if self.self_script: |
+ test.CheckedUnlink(self.self_script) |
+ if self.log_file: |
+ test.CheckedUnlink(self.log_file) |
class MjsunitTestConfiguration(test.TestConfiguration): |