brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.6 KiB · 79ff968 Raw
107 lines · python
1# -*- coding: utf-8 -*-2# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3# See https://llvm.org/LICENSE.txt for license information.4# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5 6import libear7import libscanbuild.clang as sut8import unittest9import os.path10import sys11 12 13class ClangGetVersion(unittest.TestCase):14    def test_get_version_is_not_empty(self):15        self.assertTrue(sut.get_version("clang"))16 17    def test_get_version_throws(self):18        with self.assertRaises(OSError):19            sut.get_version("notexists")20 21 22class ClangGetArgumentsTest(unittest.TestCase):23    def test_get_clang_arguments(self):24        with libear.TemporaryDirectory() as tmpdir:25            filename = os.path.join(tmpdir, "test.c")26            with open(filename, "w") as handle:27                handle.write("")28 29            result = sut.get_arguments(30                ["clang", "-c", filename, "-DNDEBUG", '-Dvar="this is it"'], tmpdir31            )32 33            self.assertTrue("NDEBUG" in result)34            self.assertTrue('var="this is it"' in result)35 36    def test_get_clang_arguments_fails(self):37        with self.assertRaises(Exception):38            sut.get_arguments(["clang", "-x", "c", "notexist.c"], ".")39 40    def test_get_clang_arguments_fails_badly(self):41        with self.assertRaises(OSError):42            sut.get_arguments(["notexist"], ".")43 44 45class ClangGetCheckersTest(unittest.TestCase):46    def test_get_checkers(self):47        # this test is only to see is not crashing48        result = sut.get_checkers("clang", [])49        self.assertTrue(len(result))50        # do check result types51        string_type = unicode if sys.version_info < (3,) else str52        for key, value in result.items():53            self.assertEqual(string_type, type(key))54            self.assertEqual(string_type, type(value[0]))55            self.assertEqual(bool, type(value[1]))56 57    def test_get_active_checkers(self):58        # this test is only to see is not crashing59        result = sut.get_active_checkers("clang", [])60        self.assertTrue(len(result))61        # do check result types62        for value in result:63            self.assertEqual(str, type(value))64 65    def test_is_active(self):66        test = sut.is_active(["a", "b.b", "c.c.c"])67 68        self.assertTrue(test("a"))69        self.assertTrue(test("a.b"))70        self.assertTrue(test("b.b"))71        self.assertTrue(test("b.b.c"))72        self.assertTrue(test("c.c.c.p"))73 74        self.assertFalse(test("ab"))75        self.assertFalse(test("ba"))76        self.assertFalse(test("bb"))77        self.assertFalse(test("c.c"))78        self.assertFalse(test("b"))79        self.assertFalse(test("d"))80 81    def test_parse_checkers(self):82        lines = [83            "OVERVIEW: Clang Static Analyzer Checkers List",84            "",85            "CHECKERS:",86            "  checker.one       Checker One description",87            "  checker.two",88            "                    Checker Two description",89        ]90        result = dict(sut.parse_checkers(lines))91        self.assertTrue("checker.one" in result)92        self.assertEqual("Checker One description", result.get("checker.one"))93        self.assertTrue("checker.two" in result)94        self.assertEqual("Checker Two description", result.get("checker.two"))95 96 97class ClangIsCtuCapableTest(unittest.TestCase):98    def test_ctu_not_found(self):99        is_ctu = sut.is_ctu_capable("not-found-clang-extdef-mapping")100        self.assertFalse(is_ctu)101 102 103class ClangGetTripleArchTest(unittest.TestCase):104    def test_arch_is_not_empty(self):105        arch = sut.get_triple_arch(["clang", "-E", "-"], ".")106        self.assertTrue(len(arch) > 0)107