OLD | NEW |
---|---|
(Empty) | |
1 # Copyright 2016 the V8 project authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 import itertools | |
6 import os | |
7 import re | |
8 | |
9 from testrunner.local import testsuite | |
10 from testrunner.local import utils | |
11 from testrunner.objects import testcase | |
12 | |
13 FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)") | |
14 PROTOCOL_TEST_JS = "protocol-test.js" | |
15 | |
16 class InspectorProtocolTestSuite(testsuite.TestSuite): | |
17 | |
18 def __init__(self, name, root): | |
19 super(InspectorProtocolTestSuite, self).__init__(name, root) | |
20 | |
21 def ListTests(self, context): | |
22 tests = [] | |
23 for dirname, dirs, files in os.walk(os.path.join(self.root), followlinks=Tru e): | |
24 for dotted in [x for x in dirs if x.startswith('.')]: | |
25 dirs.remove(dotted) | |
26 dirs.sort() | |
27 files.sort() | |
28 for filename in files: | |
29 if filename.endswith(".js") and filename != PROTOCOL_TEST_JS: | |
30 fullpath = os.path.join(dirname, filename) | |
31 relpath = fullpath[len(self.root) + 1 : -3] | |
32 testname = relpath.replace(os.path.sep, "/") | |
33 test = testcase.TestCase(self, testname) | |
34 tests.append(test) | |
35 return tests | |
36 | |
37 def GetFlagsForTestCase(self, testcase, context): | |
38 source = self.GetSourceForTest(testcase) | |
39 flags_match = re.findall(FLAGS_PATTERN, source) | |
40 flags = [] | |
41 for match in flags_match: | |
42 flags += match.strip().split() | |
43 testname = testcase.path.split(os.path.sep)[-1] | |
44 testfilename = os.path.join(self.root, testcase.path + self.suffix()) | |
45 protocoltestfilename = os.path.join(self.root, "protocol-test.js") | |
dgozman
2016/09/22 17:44:49
PROTOCOL_TEST_JS
| |
46 return [ protocoltestfilename, testfilename ] + flags | |
47 | |
48 def GetSourceForTest(self, testcase): | |
49 filename = os.path.join(self.root, testcase.path + self.suffix()) | |
50 with open(filename) as f: | |
51 return f.read() | |
52 | |
53 def shell(self): | |
54 return "inspector-protocol" | |
55 | |
56 def IsFailureOutput(self, testcase): | |
57 output = testcase.output | |
58 testpath = testcase.path | |
59 expected_path = os.path.join(self.root, testpath + "-expected.txt") | |
60 expected_lines = utils.ReadLinesFrom(expected_path) | |
61 raw_lines = output.stdout.splitlines() | |
62 actual_lines = [ s.strip() for s in raw_lines if s.strip() ] | |
63 | |
64 for (expected, actual) in itertools.izip_longest( | |
65 expected_lines, actual_lines, fillvalue=''): | |
66 if expected != actual: | |
67 print [ expected, actual ] | |
68 return True | |
69 if len(expected_lines) != len(actual_lines): | |
70 print "-----" | |
71 print "\n".join(raw_lines) | |
72 print "-----" | |
73 return True | |
74 return False | |
75 | |
76 def GetSuite(name, root): | |
77 return InspectorProtocolTestSuite(name, root) | |
OLD | NEW |