2020from hamcrest import ( assert_that ,
2121 calling ,
2222 contains_exactly ,
23+ matches_regexp ,
2324 empty ,
2425 equal_to ,
2526 raises )
3031from ycmd .completers .cpp import flags
3132from ycmd .completers .cpp .flags import ShouldAllowWinStyleFlags , INCLUDE_FLAGS
3233from ycmd .tests .test_utils import ( MacOnly , TemporaryTestDir , WindowsOnly ,
33- TemporaryClangProject )
34+ TemporaryClangProject , UnixOnly )
3435from ycmd .tests .clang import setUpModule # noqa
3536from ycmd .utils import CLANG_RESOURCE_DIR
3637from ycmd .responses import NoExtraConfDetected
@@ -1424,8 +1425,7 @@ def test_CompilationDatabase_UseFlagsFromSameDir( self ):
14241425 '-x' ,
14251426 'c++' ,
14261427 '--driver-mode=g++' ,
1427- '-Wall' ,
1428- '--' ),
1428+ '-Wall' ),
14291429 os .path .join ( tmp_dir , 'test1.cc' )
14301430 )
14311431 )
@@ -1441,8 +1441,7 @@ def test_CompilationDatabase_UseFlagsFromSameDir( self ):
14411441 '-x' ,
14421442 'c++' ,
14431443 '--driver-mode=g++' ,
1444- '-Wall' ,
1445- '--' ),
1444+ '-Wall' ),
14461445 os .path .join ( tmp_dir , 'some_dir' , 'test1.cc' )
14471446 )
14481447 )
@@ -1472,8 +1471,40 @@ def test_CompilationDatabase_HeaderFile_SameNameAsSourceFile( self ):
14721471 '--driver-mode=g++' ,
14731472 '-Wall' ,
14741473 '-x' ,
1475- 'c++-header' ,
1476- '--' ) )
1474+ 'c++-header' ) )
1475+
1476+
1477+ @UnixOnly
1478+ def test_CompilationDatabase_HeaderFile_SameNameAsSourceFile_ExtraClang (
1479+ self ):
1480+ with TemporaryTestDir () as tmp_dir :
1481+ compile_commands = [
1482+ {
1483+ 'directory' : tmp_dir ,
1484+ 'command' : 'clang++ -x c++ -Wall' ,
1485+ 'file' : os .path .join ( tmp_dir , 'test.cc' ),
1486+ },
1487+ ]
1488+
1489+ with patch ( 'ycmd.completers.cpp.flags.OnMac' , return_value = False ):
1490+ with TemporaryClangProject ( tmp_dir , compile_commands ):
1491+ # If we ask for a header file with the same name as a source file, it
1492+ # returns the flags of that cc file (and a special language flag for
1493+ # C++ # headers). It also includes a trailing `--` flag which breaks
1494+ # our "add_extra_clang_flags", so test here that works correctly.
1495+ assert_that (
1496+ flags .Flags ().FlagsForFile (
1497+ os .path .join ( tmp_dir , 'test.h' ),
1498+ add_extra_clang_flags = True )[ 0 ],
1499+ contains_exactly ( 'clang++' ,
1500+ '-x' ,
1501+ 'c++' ,
1502+ '--driver-mode=g++' ,
1503+ '-Wall' ,
1504+ '-x' ,
1505+ 'c++-header' ,
1506+ matches_regexp ( '-resource-dir=.*' ),
1507+ '-fspell-checking' ) )
14771508
14781509
14791510 def test_CompilationDatabase_HeaderFile_DifferentNameFromSourceFile ( self ):
@@ -1500,8 +1531,7 @@ def test_CompilationDatabase_HeaderFile_DifferentNameFromSourceFile( self ):
15001531 '--driver-mode=g++' ,
15011532 '-Wall' ,
15021533 '-x' ,
1503- 'c++-header' ,
1504- '--' ) )
1534+ 'c++-header' ) )
15051535
15061536
15071537 def test_CompilationDatabase_ExplicitHeaderFileEntry ( self ):
@@ -1553,8 +1583,7 @@ def test_CompilationDatabase_CUDALanguageFlags( self ):
15531583 '--driver-mode=g++' ,
15541584 '-Wall' ,
15551585 '-x' ,
1556- 'cuda' ,
1557- '--' ) )
1586+ 'cuda' ) )
15581587
15591588
15601589 def test_MakeRelativePathsInFlagsAbsolute ( self ):
0 commit comments