YouCompleteMe/python/ycm/server/tests/diagnostics_test.py
Strahinja Val Markovic e424d75c42 Preventing traceback for detailed diagnostic
Previously we'd show a Python traceback if the user asked for a detailed
diagnostic in a file that wasn't supported by Clang (something written in Python
perhaps). Now we show an nice, far less scary message informing the user of
this.

Fixes #748.
2014-01-02 14:24:17 -08:00

125 lines
3.8 KiB
Python

#!/usr/bin/env python
#
# Copyright (C) 2013 Strahinja Val Markovic <val@markovic.io>
#
# This file is part of YouCompleteMe.
#
# YouCompleteMe is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# YouCompleteMe is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from ..server_utils import SetUpPythonPath
SetUpPythonPath()
from .test_utils import Setup, BuildRequest
from webtest import TestApp
from nose.tools import with_setup, eq_
from hamcrest import ( assert_that, contains, contains_string, has_entries,
has_entry, empty )
from ..responses import NoDiagnosticSupport
from .. import handlers
import bottle
import httplib
bottle.debug( True )
@with_setup( Setup )
def Diagnostics_ClangCompleter_ZeroBasedLineAndColumn_test():
app = TestApp( handlers.app )
contents = """
struct Foo {
int x // semicolon missing here!
int y;
int c;
int d;
};
"""
event_data = BuildRequest( compilation_flags = ['-x', 'c++'],
event_name = 'FileReadyToParse',
contents = contents,
filetype = 'cpp' )
results = app.post_json( '/event_notification', event_data ).json
assert_that( results,
contains(
has_entries( { 'text': contains_string( "expected ';'" ),
'line_num': 2,
'column_num': 7 } ) ) )
@with_setup( Setup )
def Diagnostics_ClangCompleter_PragmaOnceWarningIgnored_test():
app = TestApp( handlers.app )
contents = """
#pragma once
struct Foo {
int x;
int y;
int c;
int d;
};
"""
event_data = BuildRequest( compilation_flags = ['-x', 'c++'],
event_name = 'FileReadyToParse',
contents = contents,
filepath = '/foo.h',
filetype = 'cpp' )
response = app.post_json( '/event_notification', event_data )
assert_that( response.body, empty() )
@with_setup( Setup )
def GetDetailedDiagnostic_ClangCompleter_Works_test():
app = TestApp( handlers.app )
contents = """
struct Foo {
int x // semicolon missing here!
int y;
int c;
int d;
};
"""
diag_data = BuildRequest( compilation_flags = ['-x', 'c++'],
line_num = 2,
contents = contents,
filetype = 'cpp' )
event_data = diag_data.copy()
event_data.update( {
'event_name': 'FileReadyToParse',
} )
app.post_json( '/event_notification', event_data )
results = app.post_json( '/detailed_diagnostic', diag_data ).json
assert_that( results,
has_entry( 'message', contains_string( "expected ';'" ) ) )
@with_setup( Setup )
def GetDetailedDiagnostic_JediCompleter_DoesntWork_test():
app = TestApp( handlers.app )
diag_data = BuildRequest( contents = "foo = 5",
line_num = 1,
filetype = 'python' )
response = app.post_json( '/detailed_diagnostic',
diag_data,
expect_errors = True )
eq_( response.status_code, httplib.INTERNAL_SERVER_ERROR )
assert_that( response.json,
has_entry( 'exception',
has_entry( 'TYPE', NoDiagnosticSupport.__name__ ) ) )