OLD | NEW |
| (Empty) |
1 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
2 # for details. All rights reserved. Use of this source code is governed by a | |
3 # BSD-style license that can be found in the LICENSE file. | |
4 | |
5 | |
6 import os | |
7 from os.path import join, exists | |
8 import re | |
9 | |
10 import test | |
11 import utils | |
12 | |
13 | |
14 class Error(Exception): | |
15 pass | |
16 | |
17 | |
18 class Co19TestCase(test.TestCase): | |
19 def __init__(self, path, context, filename, mode, arch, component): | |
20 super(Co19TestCase, self).__init__(context, path) | |
21 self.filename = filename | |
22 self.mode = mode | |
23 self.arch = arch | |
24 self.component = component | |
25 self._is_negative = None | |
26 | |
27 def IsNegative(self): | |
28 if self._is_negative is None : | |
29 contents = self.GetSource() | |
30 if '@compile-error' in contents or '@runtime-error' in contents: | |
31 self._is_negative = True | |
32 else: | |
33 self._is_negative = False | |
34 return self._is_negative | |
35 | |
36 def GetLabel(self): | |
37 return "%s%s %s %s" % (self.mode, self.arch, self.component, | |
38 "/".join(self.path)) | |
39 | |
40 def GetCommand(self): | |
41 # Parse the options by reading the .dart source file. | |
42 source = self.GetSource() | |
43 vm_options = utils.ParseTestOptions(test.VM_OPTIONS_PATTERN, source, | |
44 self.context.workspace) | |
45 dart_options = utils.ParseTestOptions(test.DART_OPTIONS_PATTERN, source, | |
46 self.context.workspace) | |
47 | |
48 # Combine everything into a command array and return it. | |
49 command = self.context.GetDart(self.mode, self.arch, self.component) | |
50 command += self.context.flags | |
51 if self.mode == 'release': command += ['--optimize'] | |
52 if vm_options: command += vm_options | |
53 if dart_options: command += dart_options | |
54 else: | |
55 command += [self.filename] | |
56 return command | |
57 | |
58 def GetName(self): | |
59 return self.path[-1] | |
60 | |
61 def GetPath(self): | |
62 return os.path.dirname(self.filename) | |
63 | |
64 def GetSource(self): | |
65 return file(self.filename).read() | |
66 | |
67 | |
68 class Co19TestConfiguration(test.TestConfiguration): | |
69 def __init__(self, context, root): | |
70 super(Co19TestConfiguration, self).__init__(context, root) | |
71 | |
72 def ListTests(self, current_path, path, mode, arch, component): | |
73 tests = [] | |
74 src_dir = join(self.root, "src") | |
75 strip = len(src_dir.split(os.path.sep)) | |
76 for root, dirs, files in os.walk(src_dir): | |
77 ignore_dirs = [d for d in dirs if d.startswith('.')] | |
78 for d in ignore_dirs: | |
79 dirs.remove(d) | |
80 for f in [x for x in files if self.IsTest(x)]: | |
81 test_path = [] + current_path | |
82 test_path.extend(root.split(os.path.sep)[strip:]) | |
83 test_name = short_name = f | |
84 | |
85 # remove suffixes | |
86 if short_name.endswith(".dart"): | |
87 short_name = short_name[:-5] # Remove .dart suffix. | |
88 else: | |
89 raise Error('Unknown suffix in "%s", fix IsTest() predicate' % f) | |
90 | |
91 test_path.append(short_name) | |
92 | |
93 # test full name and shorted name matches given path pattern | |
94 if self.Contains(path, test_path): pass | |
95 elif self.Contains(path, test_path + [test_name]): pass | |
96 else: | |
97 continue | |
98 | |
99 tests.append(Co19TestCase(test_path, | |
100 self.context, | |
101 join(root, f), | |
102 mode, | |
103 arch, | |
104 component)) | |
105 return tests | |
106 | |
107 _TESTNAME_PATTERN = re.compile(r'.*_t[0-9]{2}\.dart$') | |
108 def IsTest(self, name): | |
109 return self._TESTNAME_PATTERN.match(name) | |
110 | |
111 def GetTestStatus(self, sections, defs): | |
112 status = join(self.root, "co19-runtime.status") | |
113 if exists(status): | |
114 test.ReadConfigurationInto(status, sections, defs) | |
115 status = join(self.root, "co19-compiler.status") | |
116 if exists(status): | |
117 test.ReadConfigurationInto(status, sections, defs) | |
118 status = join(self.root, "co19-frog.status") | |
119 if exists(status): | |
120 test.ReadConfigurationInto(status, sections, defs) | |
121 status = join(self.root, "co19-leg.status") | |
122 if exists(status): | |
123 test.ReadConfigurationInto(status, sections, defs) | |
124 | |
125 def Contains(self, path, file): | |
126 """ reimplemented for support '**' glob pattern """ | |
127 if len(path) > len(file): | |
128 return | |
129 # ** matches to any number of directories, a/**/d matches a/b/c/d | |
130 # paths like a/**/x/**/b not allowed | |
131 patterns = [p.pattern for p in path] | |
132 if '**' in patterns: | |
133 idx = patterns.index('**') | |
134 patterns[idx : idx] = ['*'] * (len(file) - len(path)) | |
135 path = [test.Pattern(p) for p in patterns] | |
136 | |
137 for i in xrange(len(path)): | |
138 if not path[i].match(file[i]): | |
139 return False | |
140 return True | |
141 | |
142 def GetConfiguration(context, root): | |
143 return Co19TestConfiguration(context, root) | |
OLD | NEW |