コード例 #1
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()
                    })))
コード例 #2
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
                        }))
                })))
コード例 #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( '\n\n',
                          LineColMatcher( 12, 2 ),
                          LineColMatcher( 15, 1 ) ),
            ChunkMatcher( 'Bar',
                          LineColMatcher( 15,  8 ),
                          LineColMatcher( 15, 11 ) ),
            ChunkMatcher( ' ',
                          LineColMatcher( 15,  46 ),
                          LineColMatcher( 16,  1 ) ),
            ChunkMatcher( 'Bar',
                          LineColMatcher( 17, 3 ),
                          LineColMatcher( 17, 6 ) ),
            ChunkMatcher( '',
                          LineColMatcher( 17, 14 ),
                          LineColMatcher( 17, 15 ) ),
            ChunkMatcher( ' ',
                          LineColMatcher( 17, 17 ),
                          LineColMatcher( 17, 17 ) ),
            ChunkMatcher( ' ',
                          LineColMatcher( 17, 19 ),
                          LineColMatcher( 17, 19 ) ),
          )
        } ) )
      } )
    },
    'route': '/run_completer_command'
  }
  RunAfterInitialized( app, test )
コード例 #4
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)
コード例 #5
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
    })
コード例 #6
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
  } )
コード例 #7
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()
            })))
コード例 #8
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()
            })))
コード例 #9
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()
             })))
コード例 #10
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() } ) ) )
コード例 #11
0
ファイル: debug_info_test.py プロジェクト: zouhejing0000/ycmd
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()
            })))
コード例 #12
0
def Diagnostics_SimpleLocationExtent_test( 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(
    has_entries( { 'diagnostics': contains(
      has_entries( {
        'location_extent': RangeMatcher( filepath, ( 3, 3 ), ( 3, 6 ) )
      } )
    ) } ) ) )
コード例 #13
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 )
コード例 #14
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, 26 ) ),
        'ranges': contains( RangeMatcher( filepath, ( 2, 9 ), ( 2, 26 ) ) ),
        '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
      } )
    ) } )
  ) )
コード例 #15
0
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
      } )
    ) } )
  ) )
コード例 #16
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 ';'")))
コード例 #17
0
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" ),
        'fixit_available': False
      } )
    ) } )
  ) )
コード例 #18
0
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',
  } )
コード例 #19
0
ファイル: diagnostics_test.py プロジェクト: wooloow/ycmd
    def test_Diagnostics_ZeroBasedLineAndColumn(self, 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))
                        }))
                })))
コード例 #20
0
ファイル: debug_info_test.py プロジェクト: yixing-liu/ycmd
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,
                        'extras':
                        contains(
                            has_entries({
                                'key': 'Server State',
                                'value': 'Initialized',
                            }),
                            has_entries({
                                'key': 'Project Directory',
                                'value': PathToTestFile(),
                            }),
                            has_entries({
                                'key': 'Settings',
                                'value': '{}',
                            }),
                        ),
                    })),
                'items':
                empty()
            })))
コード例 #21
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")))
コード例 #22
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)
コード例 #23
0
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(*sorted([
                    'FixIt', 'Format', 'GetType', 'GetTypeImprecise', 'GoTo',
                    'GoToDeclaration', 'GoToDefinition', 'GoToImprecise',
                    'GoToInclude', 'GoToReferences', 'RefactorRename',
                    'RestartServer'
                ]))
            },
            'route': '/defined_subcommands',
        })
コード例 #24
0
ファイル: subcommands_test.py プロジェクト: navs82/ycmd
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 ) )
コード例 #25
0
def RunGoToIncludeTest(app, command, test):
    filepath = PathToTestFile('test-include', 'main.cpp')
    contents = ReadFile(filepath)
    request = {
        'completer_target': 'filetype_default',
        'filepath': filepath,
        'command_arguments': [command],
        'line_num': test['request'][0],
        'column_num': test['request'][1],
        'contents': contents,
        'filetype': 'cpp'
    }

    response = {
        'filepath': PathToTestFile('test-include', test['response']),
        'line_num': 1,
        'column_num': 1,
    }

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

    pprint(actual_response)
    eq_(response, actual_response)
コード例 #26
0
ファイル: debug_info_test.py プロジェクト: wooloow/ycmd
 def test_DebugInfo_ExtraConf_NotReturningFlags( self, app ):
   request_data = BuildRequest( filepath = PathToTestFile( 'extra_conf',
                                                           'xyz.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': PathToTestFile( 'extra_conf' ),
           } ),
           has_entries( {
             'key': 'Settings',
             'value': '{}',
           } ),
           has_entries( {
             'key': 'Compilation Command',
             'value': False
           } ),
         ),
       } ) ),
       'items': empty()
     } ) )
   )
コード例 #27
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
  }

  request = common_args
  request.update( test[ 0 ] )
  test = { 'request': request,
           'route': '/run_completer_command',
           'expect': { 'response': response,
                       'data': test[ 1 ] } }
  RunAfterInitialized( app, test )
コード例 #28
0
def Diagnostics_UpdatedOnBufferVisit_test(app):
    with TemporaryTestDir() as tmp_dir:
        source_file = os.path.join(tmp_dir, 'source.cpp')
        source_contents = """#include "header.h"
int main() {return S::h();}
"""
        with open(source_file, 'w') as sf:
            sf.write(source_contents)

        header_file = os.path.join(tmp_dir, 'header.h')
        old_header_content = """#pragma once
struct S{static int h();};
"""
        with open(header_file, 'w') as hf:
            hf.write(old_header_content)

        flags_file = os.path.join(tmp_dir, 'compile_flags.txt')
        flags_content = """-xc++"""
        with open(flags_file, 'w') as ff:
            ff.write(flags_content)

        messages_request = {
            'contents': source_contents,
            'filepath': source_file,
            'filetype': 'cpp'
        }

        test = {'request': messages_request, 'route': '/receive_messages'}
        response = RunAfterInitialized(app, test)
        assert_that(response,
                    contains_exactly(has_entries({'diagnostics': empty()})))

        # Overwrite header.cpp
        new_header_content = """#pragma once
  static int h();
  """
        with open(header_file, 'w') as f:
            f.write(new_header_content)

        # Send BufferSaved notification for the header
        file_save_request = {
            "event_name": "FileSave",
            "filepath": header_file,
            "filetype": 'cpp'
        }
        app.post_json('/event_notification', BuildRequest(**file_save_request))

        # Send BufferVisit notification
        buffer_visit_request = {
            "event_name": "BufferVisit",
            "filepath": source_file,
            "filetype": 'cpp'
        }
        app.post_json('/event_notification',
                      BuildRequest(**buffer_visit_request))
        # Assert diagnostics
        for message in PollForMessages(app, messages_request):
            if 'diagnostics' in message:
                assert_that(
                    message,
                    has_entries({
                        'diagnostics':
                        contains_exactly(
                            has_entries({
                                'kind':
                                equal_to('ERROR'),
                                'text':
                                "Use of undeclared identifier 'S' [undeclared_var_use]",
                                'ranges':
                                contains_exactly(
                                    RangeMatcher(contains_string(source_file),
                                                 (2, 20), (2, 21))),
                                'location':
                                LocationMatcher(contains_string(source_file),
                                                2, 20),
                                'location_extent':
                                RangeMatcher(contains_string(source_file),
                                             (2, 20), (2, 21))
                            }))
                    }))
                break

        # Restore original content
        with open(header_file, 'w') as f:
            f.write(old_header_content)

        # Send BufferSaved notification for the header
        file_save_request = {
            "event_name": "FileSave",
            "filepath": header_file,
            "filetype": 'cpp'
        }
        app.post_json('/event_notification', BuildRequest(**file_save_request))

        # Send BufferVisit notification
        app.post_json('/event_notification',
                      BuildRequest(**buffer_visit_request))

        # Assert no diagnostics
        for message in PollForMessages(app, messages_request):
            print(f'Message { pformat( message ) }')
            if 'diagnostics' in message:
                assert_that(message, has_entries({'diagnostics': empty()}))
                break

        # Assert no dirty files
        with open(header_file, 'r') as f:
            assert_that(f.read(), equal_to(old_header_content))
コード例 #29
0
def Diagnostics_CUDA_Kernel_test(app):
    filepath = PathToTestFile('cuda', 'kernel_call.cu')
    contents = ReadFile(filepath)
    request = {'contents': contents, 'filepath': filepath, 'filetype': 'cuda'}

    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, 59, 5),
                        'location_extent':
                        RangeMatcher(filepath, (59, 5), (59, 6)),
                        'ranges':
                        contains_exactly(
                            RangeMatcher(filepath, (59, 5), (59, 6))),
                        'text':
                        equal_to(
                            'Call to global function \'g1\' not configured'
                            ' [global_call_not_config]'),
                        'fixit_available':
                        False
                    }),
                    has_entries({
                        'kind':
                        equal_to('ERROR'),
                        'location':
                        LocationMatcher(filepath, 60, 9),
                        'location_extent':
                        RangeMatcher(filepath, (60, 9), (60, 12)),
                        'ranges':
                        contains_exactly(
                            RangeMatcher(filepath, (60, 9), (60, 12))),
                        'text':
                        equal_to(
                            'Too few execution configuration arguments to kernel '
                            'function call, expected at least 2, have 1'
                            ' [typecheck_call_too_few_args_at_least]'),
                        'fixit_available':
                        False
                    }),
                    has_entries({
                        'kind':
                        equal_to('ERROR'),
                        'location':
                        LocationMatcher(filepath, 61, 20),
                        'location_extent':
                        RangeMatcher(filepath, (61, 20), (61, 21)),
                        'ranges':
                        contains_exactly(
                            RangeMatcher(filepath, (61, 20), (61, 21))),
                        'text':
                        equal_to(
                            'Too many execution configuration arguments to '
                            'kernel function call, expected at most 4, have 5'
                            ' [typecheck_call_too_many_args_at_most]'),
                        'fixit_available':
                        False
                    }),
                    has_entries({
                        'kind':
                        equal_to('ERROR'),
                        'location':
                        LocationMatcher(filepath, 65, 15),
                        'location_extent':
                        RangeMatcher(filepath, (65, 15), (65, 16)),
                        'ranges':
                        contains_exactly(
                            RangeMatcher(filepath, (65, 15), (65, 16))),
                        'text':
                        equal_to('Kernel call to non-global function \'h1\''
                                 ' [kern_call_not_global_function]'),
                        'fixit_available':
                        False
                    }),
                    has_entries({
                        'kind':
                        equal_to('ERROR'),
                        'location':
                        LocationMatcher(filepath, 68, 15),
                        'location_extent':
                        RangeMatcher(filepath, (68, 15), (68, 16)),
                        'ranges':
                        contains_exactly(
                            RangeMatcher(filepath, (68, 15), (68, 16))),
                        'text':
                        equal_to(
                            "Kernel function type 'int (*)(int)' must have "
                            "void return type [kern_type_not_void_return]"),
                        'fixit_available':
                        False
                    }),
                    has_entries({
                        'kind':
                        equal_to('ERROR'),
                        'location':
                        LocationMatcher(filepath, 70, 8),
                        'location_extent':
                        RangeMatcher(filepath, (70, 8), (70, 18)),
                        'ranges':
                        contains_exactly(
                            RangeMatcher(filepath, (70, 8), (70, 18))),
                        'text':
                        equal_to("Use of undeclared identifier 'undeclared'"
                                 ' [undeclared_var_use]'),
                        'fixit_available':
                        False
                    }),
                )
            })))
コード例 #30
0
def StartClangd( app, filepath = PathToTestFile( 'basic.cpp' ) ):
  request_data = BuildRequest( filepath = filepath,
                               filetype = 'cpp' )
  test = { 'request': request_data }
  RunAfterInitialized( app, test )