mirror of https://gitlab.com/cppit/libclangmm
8 changed files with 96 additions and 1 deletions
@ -0,0 +1,20 @@
|
||||
#ifndef DIAGNOSTICS_H_ |
||||
#define DIAGNOSTICS_H_ |
||||
#include "TranslationUnit.h" |
||||
|
||||
namespace clang {
|
||||
class Diagnostic { |
||||
public: |
||||
class LocationData { |
||||
public: |
||||
unsigned line, column, offset; |
||||
}; |
||||
|
||||
unsigned severity; |
||||
std::string spelling; |
||||
std::string path; |
||||
LocationData start_location, end_location; |
||||
}; |
||||
} |
||||
|
||||
#endif // DIAGNOSTICS_H_
|
||||
@ -0,0 +1,32 @@
|
||||
#include <boost/test/unit_test.hpp> |
||||
#include "clangmm.h" |
||||
#include <iostream> |
||||
#include <fstream> |
||||
|
||||
using namespace std; |
||||
|
||||
BOOST_AUTO_TEST_CASE(diagnostics_test) { |
||||
std::string path("./case/main_error.cpp"); |
||||
|
||||
clang::Index index(0, 0); |
||||
|
||||
std::map<std::string, std::string> map_buffers; |
||||
ifstream ifs(path, ifstream::in); |
||||
stringstream ss; |
||||
ss << ifs.rdbuf(); |
||||
|
||||
map_buffers["./case/main_error.cpp"]=ss.str(); |
||||
|
||||
std::vector<std::string> args;
|
||||
clang::TranslationUnit tu(&index, path, args, map_buffers); |
||||
|
||||
auto diagnostics=tu.get_diagnostics(); |
||||
BOOST_CHECK(diagnostics.size()==1); |
||||
BOOST_CHECK(diagnostics[0].spelling=="use of undeclared identifier 'undeclared_variable'"); |
||||
BOOST_CHECK(diagnostics[0].path=="./case/main_error.cpp"); |
||||
BOOST_CHECK(diagnostics[0].severity==3); |
||||
BOOST_CHECK(diagnostics[0].start_location.line==5); |
||||
BOOST_CHECK(diagnostics[0].end_location.line==5); |
||||
BOOST_CHECK(diagnostics[0].start_location.column==16); |
||||
BOOST_CHECK(diagnostics[0].end_location.column==35);
|
||||
} |
||||
Loading…
Reference in new issue