def IncludeCache_NotCached_DirAccessible_test():
    include_cache = IncludeCache()
    assert_that(include_cache._cache, equal_to({}))
    includes = include_cache.GetIncludes(PathToTestFile('cache_test'))
    mtime = os.path.getmtime(PathToTestFile('cache_test'))
    assert_that(
        includes,
        contains_exactly(has_properties({
            'name': 'foo.h',
            'entry_type': 1
        })))
    assert_that(
        include_cache._cache,
        has_entry(
            PathToTestFile('cache_test'),
            has_entries({
                'mtime':
                mtime,
                'includes':
                contains_exactly(
                    has_properties({
                        'name': 'foo.h',
                        'entry_type': 1
                    }))
            })))
Example #2
0
 def __init__(self, user_options):
     super(ClangCompleter, self).__init__(user_options)
     self._completer = ycm_core.ClangCompleter()
     self._flags = Flags()
     self._include_cache = IncludeCache()
     self._diagnostic_store = None
     self._files_being_compiled = EphemeralValuesSet()
Example #3
0
  def test_IncludeCache_Cached_NoNewMtime( self ):
    include_cache = IncludeCache()
    assert_that( include_cache._cache, equal_to( {} ) )
    old_includes = include_cache.GetIncludes( PathToTestFile( 'cache_test' ) )
    old_mtime = os.path.getmtime( PathToTestFile( 'cache_test' ) )

    assert_that( old_includes, contains_exactly( has_properties( {
                                           'name': 'foo.h',
                                           'entry_type': 1
                                         } ) ) )
    assert_that( include_cache._cache,
                 has_entry( PathToTestFile( 'cache_test' ),
                            has_entries( { 'mtime': old_mtime,
                              'includes': contains_exactly( has_properties( {
                                                      'name': 'foo.h',
                                                      'entry_type': 1
                                                    } ) ) } ) ) )

    new_includes = include_cache.GetIncludes( PathToTestFile( 'cache_test' ) )
    new_mtime = os.path.getmtime( PathToTestFile( 'cache_test' ) )

    assert_that( new_mtime, equal_to( old_mtime ) )
    assert_that( new_includes, contains_exactly( has_properties( {
                                           'name': 'foo.h',
                                           'entry_type': 1
                                         } ) ) )
    assert_that( include_cache._cache,
                 has_entry( PathToTestFile( 'cache_test' ),
                            has_entries( { 'mtime': new_mtime,
                              'includes': contains_exactly( has_properties( {
                                                      'name': 'foo.h',
                                                      'entry_type': 1
                                                    } ) ) } ) ) )
Example #4
0
  def test_IncludeCache_Cached_NewMtime( self ):
    with TemporaryTestDir() as tmp_dir:
      include_cache = IncludeCache()
      assert_that( include_cache._cache, equal_to( {} ) )
      foo_path = os.path.join( tmp_dir, 'foo' )
      with open( foo_path, 'w' ) as foo_file:
        foo_file.write( 'foo' )

      old_includes = include_cache.GetIncludes( tmp_dir )
      old_mtime = os.path.getmtime( tmp_dir )
      assert_that( old_includes, contains_exactly( has_properties( {
                                             'name': 'foo',
                                             'entry_type': 1
                                           } ) ) )
      assert_that( include_cache._cache,
                   has_entry( tmp_dir,
                     has_entries( {
                       'mtime': old_mtime,
                       'includes': contains_exactly( has_properties( {
                         'name': 'foo',
                         'entry_type': 1
                       } ) )
                     } ) ) )

      sleep( 2 )

      bar_path = os.path.join( tmp_dir, 'bar' )
      with open( bar_path, 'w' ) as bar_file:
        bar_file.write( 'bar' )

      new_includes = include_cache.GetIncludes( tmp_dir )
      new_mtime = os.path.getmtime( tmp_dir )
      assert_that( old_mtime, not_( equal_to( new_mtime ) ) )
      assert_that( new_includes, contains_inanyorder(
                                   has_properties( {
                                     'name': 'foo',
                                     'entry_type': 1
                                   } ),
                                   has_properties( {
                                     'name': 'bar',
                                     'entry_type': 1
                                   } )
                                 ) )
      assert_that( include_cache._cache,
          has_entry( tmp_dir, has_entries( {
                                'mtime': new_mtime,
                                'includes': contains_inanyorder(
                                  has_properties( {
                                    'name': 'foo',
                                    'entry_type': 1
                                  } ),
                                  has_properties( {
                                    'name': 'bar',
                                    'entry_type': 1
                                  } ) )
                              } ) ) )
Example #5
0
 def __init__( self, user_options ):
   super( ClangCompleter, self ).__init__( user_options )
   self._max_diagnostics_to_display = user_options[
     'max_diagnostics_to_display' ]
   self._completer = ycm_core.ClangCompleter()
   self._flags = Flags()
   self._include_cache = IncludeCache()
   self._diagnostic_store = None
   self._files_being_compiled = EphemeralValuesSet()
   self._logger = logging.getLogger( __name__ )
Example #6
0
def IncludeCache_Cached_NoNewMtime_test():
    include_cache = IncludeCache()
    eq_(include_cache._cache, {})
    old_includes = include_cache.GetIncludes(PathToTestFile('cache_test'))
    old_mtime = os.path.getmtime(PathToTestFile('cache_test'))

    assert_that(old_includes,
                contains(has_properties({
                    'name': 'foo.h',
                    'entry_type': 1
                })))
    assert_that(
        include_cache._cache,
        has_entry(
            PathToTestFile('cache_test'),
            has_entries({
                'mtime':
                old_mtime,
                'includes':
                contains(has_properties({
                    'name': 'foo.h',
                    'entry_type': 1
                }))
            })))

    new_includes = include_cache.GetIncludes(PathToTestFile('cache_test'))
    new_mtime = os.path.getmtime(PathToTestFile('cache_test'))

    eq_(new_mtime, old_mtime)
    assert_that(new_includes,
                contains(has_properties({
                    'name': 'foo.h',
                    'entry_type': 1
                })))
    assert_that(
        include_cache._cache,
        has_entry(
            PathToTestFile('cache_test'),
            has_entries({
                'mtime':
                new_mtime,
                'includes':
                contains(has_properties({
                    'name': 'foo.h',
                    'entry_type': 1
                }))
            })))
def IncludeCache_NotCached_DirInaccessible_test():
    include_cache = IncludeCache()
    assert_that(include_cache._cache, equal_to({}))
    includes = include_cache.GetIncludes(PathToTestFile('unknown_dir'))
    assert_that(includes, equal_to([]))
    assert_that(include_cache._cache, equal_to({}))
Example #8
0
def IncludeCache_NotCached_DirInaccessible_test():
    include_cache = IncludeCache()
    eq_(include_cache._cache, {})
    includes = include_cache.GetIncludes(PathToTestFile('unknown_dir'))
    eq_(includes, [])
    eq_(include_cache._cache, {})