Skip to content

Commit 05fcc12

Browse files
committed
Add automated tests for math
1 parent a035ce3 commit 05fcc12

File tree

4 files changed

+9258
-2
lines changed

4 files changed

+9258
-2
lines changed

CMakeLists.txt

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
cmake_minimum_required(VERSION 2.8)
2+
project(chaiscript_extras)
3+
4+
# MINGW does not yet support C++11's concurrency features
5+
if(MINGW)
6+
option(MULTITHREAD_SUPPORT_ENABLED "Multithreaded Support Enabled" FALSE)
7+
else()
8+
option(MULTITHREAD_SUPPORT_ENABLED "Multithreaded Support Enabled" TRUE)
9+
endif()
10+
11+
12+
13+
if(CMAKE_COMPILER_IS_GNUCC)
14+
option(ENABLE_COVERAGE "Enable Coverage Reporting in GCC" FALSE)
15+
16+
if(ENABLE_COVERAGE)
17+
add_definitions(--coverage -O0)
18+
set(LINKER_FLAGS "${LINKER_FLAGS} --coverage")
19+
endif()
20+
endif()
21+
22+
if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
23+
option(ENABLE_THREAD_SANITIZER "Enable thread sanitizer testing in gcc/clang" FALSE)
24+
if(ENABLE_THREAD_SANITIZER)
25+
add_definitions(-fsanitize=thread -g)
26+
set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=thread")
27+
endif()
28+
29+
option(ENABLE_ADDRESS_SANITIZER "Enable address sanitizer testing in gcc/clang" FALSE)
30+
if(ENABLE_ADDRESS_SANITIZER)
31+
add_definitions(-fsanitize=address -g)
32+
set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=address")
33+
endif()
34+
35+
option(ENABLE_MEMORY_SANITIZER "Enable memory sanitizer testing in gcc/clang" FALSE)
36+
if(ENABLE_MEMORY_SANITIZER)
37+
add_definitions(-fsanitize=memory -g)
38+
set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=memory")
39+
endif()
40+
41+
option(ENABLE_UNDEFINED_SANITIZER "Enable undefined behavior sanitizer testing in gcc/clang" FALSE)
42+
if(ENABLE_UNDEFINED_SANITIZER)
43+
add_definitions(-fsanitize=undefined -g)
44+
set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=undefined")
45+
endif()
46+
47+
option(ENABLE_LTO "Enable Link Time Optimization" FALSE)
48+
49+
if (ENABLE_LTO)
50+
add_definitions(-flto)
51+
set(LINKER_FLAGS "${LINKER_FLAGS} -flto")
52+
endif()
53+
54+
option(PROFILE_GENERATE "Generate profile data" FALSE)
55+
if (PROFILE_GENERATE)
56+
add_definitions(-fprofile-generate)
57+
set(LINKER_FLAGS "${LINKER_FLAGS} -fprofile-generate")
58+
endif()
59+
60+
option(PROFILE_USE "Use profile data" FALSE)
61+
if (PROFILE_USE)
62+
add_definitions(-fprofile-use)
63+
set(LINKER_FLAGS "${LINKER_FLAGS} -fprofile-use")
64+
endif()
65+
66+
67+
endif()
68+
69+
70+
include(CTest)
71+
enable_testing()
72+
73+
74+
75+
if(CMAKE_COMPILER_IS_GNUCC)
76+
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
77+
78+
if(GCC_VERSION VERSION_LESS 4.8)
79+
set(CPP11_FLAG "-std=c++0x")
80+
else()
81+
set(CPP11_FLAG "-std=c++11")
82+
endif()
83+
else()
84+
set(CPP11_FLAG "-std=c++11")
85+
endif()
86+
87+
if(MSVC)
88+
add_definitions(/W4 /w44640)
89+
add_definitions(/bigobj)
90+
# Note on MSVC compiler flags.
91+
# The code base selective disables warnings as necessary when the compiler is complaining too much
92+
# about something that is perfectly valid, or there is simply no technical way around it
93+
# This particular warning, C4503 is in regards to the decorated names that MSVC generates internally.
94+
# The error did not come up until the move to C++11, but the compiler doesn't give enough information
95+
# to determine where the error is coming from, and the internet provides no real information for
96+
# how to workaround or fix the error. So I'm disabling it globally.
97+
add_definitions(/wd4503)
98+
else()
99+
add_definitions(-Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Wcast-qual -Wunused -Woverloaded-virtual -pedantic ${CPP11_FLAG})
100+
101+
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
102+
add_definitions(-Weverything -Wno-c++98-compat -Wno-documentation -Wno-switch-enum -Wno-weak-vtables -Wno-sign-conversion -Wno-missing-prototypes -Wno-padded -Wno-missing-noreturn)
103+
else()
104+
add_definitions(-Wnoexcept)
105+
endif()
106+
107+
if(APPLE)
108+
add_definitions(-Wno-sign-compare)
109+
endif()
110+
endif()
111+
112+
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
113+
option(USE_LIBCXX "Use clang's libcxx" TRUE)
114+
115+
if(USE_LIBCXX)
116+
add_definitions(-stdlib=libc++)
117+
set(LINKER_FLAGS "${LINKER_FLAGS} ${CPP11_FLAG} -stdlib=libc++")
118+
else()
119+
set(LINKER_FLAGS "${LINKER_FLAGS} ${CPP11_FLAG}")
120+
endif()
121+
elseif(CMAKE_COMPILER_IS_GNUCC)
122+
set(LINKER_FLAGS "${LINKER_FLAGS} ${CPP11_FLAG}")
123+
endif()
124+
125+
# limitations in MinGW require us to make an optimized build
126+
# for the sake of object sizes or something
127+
if(MINGW OR CYGWIN)
128+
add_definitions(-O3)
129+
endif()
130+
131+
132+
if(NOT MULTITHREAD_SUPPORT_ENABLED)
133+
add_definitions(-DCHAISCRIPT_NO_THREADS)
134+
endif()
135+
136+
if(CMAKE_HOST_UNIX)
137+
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Haiku")
138+
list(APPEND LIBS "dl")
139+
endif()
140+
141+
if(MULTITHREAD_SUPPORT_ENABLED)
142+
if(CMAKE_COMPILER_IS_GNUCC)
143+
execute_process(COMMAND ${CMAKE_C_COMPILER} --version OUTPUT_VARIABLE GCC_FULL_VERSION)
144+
if(GCC_FULL_VERSION MATCHES "4.8.1.*ubuntu")
145+
set(LINKER_FLAGS "${LINKER_FLAGS} -Wl,--no-as-needed -pthread")
146+
else()
147+
set(LINKER_FLAGS "${LINKER_FLAGS} -pthread")
148+
endif()
149+
else()
150+
set(LINKER_FLAGS "${LINKER_FLAGS} -pthread")
151+
endif()
152+
153+
add_definitions(-pthread)
154+
endif()
155+
156+
endif()
157+
158+
list(APPEND LIBS ${READLINE_LIB})
159+
160+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LINKER_FLAGS}")
161+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LINKER_FLAGS}")
162+
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${LINKER_FLAGS}")
163+
164+
165+
166+
167+
168+
set(CHAISCRIPT_BRANCH master)
169+
170+
file(DOWNLOAD https://github.com/ChaiScript/ChaiScript/archive/${CHAISCRIPT_BRANCH}.tar.gz "${CMAKE_BINARY_DIR}/chaiscript/chaiscript-${CHAISCRIPT_BRANCH}.tar.gz"
171+
INACTIVITY_TIMEOUT 180 TIMEOUT 180 TLS_VERIFY off)
172+
173+
execute_process(COMMAND ${CMAKE_COMMAND} -E tar -xf "${CMAKE_BINARY_DIR}/chaiscript/chaiscript-${CHAISCRIPT_BRANCH}.tar.gz" "${CMAKE_BINARY_DIR}/chaiscript"
174+
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/chaiscript")
175+
176+
include_directories("${CMAKE_BINARY_DIR}/chaiscript/ChaiScript-${CHAISCRIPT_BRANCH}/include")
177+
178+
179+
# Add catch tests macro
180+
macro(ADD_CATCH_TESTS executable)
181+
if (MSVC)
182+
file(TO_NATIVE_PATH "${QT_LIBRARY_DIR}" QT_LIB_PATH)
183+
set(NEWPATH "${QT_LIB_PATH};$ENV{PATH}")
184+
else()
185+
set(NEWPATH $ENV{PATH})
186+
endif()
187+
188+
get_target_property(target_files ${executable} SOURCES)
189+
190+
message("Files: ${target_files}")
191+
192+
foreach(source ${target_files})
193+
if(NOT "${source}" MATCHES "/moc_.*cxx")
194+
string(REGEX MATCH .*cpp source "${source}")
195+
if(source)
196+
file(READ "${source}" contents)
197+
string(REGEX MATCHALL "TEST_CASE\\([ ]*\"[^\"]+\"" found_tests ${contents})
198+
foreach(hit ${found_tests})
199+
message("Found Test: ${hit}")
200+
string(REGEX REPLACE "TEST_CASE\\([ ]*(\"[^\"]+\").*" "\\1" test_name ${hit})
201+
add_test(${test_name} "${executable}" ${test_name})
202+
set_tests_properties(${test_name} PROPERTIES TIMEOUT 660 ENVIRONMENT "PATH=${NEWPATH}")
203+
endforeach()
204+
endif()
205+
endif()
206+
endforeach()
207+
endmacro()
208+
209+
210+
211+
add_executable(math_test tests/math.cpp)
212+
target_link_libraries(math_test ${LIBS})
213+
ADD_CATCH_TESTS(math_test)
214+
215+

include/chaiscript/extras/math.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#include <cmath>
22
#include <memory>
33

4-
#include "../dispatchkit/dispatchkit.hpp"
5-
#include "../chaiscript.hpp"
4+
#include <chaiscript/chaiscript.hpp>
65

76
namespace chaiscript {
87
namespace extras {

0 commit comments

Comments
 (0)