brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · 0c49991 Raw
63 lines · python
1# DExTer : Debugging Experience Tester2# ~~~~~~   ~         ~~         ~   ~~3#4# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5# See https://llvm.org/LICENSE.txt for license information.6# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7"""Unit test harness."""8 9from fnmatch import fnmatch10import os11import unittest12 13from io import StringIO14 15from dex.utils import is_native_windows, has_pywin3216from dex.utils import PreserveAutoColors, PrettyOutput17from dex.utils import Timer18 19 20class DexTestLoader(unittest.TestLoader):21    def _match_path(self, path, full_path, pattern):22        """Don't try to import platform-specific modules for the wrong platform23        during test discovery.24        """25        d = os.path.basename(os.path.dirname(full_path))26        if is_native_windows():27            if d == "posix":28                return False29            if d == "windows":30                return has_pywin32()31        else:32            if d == "windows":33                return False34            elif d == "dbgeng":35                return False36        return fnmatch(path, pattern)37 38 39def unit_tests_ok(context):40    unittest.TestCase.maxDiff = None  # remove size limit from diff output.41 42    with Timer("unit tests"):43        suite = DexTestLoader().discover(context.root_directory, pattern="*.py")44        stream = StringIO()45        result = unittest.TextTestRunner(verbosity=2, stream=stream).run(suite)46 47        ok = result.wasSuccessful()48        if not ok or context.options.unittest == "show-all":49            with PreserveAutoColors(context.o):50                context.o.auto_reds.extend([r"FAIL(ED|\:)", r"\.\.\.\s(FAIL|ERROR)$"])51                context.o.auto_greens.extend([r"^OK$", r"\.\.\.\sok$"])52                context.o.auto_blues.extend([r"^Ran \d+ test"])53                context.o.default("\n")54                for line in stream.getvalue().splitlines(True):55                    context.o.auto(line, stream=PrettyOutput.stderr)56 57        return ok58 59 60class TestUnitTests(unittest.TestCase):61    def test_sanity(self):62        self.assertEqual(1, 1)63