Home | History | Annotate | Download | only in bin
      1 #!/usr/bin/env python
      2 # Copyright (c) 2015 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 import argparse
      6 import os
      7 import sys
      8 import unittest
      9 
     10 
     11 def _IterateTestCase(test):
     12   if isinstance(test, unittest.TestCase):
     13     yield test
     14   else:
     15     for t in test:
     16       for u in _IterateTestCase(t):
     17         yield u
     18 
     19 
     20 def main(args):
     21   parser = argparse.ArgumentParser(description='Run all vinn tests')
     22   parser.add_argument('test_name', type=str, nargs='?',
     23                       help=('Specify a specific test to run. If this is empty, '
     24                             'all tests are run. (the name can be a substring '
     25                             ' of test names)'))
     26   options = parser.parse_args(args)
     27   def _IsTestMatched(test):
     28     if not options.test_name:
     29       return True
     30     return options.test_name in test.id()
     31 
     32   suite = unittest.TestSuite()
     33   vinn_dir = os.path.join(os.path.abspath(__file__), '..', '..')
     34   discover_tests = unittest.TestLoader().discover(
     35     start_dir=vinn_dir, pattern='*test.py')
     36   for t in _IterateTestCase(discover_tests):
     37     if _IsTestMatched(t):
     38       suite.addTest(t)
     39   results = unittest.TextTestRunner(verbosity=2).run(suite)
     40   return len(results.failures)
     41 
     42 
     43 if __name__ == '__main__':
     44   sys.exit(main(sys.argv[1:]))
     45