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.
10 from compiler import GenerateSchema
12 # If --rebase is passed to this test, this is set to True, indicating the test
13 # output should be re-generated for each test (rather than running the tests
17 # The directory containing the input and expected output files corresponding
19 TESTS_DIR = 'dart_test'
21 class DartTest(unittest.TestCase):
23 def _RunTest(self, test_filename):
24 '''Given the name of a test, runs compiler.py on the file:
25 TESTS_DIR/test_filename.idl
26 and compares it to the output in the file:
27 TESTS_DIR/test_filename.dart
29 file_rel = os.path.join(TESTS_DIR, test_filename)
33 output_dir = TESTS_DIR
34 output_code = GenerateSchema('dart', ['%s.idl' % file_rel], TESTS_DIR,
35 output_dir, '', None, None, [])
38 with open('%s.dart' % file_rel) as f:
39 expected_output = f.read()
40 # Remove the first line of the output code (as it contains the filename).
41 # Also remove all blank lines, ignoring them from the comparison.
42 # Compare with lists instead of strings for clearer diffs (especially with
43 # whitespace) when a test fails.
44 self.assertEqual([l for l in expected_output.split('\n') if l],
45 [l for l in output_code.split('\n')[1:] if l])
48 # Increase the maximum diff amount to see the full diff on a failed test.
51 def testComments(self):
52 self._RunTest('comments')
54 def testDictionaries(self):
55 self._RunTest('dictionaries')
57 def testEmptyNamespace(self):
58 self._RunTest('empty_namespace')
60 def testEmptyType(self):
61 self._RunTest('empty_type')
64 self._RunTest('events')
66 def testBasicFunction(self):
67 self._RunTest('functions')
69 def testOpratableType(self):
70 self._RunTest('operatable_type')
76 if __name__ == '__main__':
77 if '--rebase' in sys.argv:
78 print "Running in rebase mode."
80 sys.argv.remove('--rebase')