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.
11 from dart_generator
import DartGenerator
12 from compiler
import GenerateSchema
14 # If --rebase is passed to this test, this is set to True, indicating the test
15 # output should be re-generated for each test (rather than running the tests
19 # The directory containing the input and expected output files corresponding
21 TESTS_DIR
= 'dart_test'
23 class DartTest(unittest
.TestCase
):
25 def _RunTest(self
, test_filename
):
26 '''Given the name of a test, runs compiler.py on the file:
27 TESTS_DIR/test_filename.idl
28 and compares it to the output in the file:
29 TESTS_DIR/test_filename.dart
31 file_rel
= os
.path
.join(TESTS_DIR
, test_filename
)
35 output_dir
= TESTS_DIR
36 output_code
= GenerateSchema('dart', ['%s.idl' % file_rel
], TESTS_DIR
,
37 output_dir
, None, None)
40 with
open('%s.dart' % file_rel
) as f
:
41 expected_output
= f
.read()
42 # Remove the first line of the output code (as it contains the filename).
43 # Also remove all blank lines, ignoring them from the comparison.
44 # Compare with lists instead of strings for clearer diffs (especially with
45 # whitespace) when a test fails.
46 self
.assertEqual([l
for l
in expected_output
.split('\n') if l
],
47 [l
for l
in output_code
.split('\n')[1:] if l
])
50 # Increase the maximum diff amount to see the full diff on a failed test.
53 def testComments(self
):
54 self
._RunTest
('comments')
56 def testDictionaries(self
):
57 self
._RunTest
('dictionaries')
59 def testEmptyNamespace(self
):
60 self
._RunTest
('empty_namespace')
62 def testEmptyType(self
):
63 self
._RunTest
('empty_type')
66 self
._RunTest
('enums')
69 self
._RunTest
('events')
71 def testBasicFunction(self
):
72 self
._RunTest
('functions')
74 def testOpratableType(self
):
75 self
._RunTest
('operatable_type')
80 if __name__
== '__main__':
81 if '--rebase' in sys
.argv
:
82 print "Running in rebase mode."
84 sys
.argv
.remove('--rebase')