Skip to content
Snippets Groups Projects
Commit 7f0a2564 authored by Ben Cumming's avatar Ben Cumming Committed by GitHub
Browse files

Merge pull request #31 from halfflat/feature/own-asserts

Use library's own version of assert.
parents 92e424bd d2b0355c
No related branches found
No related tags found
No related merge requests found
cmake_minimum_required (VERSION 2.8) cmake_minimum_required(VERSION 2.8)
# project info # project info
project (cell_algorithms) project(cell_algorithms)
enable_language(CXX) enable_language(CXX)
# save incoming CXX flags for forwarding to modparser external project # save incoming CXX flags for forwarding to modparser external project
...@@ -19,6 +19,12 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS "YES") ...@@ -19,6 +19,12 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS "YES")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
# enable assertions?
set(WITH_ASSERTIONS OFF CACHE BOOL "enable EXPECTS() assertions in code")
if(WITH_ASSERTIONS)
add_definitions("-DWITH_ASSERTIONS")
endif()
# TBB support # TBB support
set(WITH_TBB OFF CACHE BOOL "use TBB for on-node threading" ) set(WITH_TBB OFF CACHE BOOL "use TBB for on-node threading" )
if(WITH_TBB) if(WITH_TBB)
......
...@@ -7,6 +7,7 @@ set(BASE_SOURCES ...@@ -7,6 +7,7 @@ set(BASE_SOURCES
parameter_list.cpp parameter_list.cpp
profiling/profiler.cpp profiling/profiler.cpp
swcio.cpp swcio.cpp
util/debug.cpp
) )
if(${WITH_MPI}) if(${WITH_MPI})
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <vector> #include <vector>
#include "util.hpp" #include "util.hpp"
#include "util/debug.hpp"
/* /*
* Some simple wrappers around stl algorithms to improve readability of code * Some simple wrappers around stl algorithms to improve readability of code
......
#include "cell.hpp" #include "cell.hpp"
#include "tree.hpp" #include "tree.hpp"
#include "util/debug.hpp"
namespace nest { namespace nest {
namespace mc { namespace mc {
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "segment.hpp" #include "segment.hpp"
#include "cell_tree.hpp" #include "cell_tree.hpp"
#include "stimulus.hpp" #include "stimulus.hpp"
#include "util/debug.hpp"
namespace nest { namespace nest {
namespace mc { namespace mc {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <vector/include/Vector.hpp> #include <vector/include/Vector.hpp>
#include "util.hpp" #include "util.hpp"
#include "util/debug.hpp"
namespace nest { namespace nest {
namespace mc { namespace mc {
......
#include "profiler.hpp" #include "profiler.hpp"
#include "util/debug.hpp"
#include <communication/global_policy.hpp> #include <communication/global_policy.hpp>
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "point.hpp" #include "point.hpp"
#include "swcio.hpp" #include "swcio.hpp"
#include "util.hpp" #include "util.hpp"
#include "util/debug.hpp"
namespace nest { namespace nest {
namespace mc { namespace mc {
......
...@@ -2,12 +2,6 @@ ...@@ -2,12 +2,6 @@
#include <vector/include/Vector.hpp> #include <vector/include/Vector.hpp>
#ifdef DEBUG
#define EXPECTS(expression) assert(expression)
#else
#define EXPECTS(expression)
#endif
/* /*
using memory::util::red; using memory::util::red;
using memory::util::yellow; using memory::util::yellow;
......
#include <cstdlib>
#include <iostream>
#include "util/debug.hpp"
bool nest::mc::util::failed_assertion(const char *assertion, const char *file,
int line, const char *func)
{
// Explicit flush, as we can't assume default buffering semantics on stderr/cerr,
// and abort() might not flush streams.
std::cerr << file << ':' << line << " " << func
<< ": Assertion `" << assertion << "' failed." << std::endl;
std::abort();
return false;
}
#pragma once
namespace nest {
namespace mc {
namespace util {
bool failed_assertion(const char *assertion, const char *file, int line, const char *func);
}
}
}
#ifdef WITH_ASSERTIONS
#ifdef __GNUC__
#define DEBUG_FUNCTION_NAME __PRETTY_FUNCTION__
#else
#define DEBUG_FUNCTION_NAME __func__
#endif
#define EXPECTS(condition) \
(void)((condition) || \
nest::mc::util::failed_assertion(#condition, __FILE__, __LINE__, DEBUG_FUNCTION_NAME))
#else
#define EXPECTS(condition)
#endif // def WITH_ASSERTIONS
#include <vector> #include <vector>
#include "gtest.h" #include "gtest.h"
#include "algorithms.hpp"
#include "util.hpp" #include "util.hpp"
#include "util/debug.hpp"
#include "../src/algorithms.hpp"
TEST(algorithms, sum) TEST(algorithms, sum)
{ {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment