|
25 | 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 | 26 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
|
28 | | -import test |
| 28 | +import itertools |
29 | 29 | import os |
30 | | -from os.path import join, dirname, exists, basename, isdir |
31 | 30 | import re |
32 | 31 |
|
| 32 | +from testrunner.local import testsuite |
| 33 | +from testrunner.local import utils |
| 34 | +from testrunner.objects import testcase |
| 35 | + |
| 36 | + |
33 | 37 | FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)") |
34 | 38 |
|
| 39 | + |
| 40 | +class MessageTestSuite(testsuite.TestSuite): |
| 41 | + def __init__(self, name, root): |
| 42 | + super(MessageTestSuite, self).__init__(name, root) |
| 43 | + |
| 44 | + def ListTests(self, context): |
| 45 | + tests = [] |
| 46 | + for dirname, dirs, files in os.walk(self.root): |
| 47 | + for dotted in [x for x in dirs if x.startswith('.')]: |
| 48 | + dirs.remove(dotted) |
| 49 | + dirs.sort() |
| 50 | + files.sort() |
| 51 | + for filename in files: |
| 52 | + if filename.endswith(".js"): |
| 53 | + testname = join(dirname[len(self.root) + 1:], filename[:-3]) |
| 54 | + test = testcase.TestCase(self, testname) |
| 55 | + tests.append(test) |
| 56 | + return tests |
| 57 | + |
| 58 | + def GetFlagsForTestCase(self, testcase, context): |
| 59 | + source = self.GetSourceForTest(testcase) |
| 60 | + result = [] |
| 61 | + flags_match = re.findall(FLAGS_PATTERN, source) |
| 62 | + for match in flags_match: |
| 63 | + result += match.strip().split() |
| 64 | + result += context.mode_flags |
| 65 | + result.append(os.path.join(self.root, testcase.path + ".js")) |
| 66 | + return testcase.flags + result |
| 67 | + |
| 68 | + def GetSourceForTest(self, testcase): |
| 69 | + filename = os.path.join(self.root, testcase.path + self.suffix()) |
| 70 | + with open(filename) as f: |
| 71 | + return f.read() |
| 72 | + |
| 73 | + def _IgnoreLine(self, string): |
| 74 | + """Ignore empty lines, valgrind output and Android output.""" |
| 75 | + if not string: return True |
| 76 | + return (string.startswith("==") or string.startswith("**") or |
| 77 | + string.startswith("ANDROID")) |
| 78 | + |
| 79 | + def IsFailureOutput(self, output, testpath): |
| 80 | + expected_path = os.path.join(self.root, testpath + ".out") |
| 81 | + expected_lines = [] |
| 82 | + # Can't use utils.ReadLinesFrom() here because it strips whitespace. |
| 83 | + with open(expected_path) as f: |
| 84 | + for line in f: |
| 85 | + if line.startswith("#") or not line.strip(): continue |
| 86 | + expected_lines.append(line) |
| 87 | + raw_lines = output.stdout.splitlines() |
| 88 | + actual_lines = [ s for s in raw_lines if not self._IgnoreLine(s) ] |
| 89 | + env = { "basename": os.path.basename(testpath + ".js") } |
| 90 | + if len(expected_lines) != len(actual_lines): |
| 91 | + return True |
| 92 | + for (expected, actual) in itertools.izip(expected_lines, actual_lines): |
| 93 | + pattern = re.escape(expected.rstrip() % env) |
| 94 | + pattern = pattern.replace("\\*", ".*") |
| 95 | + pattern = "^%s$" % pattern |
| 96 | + if not re.match(pattern, actual): |
| 97 | + return True |
| 98 | + return False |
| 99 | + |
| 100 | + def StripOutputForTransmit(self, testcase): |
| 101 | + pass |
| 102 | + |
| 103 | + |
| 104 | +def GetSuite(name, root): |
| 105 | + return MessageTestSuite(name, root) |
| 106 | + |
| 107 | + |
| 108 | +# Deprecated definitions below. |
| 109 | +# TODO(jkummerow): Remove when SCons is no longer supported. |
| 110 | + |
| 111 | + |
| 112 | +import test |
| 113 | +from os.path import join, exists, basename, isdir |
| 114 | + |
35 | 115 | class MessageTestCase(test.TestCase): |
36 | 116 |
|
37 | 117 | def __init__(self, path, file, expected, mode, context, config): |
|
0 commit comments