Beispiel #1
0
def Subcommands_GetType_Constant_test( app ):
  filepath = PathToTestFile( 'testy', 'GetTypeTestCase.cs' )
  with WrapOmniSharpServer( app, filepath ):
    contents = ReadFile( filepath )

    gettype_data = BuildRequest( completer_target = 'filetype_default',
                                 command_arguments = [ 'GetType' ],
                                 line_num = 4,
                                 column_num = 14,
                                 contents = contents,
                                 filetype = 'cs',
                                 filepath = filepath )

    eq_( {
      u'message': u"System.String"
    }, app.post_json( '/run_completer_command', gettype_data ).json )
def Subcommands_FixIt_SpanFileEdge_test(app):
    filepath = PathToTestFile('testy', 'FixItTestCase.cs')
    RunFixItTest(
        app, 1, 1,
        has_entries({
            'fixits':
            contains(
                has_entries({
                    'location':
                    LocationMatcher(filepath, 1, 1),
                    'chunks':
                    contains(
                        ChunkMatcher('System', LocationMatcher(filepath, 1, 7),
                                     LocationMatcher(filepath, 3, 18)))
                }))
        }))
Beispiel #3
0
    def test_Subcommands_GetType_VariableUsage(self, app):
        filepath = PathToTestFile('testy', 'GetTypeTestCase.cs')
        with WrapOmniSharpServer(app, filepath):
            contents = ReadFile(filepath)

            gettype_data = BuildRequest(completer_target='filetype_default',
                                        command_arguments=['GetType'],
                                        line_num=6,
                                        column_num=5,
                                        contents=contents,
                                        filetype='cs',
                                        filepath=filepath)

            response = app.post_json('/run_completer_command',
                                     gettype_data).json
            assert_that(response, has_entry('message', 'string str'))
def Subcommands_FixIt_RemoveSingleLine_test(app):
    filepath = PathToTestFile('testy', 'FixItTestCase.cs')
    RunFixItTest(
        app, 11, 1,
        has_entries({
            'fixits':
            contains(
                has_entries({
                    'location':
                    LocationMatcher(filepath, 11, 1),
                    'chunks':
                    contains(
                        ChunkMatcher('', LocationMatcher(filepath, 10, 20),
                                     LocationMatcher(filepath, 11, 30)))
                }))
        }))
def GetCompletions_Basic_test(app):
    filepath = PathToTestFile('testy', 'Program.cs')
    with WrapOmniSharpServer(app, filepath):
        contents = ReadFile(filepath)

        completion_data = BuildRequest(filepath=filepath,
                                       filetype='cs',
                                       contents=contents,
                                       line_num=10,
                                       column_num=12)
        response_data = app.post_json('/completions', completion_data).json
        assert_that(
            response_data['completions'],
            has_items(CompletionEntryMatcher('CursorLeft'),
                      CompletionEntryMatcher('CursorSize')))
        eq_(12, response_data['completion_start_column'])
Beispiel #6
0
def Subcommands_GetType_DocsIgnored_test( app ):
  filepath = PathToTestFile( 'testy', 'GetTypeTestCase.cs' )
  with WrapOmniSharpServer( app, filepath ):
    contents = ReadFile( filepath )

    gettype_data = BuildRequest( completer_target = 'filetype_default',
                                 command_arguments = [ 'GetType' ],
                                 line_num = 10,
                                 column_num = 34,
                                 contents = contents,
                                 filetype = 'cs',
                                 filepath = filepath )

    response = app.post_json( '/run_completer_command', gettype_data ).json
    assert_that( response, has_entry(
      'message', 'int GetTypeTestCase.an_int_with_docs' ) )
Beispiel #7
0
def Subcommands_GetType_DocsIgnored_test( app ):
  filepath = PathToTestFile( 'testy', 'GetTypeTestCase.cs' )
  with WrapOmniSharpServer( app, filepath ):
    contents = ReadFile( filepath )

    gettype_data = BuildRequest( completer_target = 'filetype_default',
                                 command_arguments = [ 'GetType' ],
                                 line_num = 9,
                                 column_num = 34,
                                 contents = contents,
                                 filetype = 'cs',
                                 filepath = filepath )

    eq_( {
      u'message': u"int GetTypeTestCase.an_int_with_docs;",
    }, app.post_json( '/run_completer_command', gettype_data ).json )
Beispiel #8
0
def Subcommands_GoToImplementationElseDeclaration_NoImplementation_test(app):
    filepath = PathToTestFile('testy', 'GotoTestCase.cs')
    with WrapOmniSharpServer(app, filepath):
        contents = ReadFile(filepath)

        goto_data = BuildRequest(
            completer_target='filetype_default',
            command_arguments=['GoToImplementationElseDeclaration'],
            line_num=18,
            column_num=13,
            contents=contents,
            filetype='cs',
            filepath=filepath)

        response = app.post_json('/run_completer_command', goto_data).json
        assert_that(response, LocationMatcher(filepath, 36, 8))
Beispiel #9
0
def Subcommands_StopServer_NoErrorIfNotStarted_test(app):
    filepath = PathToTestFile('testy', 'GotoTestCase.cs')
    # Don't wrap the server - we don't want to start it!
    app.post_json(
        '/run_completer_command',
        BuildRequest(filetype='cs',
                     filepath=filepath,
                     command_arguments=['StopServer']))

    request_data = BuildRequest(filetype='cs', filepath=filepath)
    assert_that(
        app.post_json('/debug_info', request_data).json,
        has_entry(
            'completer',
            has_entry('servers',
                      contains_exactly(has_entry('is_running', False)))))
Beispiel #10
0
def Diagnostics_MaximumDiagnosticsNumberExceeded_test(app):
    filepath = PathToTestFile('testy', 'MaxDiagnostics.cs')
    contents = ReadFile(filepath)

    event_data = BuildRequest(filepath=filepath,
                              event_name='FileReadyToParse',
                              filetype='cs',
                              contents=contents)

    app.post_json('/event_notification', event_data).json
    WaitUntilCsCompleterIsReady(app, filepath)

    event_data = BuildRequest(filepath=filepath,
                              event_name='FileReadyToParse',
                              filetype='cs',
                              contents=contents)

    results = app.post_json('/event_notification', event_data).json

    assert_that(
        results,
        contains(
            has_entries({
                'kind':
                equal_to('ERROR'),
                'text':
                contains_string("The type 'MaxDiagnostics' already contains "
                                "a definition for 'test'"),
                'location':
                LocationMatcher(filepath, 4, 16),
                'location_extent':
                RangeMatcher(filepath, (4, 16), (4, 20))
            }),
            has_entries({
                'kind':
                equal_to('ERROR'),
                'text':
                contains_string('Maximum number of diagnostics exceeded.'),
                'location':
                LocationMatcher(filepath, 1, 1),
                'location_extent':
                RangeMatcher(filepath, (1, 1), (1, 1)),
                'ranges':
                contains(RangeMatcher(filepath, (1, 1), (1, 1)))
            })))

    StopCompleterServer(app, 'cs', filepath)
Beispiel #11
0
def StopServer_KeepLogFiles(app, keeping_log_files):
    with UserOption('server_keep_logfiles', keeping_log_files):
        filepath = PathToTestFile('testy', 'GotoTestCase.cs')
        contents = ReadFile(filepath)
        event_data = BuildRequest(filepath=filepath,
                                  filetype='cs',
                                  contents=contents,
                                  event_name='FileReadyToParse')

        app.post_json('/event_notification', event_data)
        WaitUntilOmniSharpServerReady(app, filepath)

        event_data = BuildRequest(filetype='cs', filepath=filepath)

        debuginfo = app.post_json('/debug_info', event_data).json

        log_files_match = re.search("^OmniSharp logfiles:\n(.*)\n(.*)",
                                    debuginfo, re.MULTILINE)
        stdout_logfiles_location = log_files_match.group(1)
        stderr_logfiles_location = log_files_match.group(2)

        try:
            ok_(os.path.exists(stdout_logfiles_location),
                "Logfile should exist at {0}".format(stdout_logfiles_location))
            ok_(os.path.exists(stderr_logfiles_location),
                "Logfile should exist at {0}".format(stderr_logfiles_location))
        finally:
            StopOmniSharpServer(app, filepath)

        if keeping_log_files:
            ok_(
                os.path.exists(stdout_logfiles_location),
                "Logfile should still exist at "
                "{0}".format(stdout_logfiles_location))
            ok_(
                os.path.exists(stderr_logfiles_location),
                "Logfile should still exist at "
                "{0}".format(stderr_logfiles_location))
        else:
            ok_(
                not os.path.exists(stdout_logfiles_location),
                "Logfile should no longer exist at "
                "{0}".format(stdout_logfiles_location))
            ok_(
                not os.path.exists(stderr_logfiles_location),
                "Logfile should no longer exist at "
                "{0}".format(stderr_logfiles_location))
Beispiel #12
0
def Diagnostics_MaximumDiagnosticsNumberExceeded_test(app):
    filepath = PathToTestFile('testy', 'MaxDiagnostics.cs')
    contents = ReadFile(filepath)

    event_data = BuildRequest(filepath=filepath,
                              event_name='FileReadyToParse',
                              filetype='cs',
                              contents=contents)

    app.post_json('/event_notification', event_data).json
    WaitUntilCsCompleterIsReady(app, filepath, False)

    event_data = BuildRequest(filepath=filepath,
                              event_name='FileReadyToParse',
                              filetype='cs',
                              contents=contents)

    results = app.post_json('/event_notification', event_data).json

    assert_that(
        results,
        contains_exactly(
            has_entries({
                'kind':
                equal_to('ERROR'),
                'text':
                contains_string("A namespace cannot directly "
                                "contain members such as fields or methods"),
                'location':
                LocationMatcher(filepath, 1, 1),
                'location_extent':
                RangeMatcher(filepath, (1, 1), (1, 6))
            }),
            has_entries({
                'kind':
                equal_to('ERROR'),
                'text':
                contains_string('Maximum number of diagnostics exceeded.'),
                'location':
                LocationMatcher(filepath, 1, 1),
                'location_extent':
                RangeMatcher(filepath, (1, 1), (1, 1)),
                'ranges':
                contains_exactly(RangeMatcher(filepath, (1, 1), (1, 1)))
            })))

    StopCompleterServer(app, 'cs', filepath)
def Subcommands_FixIt_AddTextInLine_test(app):
    filepath = PathToTestFile('testy', 'FixItTestCase.cs')
    RunFixItTest(
        app, 9, 1,
        has_entries({
            'fixits':
            contains(
                has_entries({
                    'location':
                    LocationMatcher(filepath, 9, 1),
                    'chunks':
                    contains(
                        ChunkMatcher(', StringComparison.Ordinal',
                                     LocationMatcher(filepath, 9, 29),
                                     LocationMatcher(filepath, 9, 29)))
                }))
        }))
def Subcommands_FixIt_MultipleLines_test(app):
    filepath = PathToTestFile('testy', 'FixItTestCase.cs')
    RunFixItTest(
        app, 19, 1,
        has_entries({
            'fixits':
            contains(
                has_entries({
                    'location':
                    LocationMatcher(filepath, 19, 1),
                    'chunks':
                    contains(
                        ChunkMatcher('return On',
                                     LocationMatcher(filepath, 20, 13),
                                     LocationMatcher(filepath, 21, 35)))
                }))
        }))
Beispiel #15
0
def GetCompletions_ForcedReturnsResults_test( app ):
  filepath = PathToTestFile( 'testy', 'ContinuousTest.cs' )
  with WrapOmniSharpServer( app, filepath ):
    contents = ReadFile( filepath )

    completion_data = BuildRequest( filepath = filepath,
                                    filetype = 'cs',
                                    contents = contents,
                                    line_num = 9,
                                    column_num = 21,
                                    force_semantic = True,
                                    query = 'Date' )
    response_data = app.post_json( '/completions', completion_data ).json

    assert_that( response_data[ 'completions' ],
                 has_items( CompletionEntryMatcher( 'String' ),
                            CompletionEntryMatcher( 'StringBuilder' ) ) )
def Subcommands_FixIt_ReplaceTextInLine_test(app):
    filepath = PathToTestFile('testy', 'FixItTestCase.cs')
    RunFixItTest(
        app, 10, 1,
        has_entries({
            'fixits':
            contains(
                has_entries({
                    'location':
                    LocationMatcher(filepath, 10, 1),
                    'chunks':
                    contains(
                        ChunkMatcher('const int',
                                     LocationMatcher(filepath, 10, 13),
                                     LocationMatcher(filepath, 10, 16)))
                }))
        }))
Beispiel #17
0
def Subcommands_GoToReferences_Basic_test( app ):
  filepath = PathToTestFile( 'testy', 'GotoTestCase.cs' )
  with WrapOmniSharpServer( app, filepath ):
    contents = ReadFile( filepath )

    goto_data = BuildRequest(
      completer_target = 'filetype_default',
      command_arguments = [ 'GoToReferences' ],
      line_num = 21,
      column_num = 29,
      contents = contents,
      filetype = 'cs',
      filepath = filepath
    )

    response = app.post_json( '/run_completer_command', goto_data ).json
    assert_that( response, LocationMatcher( filepath, 21, 15 ) )
def GetCompletions_DoesntStartWithAmbiguousMultipleSolutions_test(app):
    filepath = PathToTestFile('testy-multiple-solutions',
                              'solution-not-named-like-folder', 'testy',
                              'Program.cs')
    contents = ReadFile(filepath)
    event_data = BuildRequest(filepath=filepath,
                              filetype='cs',
                              contents=contents,
                              event_name='FileReadyToParse')

    assert_that(
        calling(app.post_json).with_args('/event_notification', event_data),
        raises(AppError, 'Autodetection of solution file failed'),
        "The Omnisharp server started, despite us not being able to find a "
        "suitable solution file to feed it. Did you fiddle with the solution "
        "finding code in cs_completer.py? Hopefully you've enhanced it: you need "
        "to update this test then :)")
def DebugInfo_ServerIsRunning_test(app):
    filepath = PathToTestFile('testy', 'Program.cs')
    contents = ReadFile(filepath)
    event_data = BuildRequest(filepath=filepath,
                              filetype='cs',
                              contents=contents,
                              event_name='FileReadyToParse')

    app.post_json('/event_notification', event_data)
    WaitUntilCompleterServerReady(app, 'cs')

    request_data = BuildRequest(filepath=filepath, filetype='cs')
    assert_that(
        app.post_json('/debug_info', request_data).json,
        has_entry(
            'completer',
            has_entries({
                'name':
                'C#',
                'servers':
                contains_exactly(
                    has_entries({
                        'name':
                        'OmniSharp',
                        'is_running':
                        True,
                        'executable':
                        instance_of(str),
                        'pid':
                        instance_of(int),
                        'address':
                        instance_of(str),
                        'port':
                        instance_of(int),
                        'logfiles':
                        contains_exactly(instance_of(str), instance_of(str)),
                        'extras':
                        contains_exactly(
                            has_entries({
                                'key': 'solution',
                                'value': instance_of(str)
                            }))
                    })),
                'items':
                empty()
            })))
def GetCompletions_ForcedDividesCache_test(app):
    filepath = PathToTestFile('testy', 'ContinuousTest.cs')
    with WrapOmniSharpServer(app, filepath):
        contents = ReadFile(filepath)
        event_data = BuildRequest(filepath=filepath,
                                  filetype='cs',
                                  contents=contents,
                                  event_name='FileReadyToParse')

        app.post_json('/event_notification', event_data)

        completion_data = BuildRequest(filepath=filepath,
                                       filetype='cs',
                                       contents=contents,
                                       line_num=9,
                                       column_num=21,
                                       force_semantic=True,
                                       query='Date')
        results = app.post_json('/completions', completion_data).json

        assert_that(results['completions'], not (empty()))
        assert_that(results['errors'], empty())

        completion_data = BuildRequest(filepath=filepath,
                                       filetype='cs',
                                       contents=contents,
                                       line_num=9,
                                       column_num=21,
                                       force_semantic=False,
                                       query='Date')
        results = app.post_json('/completions', completion_data).json

        # There are no semantic completions. However, we fall back to identifier
        # completer in this case.
        assert_that(
            results,
            has_entries({
                'completions':
                has_item(
                    has_entries({
                        'insertion_text': 'String',
                        'extra_menu_info': '[ID]',
                    })),
                'errors':
                empty(),
            }))
Beispiel #21
0
def Subcommands_GetDoc_Variable_test( app ):
  filepath = PathToTestFile( 'testy', 'GetDocTestCase.cs' )
  with WrapOmniSharpServer( app, filepath ):
    contents = ReadFile( filepath )

    getdoc_data = BuildRequest( completer_target = 'filetype_default',
                                command_arguments = [ 'GetDoc' ],
                                line_num = 13,
                                column_num = 28,
                                contents = contents,
                                filetype = 'cs',
                                filepath = filepath )

    eq_( {
      'detailed_info': 'int GetDocTestCase.an_int;\n'
                       'an integer, or something',
    }, app.post_json( '/run_completer_command', getdoc_data ).json )
Beispiel #22
0
def Subcommands_RangeFormat_Works_test(app):
    filepath = PathToTestFile('testy', 'Program.cs')
    with WrapOmniSharpServer(app, filepath):
        contents = ReadFile(filepath)

        request = BuildRequest(command_arguments=['Format'],
                               line_num=11,
                               column_num=2,
                               contents=contents,
                               filetype='cs',
                               filepath=filepath)
        request['range'] = {
            'start': {
                'line_num': 8,
                'column_num': 1
            },
            'end': {
                'line_num': 11,
                'column_num': 4
            }
        }
        response = app.post_json('/run_completer_command', request).json
        print('completer response = ', response)
        assert_that(
            response,
            has_entries({
                'fixits':
                contains(
                    has_entries({
                        'location':
                        LocationMatcher(filepath, 11, 2),
                        'chunks':
                        contains(
                            ChunkMatcher('\n        ',
                                         LocationMatcher(filepath, 11, 1),
                                         LocationMatcher(filepath, 11, 3)),
                            ChunkMatcher('            ',
                                         LocationMatcher(filepath, 10, 1),
                                         LocationMatcher(filepath, 10, 4)),
                            ChunkMatcher('        {\n            ',
                                         LocationMatcher(filepath, 8, 1),
                                         LocationMatcher(filepath, 9, 4)),
                        )
                    }))
            }))
Beispiel #23
0
    def test_Subcommands_GoToReferences_MultipleReferences(self, app):
        filepath = PathToTestFile('testy', 'GotoTestCase.cs')
        with WrapOmniSharpServer(app, filepath):
            contents = ReadFile(filepath)

            goto_data = BuildRequest(completer_target='filetype_default',
                                     command_arguments=['GoToReferences'],
                                     line_num=18,
                                     column_num=4,
                                     contents=contents,
                                     filetype='cs',
                                     filepath=filepath)

            response = app.post_json('/run_completer_command', goto_data).json
            assert_that(
                response,
                contains_exactly(LocationMatcher(filepath, 17, 54),
                                 LocationMatcher(filepath, 18, 4)))
def GetCompletions_HasBothImportsAndNonImport_test(app):
    filepath = PathToTestFile('testy', 'ImportTest.cs')
    with WrapOmniSharpServer(app, filepath):
        contents = ReadFile(filepath)

        completion_data = BuildRequest(filepath=filepath,
                                       filetype='cs',
                                       contents=contents,
                                       line_num=9,
                                       column_num=12,
                                       force_semantic=True,
                                       query='Date')
        response_data = app.post_json('/completions', completion_data).json

        assert_that(
            response_data['completions'],
            has_items(CompletionEntryMatcher('DateTime'),
                      CompletionEntryMatcher('DateTimeStyles')))
Beispiel #25
0
def Subcommands_GetToImplementation_Unicode_test(app):
    filepath = PathToTestFile('testy', 'Unicode.cs')
    with WrapOmniSharpServer(app, filepath):
        contents = ReadFile(filepath)

        goto_data = BuildRequest(completer_target='filetype_default',
                                 command_arguments=['GoToImplementation'],
                                 line_num=48,
                                 column_num=44,
                                 contents=contents,
                                 filetype='cs',
                                 filepath=filepath)

        response = app.post_json('/run_completer_command', goto_data).json
        assert_that(
            response,
            contains(LocationMatcher(filepath, 49, 66),
                     LocationMatcher(filepath, 50, 62)))
Beispiel #26
0
def Subcommands_GoToReferences_InvalidLocation_test(app):
    filepath = PathToTestFile('testy', 'GotoTestCase.cs')
    with WrapOmniSharpServer(app, filepath):
        contents = ReadFile(filepath)

        goto_data = BuildRequest(completer_target='filetype_default',
                                 command_arguments=['GoToReferences'],
                                 line_num=3,
                                 column_num=1,
                                 contents=contents,
                                 filetype='cs',
                                 filepath=filepath)

        response = app.post_json('/run_completer_command',
                                 goto_data,
                                 expect_errors=True).json
        assert_that(response, ErrorMatcher(RuntimeError,
                                           'No references found'))
Beispiel #27
0
def Subcommands_RefactorRename_MissingNewName_test( app ):
  continuous_test = PathToTestFile( 'testy', 'ContinuousTest.cs' )
  with WrapOmniSharpServer( app, continuous_test ):
    contents = ReadFile( continuous_test )

    request = BuildRequest( completer_target = 'filetype_default',
                            command_arguments = [ 'RefactorRename' ],
                            line_num = 5,
                            column_num = 15,
                            contents = contents,
                            filetype = 'cs',
                            filepath = continuous_test )
    response = app.post_json( '/run_completer_command',
                              request,
                              expect_errors = True ).json
    assert_that( response, ErrorMatcher( ValueError,
                            'Please specify a new name to rename it to.\n'
                            'Usage: RefactorRename <new name>' ) )
Beispiel #28
0
def Subcommands_GetType_EmptyMessage_test( app ):
  filepath = PathToTestFile( 'testy', 'GetTypeTestCase.cs' )
  with WrapOmniSharpServer( app, filepath ):
    contents = ReadFile( filepath )

    gettype_data = BuildRequest( completer_target = 'filetype_default',
                                 command_arguments = [ 'GetType' ],
                                 line_num = 1,
                                 column_num = 1,
                                 contents = contents,
                                 filetype = 'cs',
                                 filepath = filepath )

    response = app.post_json( '/run_completer_command',
                              gettype_data,
                              expect_errors = True ).json
    assert_that( response, ErrorMatcher( RuntimeError,
                                         'No type info available.' ) )
Beispiel #29
0
def Subcommands_GetDoc_Function_test( app ):
  filepath = PathToTestFile( 'testy', 'GetDocTestCase.cs' )
  with WrapOmniSharpServer( app, filepath ):
    contents = ReadFile( filepath )

    getdoc_data = BuildRequest( completer_target = 'filetype_default',
                                command_arguments = [ 'GetDoc' ],
                                line_num = 33,
                                column_num = 27,
                                contents = contents,
                                filetype = 'cs',
                                filepath = filepath )

    response = app.post_json( '/run_completer_command', getdoc_data ).json
    assert_that( response, has_entry( 'detailed_info',
      'int GetDocTestCase.DoATest()\n'
      'Very important method.\n\nWith multiple lines of '
      'commentary\nAnd Format-\n-ting' ) )
Beispiel #30
0
def Subcommands_GetDoc_Invalid_test(app):
    filepath = PathToTestFile('testy', 'GetDocTestCase.cs')
    with WrapOmniSharpServer(app, filepath, wait_for_diags=False):
        contents = ReadFile(filepath)

        getdoc_data = BuildRequest(completer_target='filetype_default',
                                   command_arguments=['GetDoc'],
                                   line_num=1,
                                   column_num=1,
                                   contents=contents,
                                   filetype='cs',
                                   filepath=filepath)

        response = app.post_json('/run_completer_command',
                                 getdoc_data,
                                 expect_errors=True).json
        assert_that(response,
                    ErrorMatcher(RuntimeError, 'No documentation available.'))