Skip to content

Commit

Permalink
Enable Tests (#18)
Browse files Browse the repository at this point in the history
Enable TestBound in the CMakeFile of the test folder. In this version, we duplicate the CMake and CMake builds to download the Google Test Framework. This is required due to the fact that with the current option ExternalProject_Add the external project is only downloaded and installed during the first CMake build. We will change this in another PR to align it with the framework Eigen.

Tests that work on linux "obviously" do not work always with windows ¯_(ツ)_/¯, e.g., in debug mode.

The above test fail was due to the fact that (.*) regular expression is not supported, but .* is. The issue is only happening on Windows. In addition, the message looks a little bit different on Windows compared to Unix systems. The output differs in "inside Bound.\n Condition" (Unix) from "inside egoa::Bound::Bound.\n Condition" (Windows).

Commits:
* Enable TestBound in the CMakeFile
* Add TestBound testcases
* Remove Gurobi Library from TestBound
* Check whether Windows and MacOS find the include with that file
* Replace find_package with own find CMake for Google Testframework
* Downloads need an initial build then the data is on the disk
   Why:
           * add subdirectory in CMake requires the CMakeFile that is not downloaded yet
* Check sudo
* The error in the tests is due to wrong runtime library
* Does DLL works
* Check without debug
* Resolve libcpmt.lib(StlLCMapStringW.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in TestBound.obj [D:\a\egoa\egoa\build\tests\TestBound.vcxproj]
      See note in: https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html#variable:CMAKE_MSVC_RUNTIME_LIBRARY
* Fix a label mistake
* Add more verbose to the test output to understand what is going on
* Check if differentiation is necessary between Debug and Release
* Follow the error given in Windows debug death test "')' is unsupported"
        D:\a\egoa\egoa\external\GoogleTestFramework\googletest\src/gtest-port.cc(844): error: Failed
        Syntax error at index 42 in simple regular expression "(.*) assertion failed at (.*)Bound.hpp:(.*) inside Bound.
        Condition: minimum_ <= maximum_": ')' is unsupported.

        Running main() from D:\a\egoa\egoa\external\GoogleTestFramework\googletest\src\gtest_main.cc
        D:\a\egoa\egoa\tests\DataStructures\TestBound.cpp(70): error: Death test: {egoa::Bound<> bound (3,1);}
                Result: died but not with expected error.
        Expected: contains regular expression "(.*) assertion failed at (.*)Bound.hpp:(.*) inside Bound.\n Condition: minimum_ <= maximum_"
        Actual msg:
        [  DEATH   ] USAGE assertion failed at D:\a\egoa\egoa\include\DataStructures/Bound.hpp:48 inside egoa::Bound<double>::Bound.
        [  DEATH   ]  Condition: minimum_ <= maximum_

        [  FAILED  ] TestBound.DeathTest (146 ms)
* The output differs in "inside Bound.\n Condition" from "inside egoa::Bound<double>::Bound.\n Condition".
 D:\a\egoa\egoa\tests\DataStructures\TestBound.cpp(70): error: Death test: {egoa::Bound<> bound (3,1);}
                Result: died but not with expected error.
                Expected: contains regular expression ".* assertion failed at .*Bound.hpp:.* inside Bound.\n Condition: minimum_ <= maximum_"
        Actual msg:
        [  DEATH   ] USAGE assertion failed at D:\a\egoa\egoa\include\DataStructures/Bound.hpp:48 inside egoa::Bound<double>::Bound.
        [  DEATH   ]  Condition: minimum_ <= maximum_
  • Loading branch information
franziska-wegner committed Dec 8, 2023
1 parent c525119 commit 63a79b1
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 16 deletions.
67 changes: 65 additions & 2 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,69 @@ jobs:
-DEGOA_ENABLE_BONMIN=OFF
-DEGOA_ENABLE_BOOST=OFF
-DEGOA_ENABLE_CPLEX=OFF
-DEGOA_ENABLE_DOCUMENTATION=OFF
-DEGOA_ENABLE_EXCEPTION_HANDLING=ON
-DEGOA_ENABLE_GUROBI=OFF
-DEGOA_ENABLE_IPOPT=OFF
-DEGOA_ENABLE_OGDF=OFF
-DEGOA_ENABLE_OPENMP=OFF
-DEGOA_ENABLE_TESTS=OFF
-DEGOA_ENABLE_VERBOSE_MAKEFILE=ON
-DEGOA_PEDANTIC_AS_ERRORS=OFF
-DEGOA_PEDANTIC_MODE=ON
-DEGOA_TEST_FRAMEWORK=OfflineGoogleTestFramework
-DEGOA_TEST_FRAMEWORK_LOCATION=external/GoogleTestFramework
-DEGOA_THREAD_LIMIT=0
-DEGOA_WARNINGS_AS_ERRORS=ON
-DBONMIN_ROOT_DIR="NONE-DIR"
-DBoost_DIRECTORIES="/opt/homebrew/opt/boost/"
-DCOIN_INCLUDE_DIR="NONE-DIR"
-DCOIN_LIBRARY_DIR="NONE-DIR"
-DCPLEX_HOME="NONE-DIR"
-DGUROBI_ROOT_DIR="NONE-DIR"
-DOGDF_AUTOGEN_INCLUDE_DIR="NONE-DIR"
-DOGDF_INCLUDE_DIR="NONE-DIR"
-DOGDF_LIBRARY_DIR="NONE-DIR"
-DOPENMP_INCLUDES="/opt/homebrew/opt/llvm/include"
-DOPENMP_LIBRARIES="/opt/homebrew/opt/llvm/lib"
-S ${{ github.workspace }}
- name: Build (Unix)
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
if: ${{ !startsWith(matrix.os,'windows-') }}
run: sudo cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}

- name: Build (Windows)
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
if: startsWith(matrix.os,'windows-')
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}

# Downloads are done
- name: Configure CMake Full
env:
CMAKE_PREFIX_PATH: ${{env.Qt6_DIR}}
CMAKE_MODULE_PATH: ${{env.Qt6_DIR}}
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DBoost_NO_SYSTEM_PATHS=TRUE
-DEGOA_BUILD_TYPE=${{ matrix.build_type }}
-DEGOA_DOWNLOAD_CPPAD=OFF
-DEGOA_DOWNLOAD_EIGEN=OFF
-DEGOA_DOWNLOAD_GOOGLE_TEST_FRAMEWORK=OFF
-DEGOA_DOWNLOAD_IEEE=OFF
-DEGOA_DOWNLOAD_PYPSA_EUR=OFF
-DEGOA_DOWNLOAD_PYPSA_ITI_COLLABORATION=OFF
-DEGOA_DOWNLOAD_SCIGRID=OFF
-DEGOA_DOWNLOAD_WINDFARM=OFF
-DEGOA_ENABLE_ASSERTION=ON
-DEGOA_ENABLE_BONMIN=OFF
-DEGOA_ENABLE_BOOST=OFF
-DEGOA_ENABLE_CPLEX=OFF
-DEGOA_ENABLE_DOCUMENTATION=ON
-DEGOA_ENABLE_EXCEPTION_HANDLING=ON
-DEGOA_ENABLE_GUROBI=OFF
Expand Down Expand Up @@ -171,7 +234,7 @@ jobs:
-DOPENMP_LIBRARIES="/opt/homebrew/opt/llvm/lib"
-S ${{ github.workspace }}
- name: Build without Windows
- name: Build (Unix)
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
if: ${{ !startsWith(matrix.os,'windows-') }}
run: sudo cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
Expand All @@ -185,7 +248,7 @@ jobs:
working-directory: ${{ steps.strings.outputs.build-output-dir }}
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest --build-config ${{ matrix.build_type }}
run: ctest --verbose --build-config ${{ matrix.build_type }}

- name: Generate documentation
if: startsWith(matrix.os,'ubuntu-')
Expand Down
29 changes: 22 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,25 @@
#

cmake_minimum_required ( VERSION 3.13.1 )
# Required for CMAKE_MSVC_RUNTIME_LIBRARY
# https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html#variable:CMAKE_MSVC_RUNTIME_LIBRARY
cmake_policy(SET CMP0091 NEW)

project ( EGOA CXX )

# The version number.
set ( EGOA_VERSION_MAJOR 1 )
set ( EGOA_VERSION_MINOR 0 )

if ( ${EGOA_BUILD_TYPE} STREQUAL "Debug")
# Select the MSVC runtime library
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDebugDLL")
else ()
# Select the MSVC runtime library
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
endif ()
message ( STATUS "CMAKE_MSVC_RUNTIME_LIBRARY: ${CMAKE_MSVC_RUNTIME_LIBRARY} in ${EGOA_BUILD_TYPE}" )

####################################################################
# Input Parameter ##################################################
####################################################################
Expand Down Expand Up @@ -121,13 +134,15 @@ endif ( EGOA_ENABLE_BOOST )
# Google tests
if ( EGOA_ENABLE_TESTS )
include ( CTest )
if ( EGOA_TEST_FRAMEWORK STREQUAL "OfflineGoogleTestFramework" )
find_package ( GoogleTestFramework PATHS ${EGOA_TEST_FRAMEWORK_LOCATION})
elseif ( EGOA_TEST_FRAMEWORK STREQUAL "OnlineGoogleTestFramework" )
find_package ( GoogleTestFrameworkOnlineVersion )
else ()
find_package ( GoogleTestFramework )
endif ()
# Temp for all, maybe only Windows and MacOS
include(FindGoogleTestFramework)
# if ( EGOA_TEST_FRAMEWORK STREQUAL "OfflineGoogleTestFramework" )
# find_package ( GoogleTestFramework PATHS ${EGOA_TEST_FRAMEWORK_LOCATION})
# elseif ( EGOA_TEST_FRAMEWORK STREQUAL "OnlineGoogleTestFramework" )
# find_package ( GoogleTestFrameworkOnlineVersion )
# else ()
# find_package ( GoogleTestFramework )
# endif ()

# Add test coverage
# -coverage includes -fprofile-arcs -ftest-coverage while compiling and
Expand Down
6 changes: 3 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

# Now simply link against gtest or gtest_main as needed
# add_executable(TestBound DataStructures/TestBound.cpp)
# target_link_libraries(TestBound gtest gtest_main gmock_main EGOA ${GUROBI_LIBRARIES})
# add_test(NAME TestBound COMMAND TestBound)
add_executable(TestBound DataStructures/TestBound.cpp)
target_link_libraries(TestBound EGOA gtest gtest_main gmock_main) #${GUROBI_LIBRARIES}
add_test(NAME TestBound COMMAND TestBound)

####################################################################################
# Tests for QUEUE data structures ##################################################
Expand Down
74 changes: 74 additions & 0 deletions tests/DataStructures/TestBound.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* TestBound.cpp
*
* Created on: Jan 28, 2019
* Author: Franziska Wegner
*/

#include "TestBound.hpp"

#include "DataStructures/Bound.hpp"

#include "Helper/TestHelper.hpp"

// using ::testing::Eq;
// using ::testing::ByRef;
using ::testing::Ge;
using ::testing::Le;

namespace egoa::test {

TestBound::TestBound () {}

TestBound::~TestBound () {}

void TestBound::SetUp () {}

void TestBound::TearDown () {}

TEST_F ( TestBound, MinPositiveNos ) {
egoa::Bound<> bound(2.1, 2.5);

EXPECT_DOUBLE_EQ (2.1, bound.Minimum());
ASSERT_THAT(bound.Minimum(), Le(bound.Maximum()));

bound.Range(2.00000001, 2.00000005);

EXPECT_DOUBLE_EQ (2.00000001, bound.Minimum());
ASSERT_THAT(bound.Minimum(), Le(bound.Maximum()));
}

TEST_F ( TestBound, MaxPositiveNos ) {
egoa::Bound<> bound(2.1, 2.5);

EXPECT_DOUBLE_EQ (2.5, bound.Maximum());
ASSERT_THAT(bound.Maximum(), Ge(bound.Minimum()));

bound.Range(2.00000001, 2.00000005);
EXPECT_DOUBLE_EQ (2.00000005, bound.Maximum());
ASSERT_THAT(bound.Maximum(), Ge(bound.Minimum()));
}

TEST_F ( TestBound, DeathTest ) {
// ASSERT_DEATH({ Bound(3, 1);}, "terminating with uncaught exception of type BoundMismatch: Minimum > maximum: 3 < 1");
#ifdef EGOA_EXCEPTION_HANDLING
try {
egoa::Bound<> bound (3,1);
FAIL() << "Expected BoundMismatch";
}
catch(egoa::BoundMismatch const & err) {
EXPECT_EQ(err.What(), std::string("Minimum > maximum: 3 < 1"));
}
catch(...) {
FAIL() << "Expected BoundMismatch2";
}
#elif EGOA_ENABLE_ASSERTION
auto assertionString = buildAssertionString ( "Bound.hpp"
, "Bound"
, "Bound"
, "minimum_ <= maximum_");
ASSERT_DEATH( {egoa::Bound<> bound (3,1);}, assertionString );
#endif
}

} // namespace egoa::test
43 changes: 43 additions & 0 deletions tests/DataStructures/TestBound.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* TestBound.hpp
*
* Created on: Jan 28, 2019
* Author: Franziska Wegner
*/

#ifndef EGOA__TESTS__DATA_STRUCTURES__BOUND_HPP
#define EGOA__TESTS__DATA_STRUCTURES__BOUND_HPP

#include "gtest/gtest.h"
#include "gmock/gmock.h"

namespace egoa::test {

/**
* @brief Fixture for testing class Bound
*/
class TestBound : public ::testing::Test {

protected:

// You can do set-up work for each test here.
TestBound();

// You can do clean-up work that doesn't throw exceptions here.
virtual ~TestBound();

// If the constructor and destructor are not enough for setting up
// and cleaning up each test, you can define the following methods:

// Code here will be called immediately after the constructor (right
// before each test).
virtual void SetUp();

// Code here will be called immediately after each test (right
// before the destructor).
virtual void TearDown();
};

} // namespace egoa::test

#endif // EGOA__TESTS__DATA_STRUCTURES__BOUND_HPP
8 changes: 4 additions & 4 deletions tests/Helper/TestHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ Types::string buildAssertionString ( Types::string fileName
{
std::stringstream result;
#ifdef EGOA_ENABLE_ASSERTION
result << "(.*) assertion failed at (.*)"
result << ".* assertion failed at .*"
<< fileName
<< ":(.*) inside "
<< ":.* inside .*"
<< function
<< ".\n Condition: "
<< message
<< "";
#else // ifdef EGOA_ENABLE_ASSERTION
#ifdef EGOA_ENABLE_EXCEPTION_HANDLING
result << "(.*) exception at (.*)"
result << ".* exception at .*"
<< fileName
<< ":(.*) inside "
<< ":.* inside .*"
<< function
<< ".\n Condition: "
<< message
Expand Down

0 comments on commit 63a79b1

Please sign in to comment.