| 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 import os | |
| 7 import sys | |
| 8 import unittest | |
| 9 import glob | |
| 10 | |
| 11 from dart_generator import DartGenerator | |
| 12 from compiler import GenerateSchema | |
| 13 | |
| 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 | |
| 16 # themselves). | |
| 17 REBASE_MODE = False | |
| 18 | |
| 19 # The directory containing the input and expected output files corresponding | |
| 20 # to each test name. | |
| 21 TESTS_DIR = 'dart_test' | |
| 22 | |
| 23 class DartTest(unittest.TestCase): | |
| 24 | |
| 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 | |
| 30 ''' | |
| 31 file_rel = os.path.join(TESTS_DIR, test_filename) | |
| 32 | |
| 33 output_dir = None | |
| 34 if REBASE_MODE: | |
| 35 output_dir = TESTS_DIR | |
| 36 output_code = GenerateSchema('dart', ['%s.idl' % file_rel], TESTS_DIR, | |
| 37 output_dir, None, None) | |
| 38 | |
| 39 if not REBASE_MODE: | |
| 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]) | |
| 48 | |
| 49 def setUp(self): | |
| 50 # Increase the maximum diff amount to see the full diff on a failed test. | |
| 51 self.maxDiff = 2000 | |
| 52 | |
| 53 def testBasicEvent(self): | |
| 54 self._RunTest('basic_event') | |
| 55 | |
| 56 def testBasicFunction(self): | |
| 57 self._RunTest('basic_function') | |
| 58 | |
| 59 def testBasicType(self): | |
| 60 self._RunTest('basic_type') | |
| 61 | |
| 62 def testComments(self): | |
| 63 self._RunTest('comments') | |
| 64 | |
| 65 def testComplexType(self): | |
| 66 self._RunTest('complex_type') | |
| 67 | |
| 68 def testEmptyNamespace(self): | |
| 69 self._RunTest('empty_namespace') | |
| 70 | |
| 71 def testEmptyType(self): | |
| 72 self._RunTest('empty_type') | |
| 73 | |
| 74 def testOpratableType(self): | |
| 75 self._RunTest('operatable_type') | |
| 76 | |
| 77 def testTags(self): | |
| 78 self._RunTest('tags') | |
| 79 | |
| 80 if __name__ == '__main__': | |
| 81 if '--rebase' in sys.argv: | |
| 82 print "Running in rebase mode." | |
| 83 REBASE_MODE = True | |
| 84 sys.argv.remove('--rebase') | |
| 85 unittest.main() | |
| OLD | NEW |