Skip to content
Snippets Groups Projects
Commit d807531b authored by Daniel Hornung's avatar Daniel Hornung
Browse files

ENH: Unit test infrastructure works, at least locally.

parent c3fdcd45
No related branches found
No related tags found
1 merge request!1Initial functionality
Pipeline #11302 failed
......@@ -78,7 +78,7 @@ string(REGEX REPLACE "\n" "" OCTLIBS "${OCTLIBS}")
string(REGEX REPLACE " " ";" OCTLIBS "${OCTLIBS}")
set(MAOXDB_DIR "${PROJECT_SOURCE_DIR}/src/lib")
add_library(maoxdb STATIC "${MAOXDB_DIR}/test.cpp" "${MAOXDB_DIR}/maoxdb.cpp")
add_library(maoxdb STATIC "${MAOXDB_DIR}/maoxdb.cpp")
set_target_properties(maoxdb PROPERTIES PUBLIC_HEADER "${MAOXDB_DIR}/maoxdb.hpp")
target_compile_options(maoxdb PRIVATE "-I${OCTINCLUDEDIR}")
get_property(_MAOX_LIB_DIR TARGET maoxdb PROPERTY LIBRARY_OUTPUT_DIRECTORY)
......@@ -179,14 +179,19 @@ endif()
option(TEST "Unit test with gtest" OFF)
if(TEST)
enable_testing()
# cmake tests suffers from not being able to define dependencies, see
# https://stackoverflow.com/questions/733475, so we disable it for now.
# enable_testing()
add_custom_target(test
echo "[EE] \\`make test\\` does not exist, did you mean \\`make test_detailed\\`?"
COMMAND exit 1)
# append all the test cases here (file name without the ".cpp" suffix)
set(test_cases
test_utilities
)
# add special cmake functions for gtest
# add special cmake functions for gtest, (although they are not used yet, see above)
include(GoogleTest)
# `make testfiles` shall just build the tests, `make test` builds and runs the tests
# `make testfiles` just builds the tests, `make test_detailed` builds and runs the tests
add_custom_target(testfiles)
add_custom_target(test_detailed DEPENDS testfiles)
# loop over all test cases and add them to the test runner
......@@ -194,7 +199,7 @@ if(TEST)
math(EXPR len_test_cases "${len_test_cases} - 1")
foreach (i RANGE "${len_test_cases}")
list(GET test_cases ${i} test_case_name)
# Use this instead, once cmake 3.14 is available everywhere.
# Once cmake 3.14 is available everywhere, use the new `foreach` instead.
# foreach (test_case_name "${test_cases}")
message(STATUS "test_case_name: ${test_case_name}")
add_executable(${test_case_name} EXCLUDE_FROM_ALL test/${test_case_name}.cpp)
......@@ -209,12 +214,6 @@ if(TEST)
maoxdb ${CONAN_LIBS_CAOSDB} ${CONAN_LIBS_GTEST} ${CONAN_LIBS_BOOST})
target_link_directories(${test_case_name} PUBLIC ${OCTLIBDIR})
target_link_options(${test_case_name} PUBLIC ${OCTLIBS})
if(_LINTING)
set_target_properties(${test_case_name}
PROPERTIES
CXX_CLANG_TIDY "${_CMAKE_CXX_CLANG_TIDY};${_CMAKE_CXX_CLANG_TIDY_TEST_CHECKS}"
CXX_INCLUDE_WHAT_YOU_USE "${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE}")
endif()
message(STATUS "CMAKE_CURRENT_BINARY_DIR: ${CMAKE_CURRENT_BINARY_DIR}")
gtest_discover_tests(${test_case_name}
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
......
......@@ -26,6 +26,7 @@
*/
#include "maoxdb.hpp"
#include "mex.h"
#include "caosdb/status_code.h"
namespace maoxdb {
......
......@@ -4,7 +4,6 @@
#include "caosdb/exceptions.h"
#include "caosdb/status_code.h"
#include "mex.h"
#include "mexproto.h"
#include <string>
// Macros /////////////////////////////////////////////////////////////////////
......
#include "maoxdb.hpp"
#include "mex.h"
#include "mexproto.h"
namespace maoxdb {
void test() {
// do nothing.
auto *mx_str = mxCreateString("Hello World!");
}
} // namespace maoxdb
......@@ -2,7 +2,6 @@
#include "caosdb/constants.h" // for LIBCAOSDB_VERSION_MAJOR, LIBCAOSDB_VE...
#include "caosdb/info.h" // for VersionInfo
#include "mex.h" // for mxArray, mexFunction
#include "mexproto.h" // for mexPrintf, mxCreateString, mxGetChars
#include <cstring> // for strcmp
#include <memory> // for unique_ptr, __shared_ptr_access, shar...
#include <string> // for allocator, char_traits, operator+
......
......@@ -4,7 +4,6 @@
#include "caosdb/info.h" // for VersionInfo
#include "maoxdb.hpp" // caosDB utils for mex files
#include "mex.h" // for mxArray, mexFunction
#include "mexproto.h" // for mexPrintf, mxCreateString, mxGetChars
#include <cstring> // for strcmp
#include <memory> // for unique_ptr, __shared_ptr_access, shar...
#include <string> // for allocator, char_traits, operator+
......
......@@ -43,13 +43,19 @@ test_octave:
octave Run_Test.m
.PHONY: test_octave
# && make test || echo "Test(s) failed."; exit 1
test_cpp:
$(eval BUILD_DIR ::= $(shell mktemp -d build_XXXXXXXX))
cd $(BUILD_DIR) \
&& conan install ../.. -s "compiler.libcxx=libstdc++11" \
&& cmake -D TEST=On ../.. \
&& make test || echo "Test(s) failed."; exit 1
# && make test || make test_detailed || echo "Test(s) failed." ; exit 1
# rm -r $(BUILD_DIR)
&& make test_detailed \
|| echo "Test(s) failed."; exit 1
# Exit with error if tests fail.
# && make test || make test_detailed || echo "Test(s) failed." ; exit 1
# Cleanup if everything went fine.
rm -r $(BUILD_DIR)
.PHONY: test_cpp
......@@ -28,8 +28,8 @@ namespace maoxdb {
TEST(test_utilities, scalar_arrays) {
mxArray *uint64_scalar;
uint64_scalar = mxScalarUINT64(1);
EXPECT_TRUE(mxIsUint64(uint64_scalar));{
EXXPECT_EQ(mxGetNumberOfElements(uint64_scalar), 1);
EXPECT_TRUE(mxIsUint64(uint64_scalar));
EXPECT_EQ(mxGetNumberOfElements(uint64_scalar), 1);
EXPECT_EQ(*((UINT64_T *) mxGetData(uint64_scalar)), 1);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment