Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Side by Side Diff: tests/stub-generator/testcfg.py

Issue 8361032: Use generated tests if dartc is not available. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 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 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. 3 # BSD-style license that can be found in the LICENSE file.
4 4
5 import os 5 import os
6 import re 6 import re
7 import shutil 7 import shutil
8 import sys 8 import sys
9 import tempfile 9 import tempfile
10 10
11 import test 11 import test
12 from testing import test_case,test_configuration 12 from testing import test_case,test_configuration
13 import utils 13 import utils
14 14
15 from os.path import join, exists, isdir 15 from os.path import join, exists, isdir
16 16
17 def GeneratedName(src):
18 return re.sub('\.dart$', '-generatedTest.dart', src)
19
17 class DartStubTestCase(test_case.StandardTestCase): 20 class DartStubTestCase(test_case.StandardTestCase):
18 def __init__(self, context, path, filename, mode, arch): 21 def __init__(self, context, path, filename, mode, arch):
19 super(DartStubTestCase, self).__init__(context, path, filename, mode, arch) 22 super(DartStubTestCase, self).__init__(context, path, filename, mode, arch)
20 self.filename = filename 23 self.filename = filename
21 self.mode = mode 24 self.mode = mode
22 self.arch = arch 25 self.arch = arch
23 26
24 def IsBatchable(self): 27 def IsBatchable(self):
25 return False 28 return False
26 29
27 def GetStubs(self): 30 def GetStubs(self):
28 source = self.GetSource() 31 source = self.GetSource()
29 stub_classes = utils.ParseTestOptions(test.ISOLATE_STUB_PATTERN, source, 32 stub_classes = utils.ParseTestOptions(test.ISOLATE_STUB_PATTERN, source,
30 self.context.workspace) 33 self.context.workspace)
31 (interface, _, classes) = stub_classes[0].partition(':') 34 (interface, _, classes) = stub_classes[0].partition(':')
32 (interface, _, implementation) = interface.partition('+') 35 (interface, _, implementation) = interface.partition('+')
33 return (interface, classes, implementation) 36 return (interface, classes, implementation)
34 37
35 def IsFailureOutput(self, output): 38 def IsFailureOutput(self, output):
36 return output.exit_code != 0 or not '##DONE##' in output.stdout 39 return output.exit_code != 0 or not '##DONE##' in output.stdout
37 40
38 def BeforeRun(self): 41 def BeforeRun(self):
42 if not self.context.generate:
43 return
39 command = self.context.GetDartC(self.mode, 'dartc') 44 command = self.context.GetDartC(self.mode, 'dartc')
40 (interface, classes, _) = self.GetStubs() 45 (interface, classes, _) = self.GetStubs()
41 d = join(self.GetPath(), 'generated') 46 d = join(self.GetPath(), 'generated')
42 if not isdir(d): 47 if not isdir(d):
43 os.mkdir(d) 48 os.mkdir(d)
44 tmpdir = tempfile.mkdtemp() 49 tmpdir = tempfile.mkdtemp()
45 src = join(self.GetPath(), interface) 50 src = join(self.GetPath(), interface)
46 dest = join(self.GetPath(), 'generated', interface) 51 dest = join(self.GetPath(), GeneratedName(interface))
47 self.RunCommand(command + [ src, 52 self.RunCommand(command + [ src,
48 # dartc generates output even if it has no 53 # dartc generates output even if it has no
49 # output to generate. 54 # output to generate.
50 '-out', tmpdir, 55 '-out', tmpdir,
51 '-isolate-stub-out', dest, 56 '-isolate-stub-out', dest,
52 '-generate-isolate-stubs', classes ]) 57 '-generate-isolate-stubs', classes ])
53 shutil.rmtree(tmpdir) 58 shutil.rmtree(tmpdir)
54 d = open(dest, 'a') 59 d = open(dest, 'a')
55 s = open(src, 'r') 60 s = open(src, 'r')
56 d.write(s.read()) 61 d.write(s.read())
57 62
58 def GetCommand(self): 63 def GetCommand(self):
59 # Parse the options by reading the .dart source file. 64 # Parse the options by reading the .dart source file.
60 source = self.GetSource() 65 source = self.GetSource()
61 vm_options = utils.ParseTestOptions(test.VM_OPTIONS_PATTERN, source, 66 vm_options = utils.ParseTestOptions(test.VM_OPTIONS_PATTERN, source,
62 self.context.workspace) 67 self.context.workspace)
63 dart_options = utils.ParseTestOptions(test.DART_OPTIONS_PATTERN, source, 68 dart_options = utils.ParseTestOptions(test.DART_OPTIONS_PATTERN, source,
64 self.context.workspace) 69 self.context.workspace)
65 (interface, _, implementation) = self.GetStubs() 70 (interface, _, implementation) = self.GetStubs()
66 71
67 # Combine everything into a command array and return it. 72 # Combine everything into a command array and return it.
68 command = self.context.GetDart(self.mode, self.arch) 73 command = self.context.GetDart(self.mode, self.arch)
69 files = [ join(self.GetPath(), 'generated', interface) ] 74 files = [ join(self.GetPath(), GeneratedName(interface)) ]
70 if vm_options: command += vm_options 75 if vm_options: command += vm_options
71 if dart_options: command += dart_options 76 if dart_options: command += dart_options
72 else: command += files 77 else: command += files
73 return command 78 return command
74 79
75 80
76 class DartStubTestConfiguration(test_configuration.StandardTestConfiguration): 81 class DartStubTestConfiguration(test_configuration.StandardTestConfiguration):
77 def __init__(self, context, root): 82 def __init__(self, context, root):
78 super(DartStubTestConfiguration, self).__init__(context, root) 83 super(DartStubTestConfiguration, self).__init__(context, root)
79 84
80 def ListTests(self, current_path, path, mode, arch): 85 def ListTests(self, current_path, path, mode, arch):
81 dartc = self.context.GetDartC(mode, 'dartc') 86 dartc = self.context.GetDartC(mode, 'dartc')
82 if not os.access(dartc[0], os.X_OK): 87 self.context.generate = os.access(dartc[0], os.X_OK)
83 print >> sys.stderr, "Can't find dartc at", str(dartc) + ", skipping"
84 return []
85 tests = [] 88 tests = []
86 for root, dirs, files in os.walk(join(self.root, 'src')): 89 for root, dirs, files in os.walk(join(self.root, 'src')):
87 if root.endswith('/generated'):
88 continue
89 for f in [x for x in files if self.IsTest(x)]: 90 for f in [x for x in files if self.IsTest(x)]:
91 if self.context.generate == f.endswith('-generatedTest.dart'):
floitsch 2011/10/21 13:47:39 This needs a comment.
Ben Laurie (Google) 2011/10/21 13:56:58 Done.
92 continue
90 test_path = current_path + [ f[:-5] ] # Remove .dart suffix. 93 test_path = current_path + [ f[:-5] ] # Remove .dart suffix.
91 if not self.Contains(path, test_path): 94 if not self.Contains(path, test_path):
92 continue 95 continue
93 tests.append(DartStubTestCase(self.context, 96 tests.append(DartStubTestCase(self.context,
94 test_path, 97 test_path,
95 join(root, f), 98 join(root, f),
96 mode, 99 mode,
97 arch)) 100 arch))
98 return tests 101 return tests
99 102
100 103
101 def GetConfiguration(context, root): 104 def GetConfiguration(context, root):
102 return DartStubTestConfiguration(context, root) 105 return DartStubTestConfiguration(context, root)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698