Laszlo Nagy | bc68758 | 2016-01-12 22:38:41 +0000 | [diff] [blame] | 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 | |
Laszlo Nagy | 8bd63e5 | 2016-04-19 12:03:03 +0000 | [diff] [blame] | 7 | import libear |
Laszlo Nagy | bc68758 | 2016-01-12 22:38:41 +0000 | [diff] [blame] | 8 | import libscanbuild.clang as sut |
Laszlo Nagy | 8bd63e5 | 2016-04-19 12:03:03 +0000 | [diff] [blame] | 9 | import unittest |
Laszlo Nagy | bc68758 | 2016-01-12 22:38:41 +0000 | [diff] [blame] | 10 | import os.path |
| 11 | |
| 12 | |
Laszlo Nagy | 8bd63e5 | 2016-04-19 12:03:03 +0000 | [diff] [blame] | 13 | class GetClangArgumentsTest(unittest.TestCase): |
Laszlo Nagy | bc68758 | 2016-01-12 22:38:41 +0000 | [diff] [blame] | 14 | def test_get_clang_arguments(self): |
Laszlo Nagy | 8bd63e5 | 2016-04-19 12:03:03 +0000 | [diff] [blame] | 15 | with libear.TemporaryDirectory() as tmpdir: |
Laszlo Nagy | bc68758 | 2016-01-12 22:38:41 +0000 | [diff] [blame] | 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 | |
Laszlo Nagy | 8bd63e5 | 2016-04-19 12:03:03 +0000 | [diff] [blame] | 24 | self.assertTrue('NDEBUG' in result) |
| 25 | self.assertTrue('var="this is it"' in result) |
Laszlo Nagy | bc68758 | 2016-01-12 22:38:41 +0000 | [diff] [blame] | 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 | |
Laszlo Nagy | 8bd63e5 | 2016-04-19 12:03:03 +0000 | [diff] [blame] | 33 | class GetCheckersTest(unittest.TestCase): |
Laszlo Nagy | bc68758 | 2016-01-12 22:38:41 +0000 | [diff] [blame] | 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)) |