def CompilationDatabase_UseFlagsFromSameDir_test(): with TemporaryClangTestDir() as tmp_dir: compile_commands = [ { 'directory': tmp_dir, 'command': 'clang++ -x c++ -Wall', 'file': os.path.join(tmp_dir, 'test.cc'), }, ] with TemporaryClangProject(tmp_dir, compile_commands): f = flags.Flags() # If we now ask for a file _not_ in the DB, we get [] eq_( f.FlagsForFile(os.path.join(tmp_dir, 'test1.cc'), add_extra_clang_flags=False), []) # Then, we ask for a file that _is_ in the db. It will cache these flags # against the files' directory. assert_that( f.FlagsForFile(os.path.join(tmp_dir, 'test.cc'), add_extra_clang_flags=False), contains('clang++', '-x', 'c++', '-x', 'c++', '-Wall')) # If we now ask for a file _not_ in the DB, but in the same dir, we should # get the same flags assert_that( f.FlagsForFile(os.path.join(tmp_dir, 'test2.cc'), add_extra_clang_flags=False), contains('clang++', '-x', 'c++', '-x', 'c++', '-Wall'))
def DebugInfo_FlagsWhenNoExtraConfAndInvalidCompilationDatabase_test( app ): with TemporaryTestDir() as tmp_dir: compile_commands = 'garbage' with TemporaryClangProject( tmp_dir, compile_commands ): request_data = BuildRequest( filepath = os.path.join( tmp_dir, 'test.cc' ), filetype = 'cpp' ) assert_that( app.post_json( '/debug_info', request_data ).json, has_entry( 'completer', has_entries( { 'name': 'C-family', 'servers': empty(), 'items': contains( has_entries( { 'key': 'compilation database path', 'value': 'None' } ), has_entries( { 'key': 'flags', 'value': '[]' } ), has_entries( { 'key': 'translation unit', 'value': os.path.join( tmp_dir, 'test.cc' ) } ) ) } ) ) )
def CompilationDatabase_InvalidDatabase_test(): with TemporaryClangTestDir() as tmp_dir: with TemporaryClangProject(tmp_dir, 'this is junk'): assert_that( calling(flags.Flags().FlagsForFile).with_args( os.path.join(tmp_dir, 'test.cc')), raises(NoExtraConfDetected))
def CompilationDatabase_FileNotInDatabase_test(): compile_commands = [] with TemporaryTestDir() as tmp_dir: with TemporaryClangProject( tmp_dir, compile_commands ): eq_( flags.Flags().FlagsForFile( os.path.join( tmp_dir, 'test.cc' ) ), ( [], os.path.join( tmp_dir, 'test.cc' ) ) )
def CompilationDatabase_ExplicitHeaderFileEntry_test(): with TemporaryTestDir() as tmp_dir: # Have an explicit header file entry which should take priority over the # corresponding source file compile_commands = [ { 'directory': tmp_dir, 'command': 'clang++ -x c++ -I. -I/absolute/path -Wall', 'file': os.path.join( tmp_dir, 'test.cc' ), }, { 'directory': tmp_dir, 'command': 'clang++ -I/absolute/path -Wall', 'file': os.path.join( tmp_dir, 'test.h' ), }, ] with TemporaryClangProject( tmp_dir, compile_commands ): assert_that( flags.Flags().FlagsForFile( os.path.join( tmp_dir, 'test.h' ), add_extra_clang_flags = False )[ 0 ], contains( 'clang++', '-x', 'c++', '-I' + os.path.normpath( '/absolute/path' ), '-Wall' ) )
def DebugInfo_FlagsWhenNoExtraConfAndCompilationDatabaseLoaded_test( app ): with TemporaryClangTestDir() as tmp_dir: compile_commands = [ { 'directory': tmp_dir, 'command': 'clang++ -I. -I/absolute/path -Wall', 'file': os.path.join( tmp_dir, 'test.cc' ), }, ] with TemporaryClangProject( tmp_dir, compile_commands ): request_data = BuildRequest( filepath = os.path.join( tmp_dir, 'test.cc' ), filetype = 'cpp' ) assert_that( app.post_json( '/debug_info', request_data ).json, has_entry( 'completer', has_entries( { 'name': 'C-family', 'servers': empty(), 'items': contains( has_entries( { 'key': 'compilation database path', 'value': instance_of( str ) } ), has_entries( { 'key': 'flags', 'value': matches_regexp( "\['clang\+\+', '-x', 'c\+\+', .*, '-Wall', .*\]" ) } ) ) } ) ) )
def CppBindings_CompilationDatabase_test(): with TemporaryTestDir() as tmp_dir: compile_commands = [ { 'directory': tmp_dir, 'command': 'clang++ -x c++ -I. -I/absolute/path -Wall', 'file': os.path.join(tmp_dir, 'test.cc'), }, ] with TemporaryClangProject(tmp_dir, compile_commands): db = ycm_core.CompilationDatabase(tmp_dir) db_successful = db.DatabaseSuccessfullyLoaded() db_busy = db.AlreadyGettingFlags() db_dir = db.database_directory compilation_info = db.GetCompilationInfoForFile( compile_commands[0]['file']) del db del compile_commands eq_(db_successful, True) eq_(db_busy, False) eq_(db_dir, tmp_dir) assert_that( compilation_info, has_properties({ 'compiler_working_dir_': tmp_dir, 'compiler_flags_': contains('clang++', '-x', 'c++', '-I.', '-I/absolute/path', '-Wall') }))
def DebugInfo_CompilationDatabase_test(app): with TemporaryClangTestDir() as tmp_dir: compile_commands = [ { 'directory': tmp_dir, 'command': 'clang++ -x c++ -I. -I/absolute/path -Wall', 'file': os.path.join(tmp_dir, 'test.cc'), }, ] with TemporaryClangProject(tmp_dir, compile_commands): request_data = BuildRequest(filepath=os.path.join( tmp_dir, 'test.cc'), filetype='cpp') assert_that( app.post_json('/debug_info', request_data).json, matches_regexp('C-family completer debug information:\n' ' No configuration file found\n' ' Using compilation database from: .+\n' ' Flags: .+-Wall.+')) assert_that( app.post_json('/debug_info', request_data).json, matches_regexp('C-family completer debug information:\n' ' No configuration file found\n' ' Using compilation database from: .+\n' ' Flags: .+-Wall.+'))
def CompilationDatabase_HeaderFileHeuristic_test(): with TemporaryClangTestDir() as tmp_dir: compile_commands = [ { 'directory': tmp_dir, 'command': 'clang++ -x c++ -Wall', 'file': os.path.join(tmp_dir, 'test.cc'), }, ] with TemporaryClangProject(tmp_dir, compile_commands): # If we ask for a header file, it returns the equivalent cc file assert_that( flags.Flags().FlagsForFile(os.path.join(tmp_dir, 'test.h'), add_extra_clang_flags=False), contains('clang++', '-x', 'c++', '-x', 'c++', '-Wall'))
def CompilationDatabase_UseFlagsFromDatabase_test(): with TemporaryClangTestDir() as tmp_dir: compile_commands = [ { 'directory': tmp_dir, 'command': 'clang++ -x c++ -I. -I/absolute/path -Wall', 'file': os.path.join(tmp_dir, 'test.cc'), }, ] with TemporaryClangProject(tmp_dir, compile_commands): assert_that( flags.Flags().FlagsForFile(os.path.join(tmp_dir, 'test.cc'), add_extra_clang_flags=False), contains('clang++', '-x', 'c++', '-x', 'c++', '-I' + os.path.normpath(tmp_dir), '-I' + os.path.normpath('/absolute/path'), '-Wall'))
def CompilationDatabase_CUDALanguageFlags_test(): with TemporaryTestDir() as tmp_dir: compile_commands = [ { 'directory': tmp_dir, 'command': 'clang++ -Wall {}'.format('./test.cu'), 'file': os.path.join(tmp_dir, 'test.cu'), }, ] with TemporaryClangProject(tmp_dir, compile_commands): # If we ask for a header file, it returns the equivalent cu file assert_that( flags.Flags().FlagsForFile(os.path.join(tmp_dir, 'test.h'), add_extra_clang_flags=False)[0], contains('clang++', '-x', 'cuda', '-Wall'))
def CompilationDatabase_HeaderFileHeuristicNotFound_test(): with TemporaryClangTestDir() as tmp_dir: compile_commands = [ { 'directory': tmp_dir, 'command': 'clang++ -x c++ -Wall', 'file': os.path.join(tmp_dir, 'test.cc'), }, ] with TemporaryClangProject(tmp_dir, compile_commands): # If we ask for a header file, it returns the equivalent cc file (if and # only if there are flags for that file) eq_( flags.Flags().FlagsForFile(os.path.join( tmp_dir, 'not_in_the_db.h'), add_extra_clang_flags=False), [])
def DebugInfo_InvalidCompilationDatabase_test(app): with TemporaryClangTestDir() as tmp_dir: compile_commands = 'garbage' with TemporaryClangProject(tmp_dir, compile_commands): request_data = BuildRequest(filepath=os.path.join( tmp_dir, 'test.cc'), filetype='cpp') assert_that( app.post_json('/debug_info', request_data).json, contains_string('C-family completer debug information:\n' ' No configuration file found\n' ' No compilation database found')) assert_that( app.post_json('/debug_info', request_data).json, contains_string('C-family completer debug information:\n' ' No configuration file found\n' ' No compilation database found'))