Chromium Code Reviews| Index: tools/json_schema_compiler/dart_generator_test.py |
| diff --git a/tools/json_schema_compiler/dart_generator_test.py b/tools/json_schema_compiler/dart_generator_test.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..d334bab6fa3432c6d3809fb3efc156fd0cbb0628 |
| --- /dev/null |
| +++ b/tools/json_schema_compiler/dart_generator_test.py |
| @@ -0,0 +1,76 @@ |
| +#!/usr/bin/env python |
| +# Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +from dart_generator import DartGenerator |
| +import os |
| +import unittest |
| +import glob |
| + |
| +class DartTest(unittest.TestCase): |
| + |
| + def _RunTest(self, |
| + test_filename, |
| + tests_dir='./dart_test/', |
| + diff_flags=['--ignore-blank-lines', '--unified', |
| + '--ignore-tab-expansion']): |
| + '''Given the name of a test, runs compiler.py on the file: |
| + <test_dir>/test_filename.idl |
| + and compares it to the output in the file: |
| + <test_dir>/test_filename.dart |
| + |
| + The default |test_dir| location can be overwritten by passing in the new |
| + location. |
| + Similarly, you can override the default |diff_flags| by passing a list of |
| + them into the function. |
| + ''' |
| + cmd = ' | '.join(self.commands) % { |
| + 'expected_output_file': os.path.join(tests_dir, |
| + '%s.dart' % test_filename), |
| + 'input_dir': tests_dir, |
| + 'input_file': os.path.join(tests_dir, '%s.idl' % test_filename), |
| + 'diff_flags': ' '.join(diff_flags) |
| + } |
| + self.assertEquals(0, os.system(cmd)) |
| + |
| + def setUp(self): |
| + # Instead of outputting to a file and creating lots of temporary files, |
| + # run the compiler and output to stdout, then pipe this straight into diff. |
| + # This avoids creating temporary files we have to clean up later. |
| + # Also remove the first line of output, since it contains the input |
| + # filename. |
| + self.commands = [ |
| + 'python compiler.py -g dart -r %(input_dir)s %(input_file)s', |
| + 'tail -n +2', |
| + '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.
|
| + |
| + def testBasicEvent(self): |
| + self._RunTest('basic_event') |
| + |
| + def testBasicFunction(self): |
| + self._RunTest('basic_function') |
| + |
| + def testBasicType(self): |
| + self._RunTest('basic_type') |
| + |
| + def testComments(self): |
| + self._RunTest('comments') |
| + |
| + def testComplexType(self): |
| + self._RunTest('complex_type') |
| + |
| + def testEmptyNamespace(self): |
| + self._RunTest('empty_namespace') |
| + |
| + def testEmptyType(self): |
| + self._RunTest('empty_type') |
| + |
| + def testOpratableType(self): |
| + self._RunTest('operatable_type') |
| + |
| + def testTags(self): |
| + self._RunTest('tags') |
| + |
| +if __name__ == '__main__': |
| + unittest.main() |