#!/usr/bin/env python3
# Copyright 2017 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import logging
import os
import sys
import unittest
if __name__ == '__main__':
logging.basicConfig(
level=logging.DEBUG if '-v' in sys.argv else logging.WARNING,
format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s')
suite = unittest.TestSuite()
loader = unittest.TestLoader()
root_dir = os.path.dirname(os.path.realpath(__file__))
if len(sys.argv) < 2:
cases = loader.discover(start_dir=root_dir, pattern='*_unittest.py')
else:
cases = []
for module in sys.argv[1:]:
pattern = '{}_unittest.py'.format(module)
cases.extend(loader.discover(start_dir=root_dir, pattern=pattern))
suite.addTests(cases)
res = unittest.TextTestRunner(verbosity=2).run(suite)
if res.wasSuccessful():
sys.exit(0)
else:
sys.exit(1)