1# -*- coding: utf-8 -*- 2# The LLVM Compiler Infrastructure 3# 4# This file is distributed under the University of Illinois Open Source 5# License. See LICENSE.TXT for details. 6 7import libear 8import libscanbuild.clang as sut 9import unittest 10import os.path 11 12 13class GetClangArgumentsTest(unittest.TestCase): 14 def test_get_clang_arguments(self): 15 with libear.TemporaryDirectory() as tmpdir: 16 filename = os.path.join(tmpdir, 'test.c') 17 with open(filename, 'w') as handle: 18 handle.write('') 19 20 result = sut.get_arguments( 21 ['clang', '-c', filename, '-DNDEBUG', '-Dvar="this is it"'], 22 tmpdir) 23 24 self.assertTrue('NDEBUG' in result) 25 self.assertTrue('var="this is it"' in result) 26 27 def test_get_clang_arguments_fails(self): 28 self.assertRaises( 29 Exception, sut.get_arguments, 30 ['clang', '-###', '-fsyntax-only', '-x', 'c', 'notexist.c'], '.') 31 32 33class GetCheckersTest(unittest.TestCase): 34 def test_get_checkers(self): 35 # this test is only to see is not crashing 36 result = sut.get_checkers('clang', []) 37 self.assertTrue(len(result)) 38 39 def test_get_active_checkers(self): 40 # this test is only to see is not crashing 41 result = sut.get_active_checkers('clang', []) 42 self.assertTrue(len(result)) 43