Add integration test parsing the standard library
This commit is contained in:
parent
e355e7a653
commit
bcf65703d7
3 changed files with 146 additions and 22 deletions
|
|
@ -26,7 +26,8 @@ set(tests
|
||||||
cpp_template_parameter.cpp
|
cpp_template_parameter.cpp
|
||||||
cpp_type_alias.cpp
|
cpp_type_alias.cpp
|
||||||
cpp_variable.cpp
|
cpp_variable.cpp
|
||||||
visitor.cpp)
|
visitor.cpp
|
||||||
|
integration.cpp)
|
||||||
|
|
||||||
add_executable(cppast_test test.cpp test_parser.hpp ${tests})
|
add_executable(cppast_test test.cpp test_parser.hpp ${tests})
|
||||||
target_include_directories(cppast_test PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
|
target_include_directories(cppast_test PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
|
|
||||||
118
test/integration.cpp
Normal file
118
test/integration.cpp
Normal file
|
|
@ -0,0 +1,118 @@
|
||||||
|
// Copyright (C) 2017 Jonathan Müller <jonathanmueller.dev@gmail.com>
|
||||||
|
// This file is subject to the license terms in the LICENSE file
|
||||||
|
// found in the top-level directory of this distribution.
|
||||||
|
|
||||||
|
#include "test_parser.hpp"
|
||||||
|
|
||||||
|
#include <cppast/cpp_preprocessor.hpp>
|
||||||
|
|
||||||
|
using namespace cppast;
|
||||||
|
|
||||||
|
void parse_included_files(const cpp_entity_index& idx, const cpp_file& file)
|
||||||
|
{
|
||||||
|
for (auto& e : file)
|
||||||
|
{
|
||||||
|
if (e.kind() == cpp_entity_kind::include_directive_t)
|
||||||
|
{
|
||||||
|
auto path = static_cast<const cpp_include_directive&>(e).full_path();
|
||||||
|
parse_file(idx, path.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("stdlib", "[!hide][integration]")
|
||||||
|
{
|
||||||
|
auto code = R"(
|
||||||
|
// list of headers from: http://en.cppreference.com/w/cpp/header
|
||||||
|
|
||||||
|
//#include <cstdlib> -- problem with compiler built-in stuff on OSX
|
||||||
|
#include <csignal>
|
||||||
|
//#include <csetjmp> -- same as above
|
||||||
|
#include <cstdarg>
|
||||||
|
#include <typeinfo>
|
||||||
|
#include <typeindex>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <bitset>
|
||||||
|
#include <functional>
|
||||||
|
#include <utility>
|
||||||
|
#include <ctime>
|
||||||
|
#include <chrono>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <initializer_list>
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
|
#include <new>
|
||||||
|
#include <memory>
|
||||||
|
#include <scoped_allocator>
|
||||||
|
|
||||||
|
#include <climits>
|
||||||
|
#include <cfloat>
|
||||||
|
#include <cstdint>
|
||||||
|
//#include <cinttypes> -- missing types from C header (for some reason)
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
|
//#include <exception> -- weird issue with compiler built-in stuff
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <cassert>
|
||||||
|
#include <system_error>
|
||||||
|
#include <cerrno>
|
||||||
|
|
||||||
|
#include <cctype>
|
||||||
|
#include <cwctype>
|
||||||
|
#include <cstring>
|
||||||
|
#include <cwchar>
|
||||||
|
//#include <cuchar> -- not supported on CI
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <vector>
|
||||||
|
#include <deque>
|
||||||
|
#include <list>
|
||||||
|
#include <forward_list>
|
||||||
|
#include <set>
|
||||||
|
#include <map>
|
||||||
|
#include <unordered_set>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <stack>
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
|
//#include <cmath> -- non-conforming GCC extension with regards to constexpr
|
||||||
|
//#include <complex> -- weird double include issue under MSVC
|
||||||
|
#include <valarray>
|
||||||
|
#include <random>
|
||||||
|
#include <numeric>
|
||||||
|
#include <ratio>
|
||||||
|
//#include <cfenv> -- same issue with cinttypes
|
||||||
|
|
||||||
|
#include <iosfwd>
|
||||||
|
#include <ios>
|
||||||
|
#include <istream>
|
||||||
|
#include <ostream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <streambuf>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
#include <locale>
|
||||||
|
//#include <clocale> -- issue on OSX
|
||||||
|
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
|
#include <thread>
|
||||||
|
#include <mutex>
|
||||||
|
#include <future>
|
||||||
|
#include <condition_variable>
|
||||||
|
)";
|
||||||
|
|
||||||
|
cpp_entity_index idx;
|
||||||
|
auto file = parse(idx, "stdlib.cpp", code);
|
||||||
|
parse_included_files(idx, *file);
|
||||||
|
}
|
||||||
|
|
@ -23,13 +23,11 @@ inline void write_file(const char* name, const char* code)
|
||||||
file << code;
|
file << code;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::unique_ptr<cppast::cpp_file> parse(const cppast::cpp_entity_index& idx,
|
inline std::unique_ptr<cppast::cpp_file> parse_file(const cppast::cpp_entity_index& idx,
|
||||||
const char* name, const char* code)
|
const char* name)
|
||||||
{
|
{
|
||||||
using namespace cppast;
|
using namespace cppast;
|
||||||
|
|
||||||
write_file(name, code);
|
|
||||||
|
|
||||||
libclang_compile_config config;
|
libclang_compile_config config;
|
||||||
config.set_flags(cpp_standard::cpp_latest);
|
config.set_flags(cpp_standard::cpp_latest);
|
||||||
|
|
||||||
|
|
@ -42,6 +40,13 @@ inline std::unique_ptr<cppast::cpp_file> parse(const cppast::cpp_entity_index& i
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline std::unique_ptr<cppast::cpp_file> parse(const cppast::cpp_entity_index& idx,
|
||||||
|
const char* name, const char* code)
|
||||||
|
{
|
||||||
|
write_file(name, code);
|
||||||
|
return parse_file(idx, name);
|
||||||
|
}
|
||||||
|
|
||||||
class test_generator : public cppast::code_generator
|
class test_generator : public cppast::code_generator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue