def Subcommands_DefinedSubcommands_test( app ):
  file_path = PathToTestFile( 'GoTo_Clang_ZeroBasedLineAndColumn_test.cc' )
  RunAfterInitialized( app, {
      'request': {
        'completer_target': 'filetype_default',
        'line_num': 10,
        'column_num': 3,
        'filetype': 'objcpp',
        'filepath': file_path
      },
      'expect': {
        'response': requests.codes.ok,
        'data': contains_exactly( *sorted( [ 'ExecuteCommand',
                                     'FixIt',
                                     'Format',
                                     'GetDoc',
                                     'GetDocImprecise',
                                     'GetType',
                                     'GetTypeImprecise',
                                     'GoTo',
                                     'GoToDeclaration',
                                     'GoToDefinition',
                                     'GoToImprecise',
                                     'GoToInclude',
                                     'GoToReferences',
                                     'RefactorRename',
                                     'RestartServer' ] ) )
      },
      'route': '/defined_subcommands',
  } )
Example #2
0
def Diagnostics_Multiline_test( app ):
  contents = """
struct Foo {
  Foo(int z) {}
};

int main() {
  Foo foo("goo");
}
"""

  filepath = PathToTestFile( 'foo.cc' )
  request = { 'contents': contents,
              'filepath': filepath,
              'filetype': 'cpp' }

  test = { 'request': request, 'route': '/receive_messages' }
  RunAfterInitialized( app, test )
  diag_data = BuildRequest( line_num = 7,
                            contents = contents,
                            filepath = filepath,
                            filetype = 'cpp' )

  results = app.post_json( '/detailed_diagnostic', diag_data ).json
  assert_that( results,
               has_entry( 'message', contains_string( "\n" ) ) )
Example #3
0
def Subcommands_RefactorRename_test( app ):
  test = {
    'request': {
      'filetype': 'cpp',
      'completer_target': 'filetype_default',
      'contents': ReadFile( PathToTestFile( 'basic.cpp' ) ),
      'filepath': PathToTestFile( 'basic.cpp' ),
      'command_arguments': [ 'RefactorRename', 'Bar' ],
      'line_num': 17,
      'column_num': 4,
    },
    'expect': {
      'response': requests.codes.ok,
      'data': has_entries( {
        'fixits': contains_exactly( has_entries( {
          'chunks': contains_exactly(
            ChunkMatcher( 'Bar',
                          LineColMatcher( 1, 8 ),
                          LineColMatcher( 1, 11 ) ),
            ChunkMatcher( 'Bar',
                          LineColMatcher( 9, 3 ),
                          LineColMatcher( 9, 6 ) ),
            ChunkMatcher( 'Bar',
                          LineColMatcher( 15,  8 ),
                          LineColMatcher( 15, 11 ) ),
            ChunkMatcher( 'Bar',
                          LineColMatcher( 17, 3 ),
                          LineColMatcher( 17, 6 ) ),
          )
        } ) )
      } )
    },
    'route': '/run_completer_command'
  }
  RunAfterInitialized( app, test )
def Diagnostics_ZeroBasedLineAndColumn_test(app):
    contents = """
void foo() {
  double baz = "foo";
}
// Padding to 5 lines
// Padding to 5 lines
"""

    filepath = PathToTestFile('foo.cc')
    request = {'contents': contents, 'filepath': filepath, 'filetype': 'cpp'}

    test = {'request': request, 'route': '/receive_messages'}
    results = RunAfterInitialized(app, test)
    assert_that(
        results,
        contains_exactly(
            has_entries({
                'diagnostics':
                contains_exactly(
                    has_entries({
                        'kind':
                        equal_to('ERROR'),
                        'text':
                        contains_string('Cannot initialize'),
                        'ranges':
                        contains_exactly(
                            RangeMatcher(filepath, (3, 10), (3, 13))),
                        'location':
                        LocationMatcher(filepath, 3, 10),
                        'location_extent':
                        RangeMatcher(filepath, (3, 10), (3, 13))
                    }))
            })))
Example #5
0
 def test_DebugInfo_Initialized( self, app ):
   request_data = BuildRequest( filepath = PathToTestFile( 'basic.cpp' ),
                                filetype = 'cpp' )
   test = { 'request': request_data }
   RunAfterInitialized( app, test )
   assert_that(
     app.post_json( '/debug_info', request_data ).json,
     has_entry( 'completer', has_entries( {
       'name': 'C-family',
       'servers': contains_exactly( has_entries( {
         'name': 'Clangd',
         'is_running': True,
         'extras': contains_exactly(
           has_entries( {
             'key': 'Server State',
             'value': 'Initialized',
           } ),
           has_entries( {
             'key': 'Project Directory',
             'value': PathToTestFile(),
           } ),
           has_entries( {
             'key': 'Settings',
             'value': '{}',
           } ),
           has_entries( {
             'key': 'Compilation Command',
             'value': False,
           } ),
         ),
       } ) ),
       'items': empty()
     } ) )
   )
Example #6
0
def GetCompletions_NoCompletionsWhenAutoTriggerOff_test(app):
    contents = """
struct Foo {
  int x;
  int y;
  char c;
};

int main()
{
  Foo foo;
  foo.
}
"""

    filepath = PathToTestFile('foo.cc')
    request = {'contents': contents, 'filepath': filepath, 'filetype': 'cpp'}

    test = {'request': request}
    results = RunAfterInitialized(app, test)
    completion_data = BuildRequest(filepath=filepath,
                                   filetype='cpp',
                                   contents=contents,
                                   line_num=11,
                                   column_num=7)

    results = app.post_json('/completions',
                            completion_data).json['completions']
    assert_that(results, empty())
def Diagnostics_DiagsNotReady_test(app):
    completer = handlers._server_state.GetFiletypeCompleter(['cpp'])
    contents = """
struct Foo {
  int x  // semicolon missing here!
  int y;
  int c;
  int d;
};
"""

    filepath = PathToTestFile('foo.cc')
    request = {'contents': contents, 'filepath': filepath, 'filetype': 'cpp'}

    test = {'request': request, 'route': '/receive_messages'}
    RunAfterInitialized(app, test)
    diag_data = BuildRequest(line_num=3,
                             contents=contents,
                             filepath=filepath,
                             filetype='cpp')

    with patch.object(completer, '_latest_diagnostics', None):
        results = app.post_json('/detailed_diagnostic', diag_data).json
        assert_that(results,
                    has_entry('message', contains_string("are not ready yet")))
Example #8
0
    def test_Diagnostics_SimpleLocationExtent(self, app):
        contents = """
void foo() {
  baz = 5;
}
// Padding to 5 lines
// Padding to 5 lines
"""

        filepath = PathToTestFile('foo.cc')
        request = {
            'contents': contents,
            'filepath': filepath,
            'filetype': 'cpp'
        }
        test = {'request': request, 'route': '/receive_messages'}
        results = RunAfterInitialized(app, test)
        assert_that(
            results,
            contains_exactly(
                has_entries({
                    'diagnostics':
                    contains_exactly(
                        has_entries({
                            'location_extent':
                            RangeMatcher(filepath, (3, 3), (3, 6))
                        }))
                })))
Example #9
0
def Diagnostics_Works_test( app ):
  contents = """
struct Foo {
  int x  // semicolon missing here!
  int y;
  int c;
  int d;
};
"""

  filepath = PathToTestFile( 'foo.cc' )
  request = { 'contents': contents,
              'filepath': filepath,
              'filetype': 'cpp' }

  test = { 'request': request, 'route': '/receive_messages' }
  RunAfterInitialized( app, test )
  diag_data = BuildRequest( line_num = 3,
                            contents = contents,
                            filepath = filepath,
                            filetype = 'cpp' )

  results = app.post_json( '/detailed_diagnostic', diag_data ).json
  assert_that( results,
               has_entry( 'message', contains_string( "expected ';'" ) ) )
Example #10
0
def RunGetSemanticTest(app,
                       filepath,
                       filetype,
                       test,
                       command,
                       matches_regexp=False):
    contents = ReadFile(filepath)
    common_args = {
        'completer_target': 'filetype_default',
        'command_arguments': command,
        'line_num': 10,
        'column_num': 3,
        'filepath': filepath,
        'contents': contents,
        'filetype': filetype
    }

    args = test[0]
    expected = test[1]

    request = common_args
    request.update(args)

    test = {'request': request, 'route': '/run_completer_command'}
    response = RunAfterInitialized(app, test)['message']

    pprint(response)
    if matches_regexp:
        assert_that(response, expected)
    else:
        assert_that(response, contains_string(expected))
Example #11
0
def RunGoToTest_all(app, filename, command, test):
    contents = ReadFile(PathToTestFile(filename))
    common_request = {
        'completer_target': 'filetype_default',
        'filepath': PathToTestFile(filename),
        'command_arguments': command,
        'line_num': 10,
        'column_num': 3,
        'contents': contents,
        'filetype': 'cpp'
    }
    common_response = {
        'filepath': os.path.abspath(PathToTestFile(filename)),
    }

    request = common_request
    request.update({
        'line_num': test['request'][0],
        'column_num': test['request'][1],
    })
    response = common_response
    response.update({
        'line_num': test['response'][0],
        'column_num': test['response'][1],
    })
    if len(test['response']) > 2:
        response.update({'filepath': PathToTestFile(test['response'][2])})

    test = {'request': request, 'route': '/run_completer_command'}
    actual_response = RunAfterInitialized(app, test)

    pprint(actual_response)
    pprint(response)
    assert_that(actual_response, has_entries(response))
Example #12
0
def GetCompletions_ForceSemantic_OnlyFilteredCompletions_test(app):
    contents = """
int main()
{
  int foobar;
  int floozar;
  int gooboo;
  int bleble;

  fooar
}
"""

    filepath = PathToTestFile('foo.cc')
    request = {'contents': contents, 'filepath': filepath, 'filetype': 'cpp'}

    test = {'request': request}
    RunAfterInitialized(app, test)
    completion_data = BuildRequest(filepath=filepath,
                                   filetype='cpp',
                                   force_semantic=True,
                                   contents=contents,
                                   line_num=9,
                                   column_num=8)

    results = app.post_json('/completions',
                            completion_data).json['completions']
    assert_that(results, empty())
Example #13
0
def Diagnostics_NoLimitToNumberOfDiagnostics_test( app ):
  filepath = PathToTestFile( 'max_diagnostics.cc' )
  contents = ReadFile( filepath )
  request = { 'contents': contents,
              'filepath': filepath,
              'filetype': 'cpp' }

  test = { 'request': request, 'route': '/receive_messages' }
  response = RunAfterInitialized( app, test )

  pprint( response )

  assert_that( response, contains(
    has_entries( { 'diagnostics': has_items(
      has_entries( {
        'kind': equal_to( 'ERROR' ),
        'location': LocationMatcher( filepath, 3, 9 ),
        'location_extent': RangeMatcher( filepath, ( 3, 9 ), ( 3, 13 ) ),
        'ranges': contains( RangeMatcher( filepath, ( 3, 9 ), ( 3, 13 ) ) ),
        'text': contains_string( "redefinition of 'test'" ),
        'fixit_available': False
      } ),
      has_entries( {
        'kind': equal_to( 'ERROR' ),
        'location': LocationMatcher( filepath, 4, 9 ),
        'location_extent': RangeMatcher( filepath, ( 4, 9 ), ( 4, 13 ) ),
        'ranges': contains( RangeMatcher( filepath, ( 4, 9 ), ( 4, 13 ) ) ),
        'text': contains_string( "redefinition of 'test'" ),
        'fixit_available': False
      } )
    ) } )
  ) )
def Diagnostics_FixIt_Available_test(app):
    filepath = PathToTestFile('FixIt_Clang_cpp11.cpp')
    contents = ReadFile(filepath)
    request = {'contents': contents, 'filepath': filepath, 'filetype': 'cpp'}

    test = {'request': request, 'route': '/receive_messages'}
    response = RunAfterInitialized(app, test)

    pprint(response)

    assert_that(
        response,
        has_items(
            has_entries({
                'diagnostics':
                has_items(
                    has_entries({
                        'location':
                        LocationMatcher(filepath, 16, 3),
                        'text':
                        contains_string(
                            'Switch condition type \'A\' '
                            'requires explicit conversion to \'int\''),
                        'fixit_available':
                        False
                    }))
            })))
Example #15
0
def RunGetSemanticTest( app,
                        filepath,
                        filetype,
                        test,
                        command,
                        response = requests.codes.ok ):
  contents = ReadFile( filepath )
  common_args = {
    'completer_target' : 'filetype_default',
    'command_arguments': command,
    'line_num'         : 10,
    'column_num'       : 3,
    'filepath'         : filepath,
    'contents'         : contents,
    'filetype'         : filetype
  }

  args = test[ 0 ]
  if response == requests.codes.ok:
    if not isinstance( test[ 1 ], BaseMatcher ):
      expected = has_entry( 'message', contains_string( test[ 1 ] ) )
    else:
      expected = has_entry( 'message', test[ 1 ] )
  else:
    expected = test[ 1 ]

  request = common_args
  request.update( args )
  test = { 'request': request,
           'route': '/run_completer_command',
           'expect': { 'response': response,
                       'data': expected } }
  RunAfterInitialized( app, test )
def Diagnostics_MultipleMissingIncludes_test(app):
    filepath = PathToTestFile('multiple_missing_includes.cc')
    contents = ReadFile(filepath)
    request = {'contents': contents, 'filepath': filepath, 'filetype': 'cpp'}

    test = {'request': request, 'route': '/receive_messages'}
    response = RunAfterInitialized(app, test)

    pprint(response)

    assert_that(
        response,
        has_items(
            has_entries({
                'diagnostics':
                has_items(
                    has_entries({
                        'kind':
                        equal_to('ERROR'),
                        'location':
                        LocationMatcher(filepath, 1, 10),
                        'text':
                        equal_to("'first_missing_include' file not found"
                                 " [pp_file_not_found]"),
                        'fixit_available':
                        False
                    }))
            })))
Example #17
0
def Diagnostics_LocationExtent_MissingSemicolon_test(app):
    filepath = PathToTestFile('location_extent.cc')
    contents = ReadFile(filepath)
    request = {'contents': contents, 'filepath': filepath, 'filetype': 'cpp'}

    test = {'request': request, 'route': '/receive_messages'}
    response = RunAfterInitialized(app, test)

    pprint(response)

    assert_that(
        response,
        contains(
            has_entries({
                'diagnostics':
                has_items(
                    has_entries({
                        'kind':
                        equal_to('ERROR'),
                        'location':
                        LocationMatcher(filepath, 2, 9),
                        'location_extent':
                        RangeMatcher(filepath, (2, 9), (2, 9)),
                        'ranges':
                        contains(RangeMatcher(filepath, (2, 9), (2, 9))),
                        'text':
                        equal_to("Expected ';' at end of declaration list"),
                        'fixit_available':
                        False
                    }),
                    has_entries({
                        'kind':
                        equal_to('ERROR'),
                        'location':
                        LocationMatcher(filepath, 5, 1),
                        'location_extent':
                        RangeMatcher(filepath, (5, 1), (6, 11)),
                        'ranges':
                        contains(RangeMatcher(filepath, (5, 1), (6, 11))),
                        'text':
                        equal_to("Unknown type name 'multiline_identifier'"),
                        'fixit_available':
                        False
                    }),
                    has_entries({
                        'kind':
                        equal_to('ERROR'),
                        'location':
                        LocationMatcher(filepath, 8, 7),
                        'location_extent':
                        RangeMatcher(filepath, (8, 7), (8, 11)),
                        'ranges':
                        contains(RangeMatcher(filepath, (8, 7), (8, 11))),
                        'text':
                        equal_to('Constructor cannot have a return type'),
                        'fixit_available':
                        False
                    }))
            })))
Example #18
0
            def Test(app):
                extra_conf = os.path.join(tmp_dir, '.ycm_extra_conf.py')
                with open(extra_conf, 'w') as f:
                    f.write('''
def Settings( **kwargs ):
  return { 'flags': [ '-x', 'c++', '-I', 'ycm' ] }
  ''')

                try:
                    request_data = BuildRequest(filepath=os.path.join(
                        tmp_dir, 'foo.cpp'),
                                                filetype='cpp')
                    request_data['contents'] = ''
                    test = {'request': request_data}
                    RunAfterInitialized(app, test)
                    assert_that(
                        app.post_json('/debug_info', request_data).json,
                        has_entry(
                            'completer',
                            has_entries({
                                'name':
                                'C-family',
                                'servers':
                                contains(
                                    has_entries({
                                        'name':
                                        'Clangd',
                                        'is_running':
                                        True,
                                        'extras':
                                        contains(
                                            has_entries({
                                                'key': 'Server State',
                                                'value': 'Initialized',
                                            }),
                                            has_entries({
                                                'key': 'Project Directory',
                                                'value': tmp_dir,
                                            }),
                                            has_entries({
                                                'key': 'Settings',
                                                'value': '{}',
                                            }),
                                            has_entries({
                                                'key':
                                                'Compilation Command',
                                                'value':
                                                has_items(
                                                    '-x', 'c++', '-I', 'ycm')
                                            }),
                                        ),
                                    })),
                                'items':
                                empty()
                            })))
                finally:
                    os.remove(extra_conf)
Example #19
0
    def test_Diagnostics_MaximumDiagnosticsNumberExceeded(self, app):
        filepath = PathToTestFile('max_diagnostics.cc')
        contents = ReadFile(filepath)
        request = {
            'contents': contents,
            'filepath': filepath,
            'filetype': 'cpp'
        }

        test = {'request': request, 'route': '/receive_messages'}
        response = RunAfterInitialized(app, test)

        pprint(response)

        assert_that(
            response,
            contains_exactly(
                has_entries({
                    'diagnostics':
                    has_items(
                        has_entries({
                            'kind':
                            equal_to('ERROR'),
                            'location':
                            LocationMatcher(filepath, 3, 9),
                            'location_extent':
                            RangeMatcher(filepath, (3, 9), (3, 13)),
                            'ranges':
                            contains_exactly(
                                RangeMatcher(filepath, (3, 9), (3, 13))),
                            'text':
                            contains_string("Redefinition of 'test'"),
                            'fixit_available':
                            False
                        }),
                        has_entries({
                            'kind':
                            equal_to('ERROR'),
                            'location':
                            LocationMatcher(filepath, 1, 1),
                            'location_extent':
                            RangeMatcher(filepath, (1, 1), (1, 1)),
                            'ranges':
                            contains_exactly(
                                RangeMatcher(filepath, (1, 1), (1, 1))),
                            'text':
                            equal_to(
                                'Maximum number of diagnostics exceeded.'),
                            'fixit_available':
                            False
                        }))
                })))
Example #20
0
def DebugInfo_ExtraConf_UseDatabaseOverGlobal_test(app):
    with TemporaryTestDir() as tmp_dir:
        database = [{
            'directory': tmp_dir,
            'command': 'clang++ -x c++ -I test foo.cpp',
            'file': os.path.join(tmp_dir, 'foo.cpp'),
        }]

        with TemporaryClangProject(tmp_dir, database):
            request_data = BuildRequest(filepath=os.path.join(
                tmp_dir, 'foo.cpp'),
                                        filetype='cpp')
            request_data['contents'] = ''
            test = {'request': request_data}
            RunAfterInitialized(app, test)
            assert_that(
                app.post_json('/debug_info', request_data).json,
                has_entry(
                    'completer',
                    has_entries({
                        'name':
                        'C-family',
                        'servers':
                        contains_exactly(
                            has_entries({
                                'name':
                                'Clangd',
                                'is_running':
                                True,
                                'extras':
                                contains_exactly(
                                    has_entries({
                                        'key': 'Server State',
                                        'value': 'Initialized',
                                    }),
                                    has_entries({
                                        'key': 'Project Directory',
                                        'value': tmp_dir,
                                    }),
                                    has_entries({
                                        'key': 'Settings',
                                        'value': '{}',
                                    }),
                                    has_entries({
                                        'key': 'Compilation Command',
                                        'value': False
                                    }),
                                ),
                            })),
                        'items':
                        empty()
                    })))
Example #21
0
def RunFixItTest(app, line, column, lang, file_path, check):
    contents = ReadFile(file_path)

    language_options = {
        'cpp11': {
            'filetype': 'cpp',
        },
        'cuda': {
            'filetype': 'cuda',
        },
        'objective-c': {
            'filetype': 'objc',
        },
    }

    args = {
        'completer_target': 'filetype_default',
        'contents': contents,
        'filepath': file_path,
        'command_arguments': ['FixIt'],
        'line_num': line,
        'column_num': column,
    }
    args.update(language_options[lang])
    test = {'request': args, 'route': '/detailed_diagnostic'}
    # First get diags.
    diags = RunAfterInitialized(app, test)
    while 'message' in diags and 'diagnostics' in diags['message'].lower():
        receive_diags = {'request': args, 'route': '/receive_messages'}
        RunAfterInitialized(app, receive_diags)
        diags = RunAfterInitialized(app, test)

    results = app.post_json('/run_completer_command',
                            BuildRequest(**args)).json

    pprint(results)
    check(results)
Example #22
0
def RunGoToTest_all(app, folder, command, test):
    filepath = PathToTestFile(folder, test['req'][0])
    common_request = {
        'completer_target': 'filetype_default',
        'filepath': filepath,
        'command_arguments': [command],
        'contents': ReadFile(filepath),
        'filetype': 'cpp'
    }

    request = common_request
    request.update({
        'line_num': test['req'][1],
        'column_num': test['req'][2],
    })

    response = test['res']

    if isinstance(response, list):
        expect = {
            'response':
            requests.codes.ok,
            'data':
            contains(*[
                LocationMatcher(
                    PathToTestFile(folder, os.path.normpath(location[0])),
                    location[1], location[2]) for location in response
            ])
        }
    elif isinstance(response, tuple):
        expect = {
            'response':
            requests.codes.ok,
            'data':
            LocationMatcher(
                PathToTestFile(folder, os.path.normpath(response[0])),
                response[1], response[2])
        }
    else:
        expect = {
            'response': requests.codes.internal_server_error,
            'data': ErrorMatcher(RuntimeError, test['res'])
        }

    RunAfterInitialized(app, {
        'request': request,
        'route': '/run_completer_command',
        'expect': expect
    })
Example #23
0
def RunGoToTest_all( app, folder, command, test ):
  req = test[ 'req' ]
  filepath = PathToTestFile( folder, req[ 0 ] )
  request = {
    'completer_target' : 'filetype_default',
    'filepath'         : filepath,
    'contents'         : ReadFile( filepath ),
    'filetype'         : 'cpp',
    'line_num'         : req[ 1 ],
    'column_num'       : req[ 2 ],
    'command_arguments': [ command ] + ( [] if len( req ) < 4 else req[ 3 ] ),
  }

  response = test[ 'res' ]

  if isinstance( response, list ):
    expect = {
      'response': requests.codes.ok,
      'data': contains_exactly( *[
        LocationMatcher(
          PathToTestFile( folder, os.path.normpath( location[ 0 ] ) ),
          location[ 1 ],
          location[ 2 ],
          **( {} if len( location ) < 4 else location[ 3 ] )
        ) for location in response
      ] )
    }
  elif isinstance( response, tuple ):
    expect = {
      'response': requests.codes.ok,
      'data': LocationMatcher(
        PathToTestFile( folder, os.path.normpath( response[ 0 ] ) ),
        response[ 1 ],
        response[ 2 ],
        **( {} if len( response ) < 4 else response[ 3 ] )
      )
    }
  else:
    expect = {
      'response': requests.codes.internal_server_error,
      'data': ErrorMatcher( RuntimeError, test[ 'res' ] )
    }

  RunAfterInitialized( app, {
    'request': request,
    'route'  : '/run_completer_command',
    'expect' : expect
  } )
Example #24
0
def DebugInfo_ExtraConf_MacIncludeFlags_test(app):
    request_data = BuildRequest(filepath=PathToTestFile(
        'extra_conf', 'foo.cpp'),
                                filetype='cpp')
    test = {'request': request_data}
    RunAfterInitialized(app, test)
    assert_that(
        app.post_json('/debug_info', request_data).json,
        has_entry(
            'completer',
            has_entries({
                'name':
                'C-family',
                'servers':
                contains_exactly(
                    has_entries({
                        'name':
                        'Clangd',
                        'is_running':
                        True,
                        'extras':
                        contains_exactly(
                            has_entries({
                                'key': 'Server State',
                                'value': 'Initialized',
                            }),
                            has_entries({
                                'key': 'Project Directory',
                                'value': PathToTestFile('extra_conf'),
                            }),
                            has_entries({
                                'key': 'Settings',
                                'value': '{}',
                            }),
                            has_entries({
                                'key':
                                'Compilation Command',
                                'value':
                                has_items('-isystem', '-iframework')
                            }),
                        ),
                    })),
                'items':
                empty()
            })))
Example #25
0
def DebugInfo_ExtraConf_Global_test(app):
    request_data = BuildRequest(filepath=PathToTestFile('foo.cpp'),
                                contents='',
                                filetype='cpp')
    test = {'request': request_data}
    request_data['contents'] = ''
    RunAfterInitialized(app, test)
    assert_that(
        app.post_json('/debug_info', request_data).json,
        has_entry(
            'completer',
            has_entries({
                'name':
                'C-family',
                'servers':
                contains(
                    has_entries({
                        'name':
                        'Clangd',
                        'is_running':
                        True,
                        'extras':
                        contains(
                            has_entries({
                                'key': 'Server State',
                                'value': 'Initialized',
                            }),
                            has_entries({
                                'key': 'Project Directory',
                                'value': PathToTestFile(),
                            }),
                            has_entries({
                                'key': 'Settings',
                                'value': '{}',
                            }),
                            has_entries({
                                'key': 'Compilation Command',
                                'value': has_items('-I', 'test'),
                            }),
                        ),
                    })),
                'items':
                empty()
            })))
Example #26
0
 def Test(app):
     request_data = BuildRequest(filepath=os.path.join(
         tmp_dir, 'foo.cpp'),
                                 filetype='cpp')
     request_data['contents'] = ''
     test = {'request': request_data}
     RunAfterInitialized(app, test)
     assert_that(
         app.post_json('/debug_info', request_data).json,
         has_entry(
             'completer',
             has_entries({
                 'name':
                 'C-family',
                 'servers':
                 contains(
                     has_entries({
                         'name':
                         'Clangd',
                         'is_running':
                         True,
                         'extras':
                         contains(
                             has_entries({
                                 'key': 'Server State',
                                 'value': 'Initialized',
                             }),
                             has_entries({
                                 'key': 'Project Directory',
                                 'value': tmp_dir,
                             }),
                             has_entries({
                                 'key': 'Settings',
                                 'value': '{}',
                             }),
                             has_entries({
                                 'key': 'Compilation Command',
                                 'value': False
                             }),
                         ),
                     })),
                 'items':
                 empty()
             })))
Example #27
0
def Diagnostics_PragmaOnceWarningIgnored_test( app ):
  contents = """
#pragma once

struct Foo {
  int x;
  int y;
  int c;
  int d;
};
"""

  request = { 'contents': contents,
              'filepath': PathToTestFile( 'foo.h' ),
              'filetype': 'cpp' }
  test = { 'request': request, 'route': '/receive_messages' }
  response = RunAfterInitialized( app, test )
  assert_that( response, contains(
      has_entries( { 'diagnostics': empty() } ) ) )
Example #28
0
def DebugInfo_Initialized_test(app):
    request_data = BuildRequest(filepath=PathToTestFile('basic.cpp'),
                                filetype='cpp')
    test = {'request': request_data}
    RunAfterInitialized(app, test)
    assert_that(
        app.post_json('/debug_info', request_data).json,
        has_entry(
            'completer',
            has_entries({
                'name':
                'clangd',
                'servers':
                contains(has_entries({
                    'name': 'clangd',
                    'is_running': True
                })),
                'items':
                empty()
            })))
Example #29
0
def Subcommands_RefactorRename_test( app ):
  test = {
    'request': {
      'filetype': 'cpp',
      'completer_target': 'filetype_default',
      'contents': ReadFile( PathToTestFile( 'basic.cpp' ) ),
      'filepath': PathToTestFile( 'basic.cpp' ),
      'command_arguments': [ 'RefactorRename', 'Bar' ],
      'line_num': 17,
      'column_num': 4,
    },
    'expect': {
      'response': requests.codes.ok,
      'data': has_entries( {
        'fixits': contains( has_entries( {
          'chunks': contains(
            ChunkMatcher( 'Bar',
                          LineColMatcher( 1, 8 ),
                          LineColMatcher( 1, 11 ) ),
            ChunkMatcher( 'Bar',
                          LineColMatcher( 9, 3 ),
                          LineColMatcher( 9, 6 ) ),
            # NOTE: Bug in clangd. It returns the same chunk twice which is a
            # strict protocol violation.
            ChunkMatcher( 'Bar',
                          LineColMatcher( 15, 8 ),
                          LineColMatcher( 15, 11 ) ),
            ChunkMatcher( 'Bar',
                          LineColMatcher( 15, 8 ),
                          LineColMatcher( 15, 11 ) ),
            ChunkMatcher( 'Bar',
                          LineColMatcher( 17, 3 ),
                          LineColMatcher( 17, 6 ) )
          )
        } ) )
      } )
    },
    'route': '/run_completer_command'
  }
  RunAfterInitialized( app, test )
def Subcommands_GoTo_ZeroBasedLineAndColumn_test( app ):
  file_path = PathToTestFile( 'GoTo_Clang_ZeroBasedLineAndColumn_test.cc' )
  RunAfterInitialized( app, {
      'request': {
          'contents': ReadFile( file_path ),
          'completer_target': 'filetype_default',
          'command_arguments': [ 'GoToDefinition' ],
          'line_num': 10,
          'column_num': 3,
          'filetype': 'cpp',
          'filepath': file_path
      },
      'expect': {
          'response': requests.codes.ok,
          'data': {
              'filepath': os.path.abspath( file_path ),
              'line_num': 2,
              'column_num': 8
          }
      },
      'route': '/run_completer_command',
  } )