OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2016 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 """Runs Dart example tests""" |
| 7 |
| 8 # This script runs tests of example Dart Mojo apps. |
| 9 # It looks for files named *_test.dart under subdirectories of |
| 10 # //examples/dart in the EXAMPLES list, below. These tests are |
| 11 # passed a command line argument --mojo-shell /path/to/mojo_shell that they |
| 12 # can use to run the example. |
| 13 |
| 14 import argparse |
| 15 import os |
| 16 import subprocess |
| 17 import sys |
| 18 |
| 19 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 20 SRC_DIR = os.path.dirname(os.path.dirname(SCRIPT_DIR)) |
| 21 |
| 22 DART_SDK = os.path.join(SRC_DIR, 'third_party', 'dart-sdk', 'dart-sdk', 'bin') |
| 23 DART = os.path.join(DART_SDK, 'dart') |
| 24 |
| 25 # Add subdirectories of //examples/dart here. |
| 26 EXAMPLES = ['hello_world', 'wget'] |
| 27 |
| 28 def FindTests(example): |
| 29 tests = [] |
| 30 for root, _, files in os.walk(os.path.join(SCRIPT_DIR, example)): |
| 31 for f in files: |
| 32 if f.endswith('_test.dart'): |
| 33 tests.append(os.path.join(root, f)) |
| 34 return tests |
| 35 |
| 36 def RunTests(tests, build_dir, package_root): |
| 37 for test in tests: |
| 38 test_path = os.path.join(SCRIPT_DIR, test) |
| 39 subprocess.check_call( |
| 40 [DART, '-p', package_root, '--checked', test_path, |
| 41 '--mojo-shell', os.path.join(build_dir, 'mojo_shell'),]) |
| 42 |
| 43 def main(build_dir, package_root): |
| 44 for example in EXAMPLES: |
| 45 tests = FindTests(example) |
| 46 RunTests(tests, build_dir, package_root) |
| 47 |
| 48 if __name__ == '__main__': |
| 49 parser = argparse.ArgumentParser(description="Run Dart example tests") |
| 50 parser.add_argument('-b', '--build-dir', |
| 51 dest='build_dir', |
| 52 metavar='<build-directory>', |
| 53 type=str, |
| 54 required=True, |
| 55 help='The build output directory. E.g. out/Debug') |
| 56 args = parser.parse_args() |
| 57 package_root = os.path.join( |
| 58 SRC_DIR, args.build_dir, 'gen', 'dart-pkg', 'packages') |
| 59 sys.exit(main(args.build_dir, package_root)) |
OLD | NEW |