summaryrefslogtreecommitdiffstats
path: root/tools/scan-build-py/tests/unit/test_clang.py
blob: 2f1fd79d4a92d9f61bcecfc5ee196f91cd662fd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# -*- coding: utf-8 -*-
#                     The LLVM Compiler Infrastructure
#
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.

import libscanbuild.clang as sut
from . import fixtures
import os.path


class GetClangArgumentsTest(fixtures.TestCase):
    def test_get_clang_arguments(self):
        with fixtures.TempDir() as tmpdir:
            filename = os.path.join(tmpdir, 'test.c')
            with open(filename, 'w') as handle:
                handle.write('')

            result = sut.get_arguments(
                ['clang', '-c', filename, '-DNDEBUG', '-Dvar="this is it"'],
                tmpdir)

            self.assertIn('NDEBUG', result)
            self.assertIn('var="this is it"', result)

    def test_get_clang_arguments_fails(self):
        self.assertRaises(
            Exception, sut.get_arguments,
            ['clang', '-###', '-fsyntax-only', '-x', 'c', 'notexist.c'], '.')


class GetCheckersTest(fixtures.TestCase):
    def test_get_checkers(self):
        # this test is only to see is not crashing
        result = sut.get_checkers('clang', [])
        self.assertTrue(len(result))

    def test_get_active_checkers(self):
        # this test is only to see is not crashing
        result = sut.get_active_checkers('clang', [])
        self.assertTrue(len(result))