OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 from dart_generator import DartGenerator | |
7 import os | |
8 import unittest | |
9 import glob | |
10 | |
11 class DartTest(unittest.TestCase): | |
12 | |
13 def _RunTest(self, | |
14 test_filename, | |
15 tests_dir='./dart_test/', | |
16 diff_flags=['--ignore-blank-lines', '--unified', | |
17 '--ignore-tab-expansion']): | |
18 '''Given the name of a test, runs compiler.py on the file: | |
19 <test_dir>/test_filename.idl | |
20 and compares it to the output in the file: | |
21 <test_dir>/test_filename.dart | |
22 | |
23 The default |test_dir| location can be overwritten by passing in the new | |
24 location. | |
25 Similarly, you can override the default |diff_flags| by passing a list of | |
26 them into the function. | |
27 ''' | |
28 cmd = ' | '.join(self.commands) % { | |
29 'expected_output_file': os.path.join(tests_dir, | |
30 '%s.dart' % test_filename), | |
31 'input_dir': tests_dir, | |
32 'input_file': os.path.join(tests_dir, '%s.idl' % test_filename), | |
33 'diff_flags': ' '.join(diff_flags) | |
34 } | |
35 self.assertEquals(0, os.system(cmd)) | |
36 | |
37 def setUp(self): | |
38 # Instead of outputting to a file and creating lots of temporary files, | |
39 # run the compiler and output to stdout, then pipe this straight into diff. | |
40 # This avoids creating temporary files we have to clean up later. | |
41 # Also remove the first line of output, since it contains the input | |
42 # filename. | |
43 self.commands = [ | |
44 'python compiler.py -g dart -r %(input_dir)s %(input_file)s', | |
45 'tail -n +2', | |
46 'diff %(diff_flags)s %(expected_output_file)s -'] | |
not at google - send to devlin
2013/02/20 00:43:01
I don't think we can assume that these will work -
sashab
2013/02/20 02:54:23
Done.
| |
47 | |
48 def testBasicEvent(self): | |
49 self._RunTest('basic_event') | |
50 | |
51 def testBasicFunction(self): | |
52 self._RunTest('basic_function') | |
53 | |
54 def testBasicType(self): | |
55 self._RunTest('basic_type') | |
56 | |
57 def testComments(self): | |
58 self._RunTest('comments') | |
59 | |
60 def testComplexType(self): | |
61 self._RunTest('complex_type') | |
62 | |
63 def testEmptyNamespace(self): | |
64 self._RunTest('empty_namespace') | |
65 | |
66 def testEmptyType(self): | |
67 self._RunTest('empty_type') | |
68 | |
69 def testOpratableType(self): | |
70 self._RunTest('operatable_type') | |
71 | |
72 def testTags(self): | |
73 self._RunTest('tags') | |
74 | |
75 if __name__ == '__main__': | |
76 unittest.main() | |
OLD | NEW |