This file is indexed.

/usr/share/clang/scan-build-py-4.0/tests/unit/test_compilation.py is in clang-tools-4.0 1:4.0.1-10~deb9u2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# -*- 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.compilation as sut
import unittest


class CompilerTest(unittest.TestCase):

    def test_is_compiler_call(self):
        self.assertIsNotNone(sut.compiler_language(['clang']))
        self.assertIsNotNone(sut.compiler_language(['clang-3.6']))
        self.assertIsNotNone(sut.compiler_language(['clang++']))
        self.assertIsNotNone(sut.compiler_language(['clang++-3.5.1']))
        self.assertIsNotNone(sut.compiler_language(['cc']))
        self.assertIsNotNone(sut.compiler_language(['c++']))
        self.assertIsNotNone(sut.compiler_language(['gcc']))
        self.assertIsNotNone(sut.compiler_language(['g++']))
        self.assertIsNotNone(sut.compiler_language(['/usr/local/bin/gcc']))
        self.assertIsNotNone(sut.compiler_language(['/usr/local/bin/g++']))
        self.assertIsNotNone(sut.compiler_language(['/usr/local/bin/clang']))
        self.assertIsNotNone(
            sut.compiler_language(['armv7_neno-linux-gnueabi-g++']))

        self.assertIsNone(sut.compiler_language([]))
        self.assertIsNone(sut.compiler_language(['']))
        self.assertIsNone(sut.compiler_language(['ld']))
        self.assertIsNone(sut.compiler_language(['as']))
        self.assertIsNone(sut.compiler_language(['/usr/local/bin/compiler']))


class SplitTest(unittest.TestCase):

    def test_detect_cxx_from_compiler_name(self):
        def test(cmd):
            result = sut.split_command([cmd, '-c', 'src.c'])
            self.assertIsNotNone(result, "wrong input for test")
            return result.compiler == 'c++'

        self.assertFalse(test('cc'))
        self.assertFalse(test('gcc'))
        self.assertFalse(test('clang'))

        self.assertTrue(test('c++'))
        self.assertTrue(test('g++'))
        self.assertTrue(test('g++-5.3.1'))
        self.assertTrue(test('clang++'))
        self.assertTrue(test('clang++-3.7.1'))
        self.assertTrue(test('armv7_neno-linux-gnueabi-g++'))

    def test_action(self):
        self.assertIsNotNone(sut.split_command(['clang', 'source.c']))
        self.assertIsNotNone(sut.split_command(['clang', '-c', 'source.c']))
        self.assertIsNotNone(sut.split_command(['clang', '-c', 'source.c',
                                                '-MF', 'a.d']))

        self.assertIsNone(sut.split_command(['clang', '-E', 'source.c']))
        self.assertIsNone(sut.split_command(['clang', '-c', '-E', 'source.c']))
        self.assertIsNone(sut.split_command(['clang', '-c', '-M', 'source.c']))
        self.assertIsNone(
            sut.split_command(['clang', '-c', '-MM', 'source.c']))

    def test_source_file(self):
        def test(expected, cmd):
            self.assertEqual(expected, sut.split_command(cmd).files)

        test(['src.c'], ['clang', 'src.c'])
        test(['src.c'], ['clang', '-c', 'src.c'])
        test(['src.C'], ['clang', '-x', 'c', 'src.C'])
        test(['src.cpp'], ['clang++', '-c', 'src.cpp'])
        test(['s1.c', 's2.c'], ['clang', '-c', 's1.c', 's2.c'])
        test(['s1.c', 's2.c'], ['cc', 's1.c', 's2.c', '-ldep', '-o', 'a.out'])
        test(['src.c'], ['clang', '-c', '-I', './include', 'src.c'])
        test(['src.c'], ['clang', '-c', '-I', '/opt/me/include', 'src.c'])
        test(['src.c'], ['clang', '-c', '-D', 'config=file.c', 'src.c'])

        self.assertIsNone(
            sut.split_command(['cc', 'this.o', 'that.o', '-o', 'a.out']))
        self.assertIsNone(
            sut.split_command(['cc', 'this.o', '-lthat', '-o', 'a.out']))

    def test_filter_flags(self):
        def test(expected, flags):
            command = ['clang', '-c', 'src.c'] + flags
            self.assertEqual(expected, sut.split_command(command).flags)

        def same(expected):
            test(expected, expected)

        def filtered(flags):
            test([], flags)

        same([])
        same(['-I', '/opt/me/include', '-DNDEBUG', '-ULIMITS'])
        same(['-O', '-O2'])
        same(['-m32', '-mmms'])
        same(['-Wall', '-Wno-unused', '-g', '-funroll-loops'])

        filtered([])
        filtered(['-lclien', '-L/opt/me/lib', '-L', '/opt/you/lib'])
        filtered(['-static'])
        filtered(['-MD', '-MT', 'something'])
        filtered(['-MMD', '-MF', 'something'])


class SourceClassifierTest(unittest.TestCase):

    def test_sources(self):
        self.assertIsNone(sut.classify_source('file.o'))
        self.assertIsNone(sut.classify_source('file.exe'))
        self.assertIsNone(sut.classify_source('/path/file.o'))
        self.assertIsNone(sut.classify_source('clang'))

        self.assertEqual('c', sut.classify_source('file.c'))
        self.assertEqual('c', sut.classify_source('./file.c'))
        self.assertEqual('c', sut.classify_source('/path/file.c'))
        self.assertEqual('c++', sut.classify_source('file.c', False))
        self.assertEqual('c++', sut.classify_source('./file.c', False))
        self.assertEqual('c++', sut.classify_source('/path/file.c', False))