Files
boost-ci/test/test.cpp
Alexander Grund ad98a10a48 Add some example throwing and catching an exception
In other repos Clang 14 with libc++ reports an ASAN failure:
> AddressSanitizer: alloc-dealloc-mismatch

- `free` in std::range_error::~range_error() (/lib/x86_64-linux-gnu/libc++abi.so.1...)
- Allocated by `new` in std::runtime_error::runtime_error(std::__1::basic_string<...> const&) (/lib/x86_64-linux-gnu/libc++.so.1...)
2022-06-05 19:52:23 +02:00

37 lines
1.1 KiB
C++

//
// Copyright (c) 2020 Mateusz Loskot <mateusz@loskot.net>
//
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Use some STL components just to quick check compilers
#include <string>
#include <map>
#include <vector>
// Use our dummy lib
#include <boost/boost-ci/boost_ci.hpp>
// And the usual test framwork
#include <boost/core/lightweight_test.hpp>
// Check that including a file from the same directory works
#include "test2.hpp"
int main()
{
const bool isMSVC = MSVC_VALUE;
std::map<std::string, std::vector<int> > map;
map["result"].push_back(boost::boost_ci::get_answer());
// Specifically crafted condition to check for coverage from MSVC and non MSVC builds
if(isMSVC)
{
BOOST_TEST_EQ(boost::boost_ci::get_answer(), 21);
} else
{
BOOST_TEST_EQ(boost::boost_ci::get_answer(), 42);
}
BOOST_TEST_EQ(map["result"].size(), 1u);
BOOST_TEST_THROWS(boost::boost_ci::get_answer(-1), boost::boost_ci::example_error);
return boost::report_errors();
}