Add tests in both travis and the Installation/tests.

This commit is contained in:
Maxime Gimeno 2020-07-22 12:44:18 +02:00
parent f504e45509
commit 241d477efd
2 changed files with 80 additions and 267 deletions

View File

@ -98,254 +98,17 @@ cd $ROOT
if [ "$ARG" = "Installation" ]
then
# ==-- CGAL installed in a non-default prefix, with the CGAL_Qt5 header-files. --==
cd $ROOT
mkdir build_test
cd build_test
mytime cmake -DCMAKE_INSTALL_PREFIX=install/ ..
mytime make install
# test install with minimal downstream example
mkdir installtest
cd installtest
touch main.cpp
mkdir build
# https://doc.cgal.org/latest/Triangulation_2/Triangulation_2_2draw_triangulation_2_8cpp-example.html and https://doc.cgal.org/latest/Algebraic_foundations/Algebraic_foundations_2interoperable_8cpp-example.html
cat << EOF > main.cpp
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Triangulation_2.h>
#include <CGAL/draw_triangulation_2.h>
#include <CGAL/basic.h>
#include <CGAL/Coercion_traits.h>
#include <CGAL/IO/io.h>
#include <fstream>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Triangulation_2<K> Triangulation;
typedef Triangulation::Point Point;
template <typename A, typename B>
typename CGAL::Coercion_traits<A,B>::Type
binary_func(const A& a , const B& b){
typedef CGAL::Coercion_traits<A,B> CT;
CGAL_static_assertion((CT::Are_explicit_interoperable::value));
typename CT::Cast cast;
return cast(a)*cast(b);
}
int main(int argc, char**) {
std::cout<< binary_func(double(3), int(5)) << std::endl;
std::cout<< binary_func(int(3), double(5)) << std::endl;
std::ifstream in("data/triangulation_prog1.cin");
std::istream_iterator<Point> begin(in);
std::istream_iterator<Point> end;
Triangulation t;
t.insert(begin, end);
if(argc == 3) // do not test Qt5 at runtime
CGAL::draw(t);
return EXIT_SUCCESS;
}
EOF
cat << EOF > "CMakeLists.txt"
cmake_minimum_required(VERSION 3.1...3.15)
find_package(CGAL COMPONENTS Qt5)
add_definitions(-DCGAL_USE_BASIC_VIEWER -DQT_NO_KEYWORDS)
add_executable(test main.cpp)
target_link_libraries(test PUBLIC CGAL::CGAL_Qt5)
EOF
cd build
mytime cmake -DCMAKE_INSTALL_PREFIX=../../install ..
make -j2
./test
cd ..
rm -rf ./build
cd ..
rm -rf ./install/*
# ==-- CGAL installed in a non-default prefix, without the CGAL_Qt5 header-files. --==
# https://doc.cgal.org/latest/Triangulation_2/Triangulation_2_2draw_triangulation_2_8cpp-example.html and https://doc.cgal.org/latest/Algebraic_foundations/Algebraic_foundations_2interoperable_8cpp-example.html
mytime cmake -DCMAKE_INSTALL_PREFIX=install/ -DCGAL_BUILD_THREE_DOC=TRUE -DWITH_CGAL_Qt5=OFF ..
mytime make install
# test install with minimal downstream example
cd installtest
touch main.cpp
mkdir build
cat << EOF > "CMakeLists.txt"
cmake_minimum_required(VERSION 3.1...3.15)
find_package(CGAL)
add_definitions(-DQT_NO_KEYWORDS)
add_executable(test main.cpp)
target_link_libraries(test PUBLIC CGAL::CGAL)
EOF
cat << EOF > main.cpp
#include <iostream>
#include <CGAL/Simple_cartesian.h>
typedef CGAL::Simple_cartesian<double> Kernel;
typedef Kernel::Point_2 Point_2;
typedef Kernel::Segment_2 Segment_2;
int main()
{
Point_2 p(1,1), q(10,10);
std::cout << "p = " << p << std::endl;
std::cout << "q = " << q.x() << " " << q.y() << std::endl;
std::cout << "sqdist(p,q) = "
<< CGAL::squared_distance(p,q) << std::endl;
Segment_2 s(p,q);
Point_2 m(5, 9);
std::cout << "m = " << m << std::endl;
std::cout << "sqdist(Segment_2(p,q), m) = "
<< CGAL::squared_distance(s,m) << std::endl;
std::cout << "p, q, and m ";
switch (CGAL::orientation(p,q,m)){
case CGAL::COLLINEAR:
std::cout << "are collinear\n";
break;
case CGAL::LEFT_TURN:
std::cout << "make a left turn\n";
break;
case CGAL::RIGHT_TURN:
std::cout << "make a right turn\n";
break;
}
std::cout << " midpoint(p,q) = " << CGAL::midpoint(p,q) << std::endl;
return 0;
}
EOF
cd build
mytime cmake -DCMAKE_INSTALL_PREFIX=../../install ..
make -j2
./test
cd ..
rm -rf ./build
cd ../..
rm -rf ./install_test
#==-- configure CGAL (as header-only), then use its build-directory as CGAL_DIR (we might want to support that use-case to be compatible with our usage with non-header-only, for CGAL-4.14) --==
mkdir config_dir
cd config_dir
mytime cmake ..
cd ..
mkdir test_dir
#==-- test install with minimal downstream example --==
cd test_dir
touch main.cpp
mkdir build
cat << EOF > main.cpp
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Triangulation_2.h>
#include <CGAL/draw_triangulation_2.h>
#include <CGAL/basic.h>
#include <CGAL/Coercion_traits.h>
#include <CGAL/IO/io.h>
#include <fstream>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Triangulation_2<K> Triangulation;
typedef Triangulation::Point Point;
template <typename A, typename B>
typename CGAL::Coercion_traits<A,B>::Type
binary_func(const A& a , const B& b){
typedef CGAL::Coercion_traits<A,B> CT;
CGAL_static_assertion((CT::Are_explicit_interoperable::value));
typename CT::Cast cast;
return cast(a)*cast(b);
}
int main(int argc, char**) {
std::cout<< binary_func(double(3), int(5)) << std::endl;
std::cout<< binary_func(int(3), double(5)) << std::endl;
std::ifstream in("data/triangulation_prog1.cin");
std::istream_iterator<Point> begin(in);
std::istream_iterator<Point> end;
Triangulation t;
t.insert(begin, end);
if(argc == 3) // do not test Qt5 at runtime
CGAL::draw(t);
return EXIT_SUCCESS;
}
EOF
cat << EOF > "CMakeLists.txt"
cmake_minimum_required(VERSION 3.1...3.15)
find_package(CGAL COMPONENTS Qt5)
add_definitions(-DCGAL_USE_BASIC_VIEWER -DQT_NO_KEYWORDS)
add_executable(test main.cpp)
target_link_libraries(test PUBLIC CGAL::CGAL_Qt5)
EOF
cd build
mytime cmake -DCGAL_DIR=$ROOT/config_dir ..
CGAL_PATH=$(cat CMakeCache.txt |grep -i cgal_dir)
if [ "$CGAL_PATH" != "CGAL_DIR:PATH=$ROOT/config_dir"]; then
exit 1;
fi
make -j2
./test
cd ../..
rm -rf config_dir test_dir
#==-- CGAL_DIR pointing to the directory containing Git/CGALConfig.cmake (for the Git layout only) --==
mkdir test_dir
cd test_dir
touch main.cpp
mkdir build
cat << EOF > main.cpp
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Triangulation_2.h>
#include <CGAL/draw_triangulation_2.h>
#include <CGAL/basic.h>
#include <CGAL/Coercion_traits.h>
#include <CGAL/IO/io.h>
#include <fstream>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Triangulation_2<K> Triangulation;
typedef Triangulation::Point Point;
template <typename A, typename B>
typename CGAL::Coercion_traits<A,B>::Type
binary_func(const A& a , const B& b){
typedef CGAL::Coercion_traits<A,B> CT;
CGAL_static_assertion((CT::Are_explicit_interoperable::value));
typename CT::Cast cast;
return cast(a)*cast(b);
}
int main(int argc, char**) {
std::cout<< binary_func(double(3), int(5)) << std::endl;
std::cout<< binary_func(int(3), double(5)) << std::endl;
std::ifstream in("data/triangulation_prog1.cin");
std::istream_iterator<Point> begin(in);
std::istream_iterator<Point> end;
Triangulation t;
t.insert(begin, end);
if(argc == 3) // do not test Qt5 at runtime
CGAL::draw(t);
return EXIT_SUCCESS;
}
EOF
cat << EOF > "CMakeLists.txt"
cmake_minimum_required(VERSION 3.1...3.15)
find_package(CGAL COMPONENTS Qt5)
add_definitions(-DCGAL_USE_BASIC_VIEWER -DQT_NO_KEYWORDS)
add_executable(test main.cpp)
target_link_libraries(test PUBLIC CGAL::CGAL_Qt5)
EOF
cd build
mytime cmake -DCGAL_DIR=$ROOT/CGALConfig.cmake ..
if [ "$CGAL_PATH" != "CGAL_DIR:PATH=$ROOT"]; then
exit 1;
fi
make -j2
./test
cd ../..
rm -rf config_dir test_dir
mkdir config_dir
cd config_dir
cmake -DWITH_tests=ON -DBUILD_TESTING=ON ..
ctest -j2 -R test_config_file --output-on-failure
cd ..
rm -rf ./config_dir
#==-- configure all CGAL with -DWITH_examples=ON -DWITH_demos=ON -DWITH_tests=ON, and then launch CTest on a few labels. --==
mkdir config_dir
cd config_dir
cmake -DWITH_examples=ON -DWITH_demos=ON -DWITH_tests=ON -DBUILD_TESTING=ON ..
ctest -j2 -L AABB_tree
ctest -j2 -L AABB_tree --output-on-failure
cd ..
rm -rf ./config_dir
exit 0

View File

@ -142,50 +142,100 @@ set_tests_properties(
test_find_package_version_fail-exact
PROPERTIES WILL_FAIL TRUE)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/non_standard_install)
find_package(CGAL COMPONENTS Qt5)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/non_standard_install)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/non_standard_build)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test_config_file)
set(TEST_SRC_FILE ${CMAKE_CURRENT_SOURCE_DIR}/test_configuration.cpp)
if(CGAL_Qt5_FOUND)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/non_standard_install_qt5)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/non_standard_build_qt5)
endif()#CGAL_Qt5_FOUND
#If ctest is ran from a global config, CGAL_SOURCE_DIR exists, but from Installation/test it doesn't. In that case, however, there is a CGAL_DIR.
if("${CGAL_SOURCE_DIR}" STREQUAL "")
set(CGAL_SOURCE_DIR ${CGAL_DIR})
endif()
configure_file(test_configuration.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/test_config_file/CMakeLists.txt @ONLY)
message("CMAKE_SOURCE_DIR is ${CMAKE_SOURCE_DIR}")
#test CGAL_DIR = source_dir (Git_root or CGAL-5.x dir.
add_test(NAME test_config_file
COMMAND ${CMAKE_COMMAND} -S ${CMAKE_CURRENT_BINARY_DIR}/test_config_file -B ${CMAKE_CURRENT_BINARY_DIR}/build-test_config_file -DCGAL_DO_NOT_WARN_ABOUT_CMAKE_BUILD_TYPE=ON -DCGAL_DIR=${CGAL_SOURCE_DIR} -DCGAL_GIVEN_DIR=${CGAL_SOURCE_DIR})
list(APPEND test_config_lst "test_config_file")
if(CGAL_TEST_SUITE)
if ( CGAL_BRANCH_BUILD )
#test CGAL_DIR = Git/Installation/lib/cmake/CGAL
add_test(NAME test_config_file_2
COMMAND ${CMAKE_COMMAND} -S ${CMAKE_CURRENT_BINARY_DIR}/test_config_file -B ${CMAKE_CURRENT_BINARY_DIR}/build-test_config_file_2 -DCGAL_DO_NOT_WARN_ABOUT_CMAKE_BUILD_TYPE=ON -DCGAL_DIR=${CGAL_SOURCE_DIR}/Installation/lib/cmake/CGAL/ -DCGAL_GIVEN_DIR=${CGAL_SOURCE_DIR}/Installation/lib/cmake/CGAL)
elseif(CGAL_TEST_SUITE)#CGAL_BRANCH_BUILD
#test CGAL_DIR = CGAL-5.x/lib/cmake/CGAL
add_test(NAME test_config_file_2
COMMAND ${CMAKE_COMMAND} -S ${CMAKE_CURRENT_BINARY_DIR}/test_config_file -B ${CMAKE_CURRENT_BINARY_DIR}/build-test_config_file_2 -DCGAL_DO_NOT_WARN_ABOUT_CMAKE_BUILD_TYPE=ON -DCGAL_DIR=${CGAL_SOURCE_DIR}/lib/cmake/CGAL/ -DCGAL_GIVEN_DIR=${CGAL_SOURCE_DIR}/lib/cmake/CGAL)
list(APPEND test_config_lst "test_config_file_2")
endif()#CGAL_TEST_SUITE
else()#CGAL_BRANCH_BUILD
#use the CGAL_DIR
add_test(NAME test_config_file_2
COMMAND ${CMAKE_COMMAND} -S ${CMAKE_CURRENT_BINARY_DIR}/test_config_file -B ${CMAKE_CURRENT_BINARY_DIR}/build-test_config_file_2 -DCGAL_DO_NOT_WARN_ABOUT_CMAKE_BUILD_TYPE=ON -DCGAL_DIR=${CGAL_SOURCE_DIR}/Installation/lib/cmake/CGAL/ -DCGAL_GIVEN_DIR=${CGAL_SOURCE_DIR}/Installation/lib/cmake/CGAL)
endif()#CGAL_BRANCH_BUILD
list(APPEND test_config_lst "test_config_file_2")
#configure cgal for a non standard install without qt5
add_test(NAME config_non_standard_cgal
COMMAND ${CMAKE_COMMAND} -S ${CGAL_DIR} -B ${CMAKE_CURRENT_BINARY_DIR}/non_standard_install -DCGAL_DO_NOT_WARN_ABOUT_CMAKE_BUILD_TYPE=ON -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test_config_file)
COMMAND ${CMAKE_COMMAND} -S ${CGAL_SOURCE_DIR} -B ${CMAKE_CURRENT_BINARY_DIR}/non_standard_build -DCGAL_DO_NOT_WARN_ABOUT_CMAKE_BUILD_TYPE=ON -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/non_standard_install)
#install cgal in the non standard place
add_test(NAME install_non_standard_cgal
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/non_standard_install --target "install")
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/non_standard_build --target "install" --config "$<CONFIG>")
#test CGAL_DIR=non standard place without cgal_qt5
add_test(NAME test_config_file_3
COMMAND ${CMAKE_COMMAND} -S ${CMAKE_CURRENT_BINARY_DIR}/test_config_file -B ${CMAKE_CURRENT_BINARY_DIR}/build-test_config_file_3 -DCGAL_DO_NOT_WARN_ABOUT_CMAKE_BUILD_TYPE=ON -DCGAL_DIR=${CMAKE_CURRENT_BINARY_DIR}/non_standard_install -DCGAL_GIVEN_DIR=${CMAKE_CURRENT_BINARY_DIR}/non_standard_install)
set_property(TEST test_config_file_3 APPEND PROPERTY LABELS "test_config_file_3")
set_property(TEST install_non_standard_cgal APPEND PROPERTY LABELS "test_config_file_3")
set_property(TEST config_non_standard_cgal APPEND PROPERTY LABELS "test_config_file_3")
set_property(TEST test_config_file_3 APPEND PROPERTY LABELS Installation_Tests "test_config_file_3")
list(APPEND test_config_lst "test_config_file_3")
if(CGAL_Qt5_FOUND)
#configure cgal for a non standard install with qt5
add_test(NAME config_non_standard_cgal_qt5
COMMAND ${CMAKE_COMMAND} -S ${CGAL_SOURCE_DIR} -B ${CMAKE_CURRENT_BINARY_DIR}/non_standard_build_qt5 -DCGAL_DO_NOT_WARN_ABOUT_CMAKE_BUILD_TYPE=ON -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/non_standard_install_qt5 -DWITH_CGAL_Qt5=ON)
#install cgal in the non standard place
add_test(NAME install_non_standard_cgal_qt5
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/non_standard_build_qt5 --target "install" --config "$<CONFIG>")
#test CGAL_DIR=non standard place with cgal_qt5
add_test(NAME test_config_file_4
COMMAND ${CMAKE_COMMAND} -S ${CMAKE_CURRENT_BINARY_DIR}/test_config_file -B ${CMAKE_CURRENT_BINARY_DIR}/build-test_config_file_4 -DCGAL_DO_NOT_WARN_ABOUT_CMAKE_BUILD_TYPE=ON -DCGAL_DIR=${CMAKE_CURRENT_BINARY_DIR}/non_standard_install -DCGAL_GIVEN_DIR=${CMAKE_CURRENT_BINARY_DIR}/non_standard_install)
set_property(TEST test_config_file_4 APPEND PROPERTY LABELS Installation_Tests "test_config_file_4")
list(APPEND test_config_lst "test_config_file_4")
endif()#CGAL_Qt5_FOUND
#test CGAL_DIR=non standard build
add_test(NAME test_config_file_5
COMMAND ${CMAKE_COMMAND} -S ${CMAKE_CURRENT_BINARY_DIR}/test_config_file -B ${CMAKE_CURRENT_BINARY_DIR}/build-test_config_file_5 -DCGAL_DO_NOT_WARN_ABOUT_CMAKE_BUILD_TYPE=ON -DCGAL_DIR=${CMAKE_CURRENT_BINARY_DIR}/non_standard_build -DCGAL_GIVEN_DIR=${CMAKE_CURRENT_BINARY_DIR}/non_standard_build)
set_property(TEST test_config_file_5 APPEND PROPERTY LABELS Installation_Tests "test_config_file_5")
list(APPEND test_config_lst "test_config_file_5")
foreach(tgt ${test_config_lst})
#add_custom_target(${tgt}_target)
add_test(NAME "${tgt}_SetupFixture" COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/build-${tgt})
add_test(NAME "${tgt}_CleanupFixture" COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_CURRENT_BINARY_DIR}/build-${tgt})
set_property(TEST ${tgt} APPEND PROPERTY DEPENDS "${tgt}_SetupFixture")
set_property(TEST "${tgt}_SetupFixture" APPEND PROPERTY FIXTURES_SETUP ${tgt})
set_property(TEST "${tgt}_CleanupFixture" APPEND PROPERTY FIXTURES_CLEANUP ${tgt})
set_property(TEST "${tgt}_CleanupFixture" APPEND PROPERTY DEPENDS ${tgt})
set_property(TEST "${tgt}_SetupFixture" APPEND PROPERTY LABELS ${tgt})
set_property(TEST "${tgt}_CleanupFixture" APPEND PROPERTY LABELS ${tgt})
set_property(TEST "${tgt}_SetupFixture" APPEND PROPERTY FIXTURES_SETUP ${tgt}_target)
set_property(TEST "${tgt}_CleanupFixture" APPEND PROPERTY FIXTURES_CLEANUP ${tgt}_target)
set_property(TEST "${tgt}_SetupFixture" APPEND PROPERTY LABELS Installation_Tests ${tgt}_target)
set_property(TEST "${tgt}_CleanupFixture" APPEND PROPERTY LABELS Installation_Tests ${tgt}_target)
set_property(TEST ${tgt} APPEND PROPERTY FIXTURES_REQUIRED ${tgt}_target)
endforeach()
set_property(TEST install_non_standard_cgal APPEND PROPERTY DEPENDS config_non_standard_cgal)
set_property(TEST test_config_file_3 APPEND PROPERTY DEPENDS install_non_standard_cgal)
set_property(TEST config_non_standard_cgal APPEND PROPERTY FIXTURES_SETUP test_config_file_3)
set_property(TEST install_non_standard_cgal APPEND PROPERTY FIXTURES_SETUP test_config_file_3)
set_property(TEST config_non_standard_cgal APPEND PROPERTY FIXTURES_SETUP test_config_file_3_target)
set_property(TEST install_non_standard_cgal APPEND PROPERTY FIXTURES_SETUP test_config_file_3_target)
set_property(TEST test_config_file_3 test_config_file_5 APPEND PROPERTY FIXTURES_REQUIRED test_config_file_3_target)
if(CGAL_Qt5_FOUND)
set_property(TEST install_non_standard_cgal_qt5 APPEND PROPERTY DEPENDS config_non_standard_cgal_qt5)
set_property(TEST config_non_standard_cgal_qt5 APPEND PROPERTY FIXTURES_SETUP test_config_file_4_target)
set_property(TEST install_non_standard_cgal_qt5 APPEND PROPERTY FIXTURES_SETUP test_config_file_4_target)
set_property(TEST test_config_file_4 APPEND PROPERTY FIXTURES_REQUIRED test_config_file_4_target)
endif()#CGAL_Qt5_FOUND