forked from niosus/EasyClangComplete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_flags_source.py
51 lines (42 loc) · 2.01 KB
/
test_flags_source.py
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
"""Tests for cmake database generation."""
import imp
from os import path
from unittest import TestCase
from EasyClangComplete.plugin.flags_sources import flags_source
from EasyClangComplete.plugin.utils import flag
imp.reload(flags_source)
imp.reload(flag)
FlagsSource = flags_source.FlagsSource
Flag = flag.Flag
class TestFlagsSource(TestCase):
"""Test getting flags from a list of chunks."""
def test_init(self):
"""Initialization test."""
include_prefixes = ["-I", "-isystem"]
flags_source = FlagsSource(include_prefixes)
self.assertEqual(flags_source._include_prefixes, include_prefixes)
def test_parse_flags(self):
"""Test that the flags are parsed correctly."""
from os import listdir
current_folder = path.dirname(__file__)
folder_to_expand = path.join(current_folder, '*')
initial_str_flags = ["-I", current_folder, "-I" + current_folder,
"-isystem", current_folder, "-std=c++11",
"#simulate a comment",
"-Iblah\n", "-I", "blah", "-I" + folder_to_expand]
flags = Flag.tokenize_list(initial_str_flags, current_folder)
expected_blah_path = path.join(current_folder, "blah")
self.assertIn(Flag("-I", current_folder, " "), flags)
self.assertIn(Flag("-I", current_folder), flags)
self.assertIn(Flag("-isystem", current_folder, " "), flags)
self.assertIn(Flag("-I", expected_blah_path, " "), flags)
self.assertIn(Flag("-I", expected_blah_path), flags)
self.assertIn(Flag("", "-std=c++11"), flags)
# Check star expansion for a flags source
for child in listdir(current_folder):
child = path.join(current_folder, child)
if path.isdir(child):
self.assertIn(Flag("-I", child), flags)
self.assertNotIn(Flag("", "-Iblah"), flags)
self.assertNotIn(Flag("-I", "blah", " "), flags)
self.assertNotIn(Flag("", "-isystem" + current_folder), flags)