From 61c96a0808f7c7ba1beeb5db8cf4115acc1a1c25 Mon Sep 17 00:00:00 2001
From: ralfulrich <ralf.ulrich@kit.edu>
Date: Fri, 28 Dec 2018 11:39:02 +0100
Subject: [PATCH] added central macro for adding and configuring unit tests

---
 #.gitlab-ci.yml#                         | 37 ------------------------
 .gitlab-ci.yml                           |  8 ++++-
 CMakeModules/CorsikaUtilities.cmake      | 10 +++++++
 Environment/CMakeLists.txt               |  4 +--
 Framework/Cascade/CMakeLists.txt         |  6 +---
 Framework/Geometry/CMakeLists.txt        |  3 +-
 Framework/Logging/CMakeLists.txt         |  6 +---
 Framework/Particles/CMakeLists.txt       |  9 +-----
 Framework/ProcessSequence/CMakeLists.txt |  6 +---
 Framework/Random/CMakeLists.txt          |  4 +--
 Framework/StackInterface/CMakeLists.txt  |  2 +-
 Framework/Units/CMakeLists.txt           |  3 +-
 Framework/Utilities/CMakeLists.txt       |  3 +-
 Processes/NullModel/CMakeLists.txt       |  4 +--
 Processes/Sibyll/CMakeLists.txt          |  4 +--
 Processes/StackInspector/CMakeLists.txt  |  4 +--
 Processes/TrackWriter/CMakeLists.txt     |  3 +-
 Processes/TrackingLine/CMakeLists.txt    |  3 +-
 Stack/SuperStupidStack/CMakeLists.txt    |  6 +---
 19 files changed, 33 insertions(+), 92 deletions(-)
 delete mode 100644 #.gitlab-ci.yml#

diff --git a/#.gitlab-ci.yml# b/#.gitlab-ci.yml#
deleted file mode 100644
index fb8f6a95..00000000
--- a/#.gitlab-ci.yml#
+++ /dev/null
@@ -1,37 +0,0 @@
-image: ubuntu:bionic
-
-variables:
-  GIT_SSL_NO_VERIFY: "1"
-
-before_script:
-  - apt-get update --yes
-  - apt-get install --yes cmake libboost-dev libeigen3-dev python3 gfortran
-
-build:
-  stage: build
-  tags:
-    - run1
-  script:
-    - mkdir build
-    - cd build
-    - cmake .. 
-    - cmake --build .
-    - ctest -V
-
-# code_quality:
-#   image: docker:stable
-#   variables:
-#     DOCKER_DRIVER: overlay2
-#   allow_failure: true
-#   services:
-#     - docker:stable-dind
-#   script:
-#     - export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
-#     - docker run
-#         --env SOURCE_CODE="$PWD"
-#         --volume "$PWD":/code
-#         --volume /var/run/docker.sock:/var/run/docker.sock
-#         "registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
-#   artifacts:
-#     reports:
-#       codequality: gl-code-quality-report.json
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 7d470049..5cf0a781 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -22,7 +22,13 @@ build:
     paths:
       - build/test.log.gz
     when: on_failure
-
+    reports:
+      junit:
+        - */junit*.xml
+        - */*/junit*.xml
+        - */*/*/junit*.xml
+        - */*/*/*/junit*.xml
+        - */*/*/*/*/junit*.xml
 
 # code_quality:
 #   image: docker:stable
diff --git a/CMakeModules/CorsikaUtilities.cmake b/CMakeModules/CorsikaUtilities.cmake
index 0ba70d8f..abcebea9 100644
--- a/CMakeModules/CorsikaUtilities.cmake
+++ b/CMakeModules/CorsikaUtilities.cmake
@@ -78,3 +78,13 @@ macro (CORSIKA_ADD_FILES_ABSOLUTE varname)
     set ("${varname}" "${${varname}}" PARENT_SCOPE)
   endif()
 endmacro(CORSIKA_ADD_FILES_ABSOLUTE)
+
+
+
+#
+# central macro to activate unit tests in cmake
+#
+
+function (CORSIKA_ADD_TEST name)
+  add_test (NAME ${name} COMMAND ${name} -o junit-${name}.xml -r junit)
+endfunction (CORSIKA_ADD_TEST)
diff --git a/Environment/CMakeLists.txt b/Environment/CMakeLists.txt
index ca93c81c..c4083f6f 100644
--- a/Environment/CMakeLists.txt
+++ b/Environment/CMakeLists.txt
@@ -48,6 +48,4 @@ target_link_libraries (
   CORSIKAenvironment
   CORSIKAthirdparty # for catch2
   )
-
-add_test (NAME testGeometry COMMAND testGeometry)
-
+CORSIKA_ADD_TEST(testGeometry)
diff --git a/Framework/Cascade/CMakeLists.txt b/Framework/Cascade/CMakeLists.txt
index 8b832d21..3e51de61 100644
--- a/Framework/Cascade/CMakeLists.txt
+++ b/Framework/Cascade/CMakeLists.txt
@@ -59,8 +59,4 @@ target_link_libraries (
   CORSIKAunits
   CORSIKAthirdparty # for catch2
   )
-
-add_test (
-  NAME testCascade
-  COMMAND testCascade
-  )
+CORSIKA_ADD_TEST(testStackInterface)
diff --git a/Framework/Geometry/CMakeLists.txt b/Framework/Geometry/CMakeLists.txt
index 3e2a8e1d..4d708ff1 100644
--- a/Framework/Geometry/CMakeLists.txt
+++ b/Framework/Geometry/CMakeLists.txt
@@ -69,5 +69,4 @@ target_link_libraries (
   CORSIKAthirdparty # for catch2
   )
 
-add_test (NAME testGeometry COMMAND testGeometry)
-
+CORSIKA_ADD_TEST(testGeometry)
diff --git a/Framework/Logging/CMakeLists.txt b/Framework/Logging/CMakeLists.txt
index d7af35a8..f8b15035 100644
--- a/Framework/Logging/CMakeLists.txt
+++ b/Framework/Logging/CMakeLists.txt
@@ -47,9 +47,5 @@ target_link_libraries (
   CORSIKAlogging
   CORSIKAthirdparty # for catch2
   )
-
-add_test (
-  NAME testLogging
-  COMMAND testLogging
-  )
+CORSIKA_ADD_TEST (testLogging)
 
diff --git a/Framework/Particles/CMakeLists.txt b/Framework/Particles/CMakeLists.txt
index 3301139d..7798d222 100644
--- a/Framework/Particles/CMakeLists.txt
+++ b/Framework/Particles/CMakeLists.txt
@@ -92,11 +92,4 @@ target_link_libraries (
   CORSIKAunits
   CORSIKAthirdparty # for catch2
   )
-
-add_test (
-  NAME
-  testParticles
-  COMMAND
-  testParticles
-  )
-
+CORSIKA_ADD_TEST(testParticles)
diff --git a/Framework/ProcessSequence/CMakeLists.txt b/Framework/ProcessSequence/CMakeLists.txt
index 6c3e5ff8..d45d28d6 100644
--- a/Framework/ProcessSequence/CMakeLists.txt
+++ b/Framework/ProcessSequence/CMakeLists.txt
@@ -48,8 +48,4 @@ target_link_libraries (
   CORSIKAprocesssequence
   CORSIKAthirdparty # for catch2
   )
-
-add_test (
-  NAME testProcessSequence
-  COMMAND testProcessSequence
-  )
+CORSIKA_ADD_TEST(testProcessSequence)
diff --git a/Framework/Random/CMakeLists.txt b/Framework/Random/CMakeLists.txt
index 230f84f6..3607b585 100644
--- a/Framework/Random/CMakeLists.txt
+++ b/Framework/Random/CMakeLists.txt
@@ -45,6 +45,4 @@ target_link_libraries (
   CORSIKArandom
   CORSIKAthirdparty # for catch2
   )
-
-add_test (NAME testRandom COMMAND testRandom)
-
+CORSIKA_ADD_TEST(testRandom)
diff --git a/Framework/StackInterface/CMakeLists.txt b/Framework/StackInterface/CMakeLists.txt
index 42c52cea..c6106121 100644
--- a/Framework/StackInterface/CMakeLists.txt
+++ b/Framework/StackInterface/CMakeLists.txt
@@ -33,5 +33,5 @@ install (
 
 #code testing
 add_executable (testStackInterface testStackInterface.cc)
-add_test(NAME testStackInterface COMMAND testStackInterface)
 target_link_libraries (testStackInterface CORSIKAstackinterface CORSIKAthirdparty) # for catch2
+CORSIKA_ADD_TEST(testStackInterface)
diff --git a/Framework/Units/CMakeLists.txt b/Framework/Units/CMakeLists.txt
index 7948859e..639c5cbd 100644
--- a/Framework/Units/CMakeLists.txt
+++ b/Framework/Units/CMakeLists.txt
@@ -22,5 +22,4 @@ install (FILES ${CORSIKAunits_HEADERS} DESTINATION include/${CORSIKAunits_NAMESP
 # code testing
 add_executable (testUnits testUnits.cc)
 target_link_libraries (testUnits CORSIKAunits CORSIKAthirdparty) # for catch2
-add_test(NAME testUnits COMMAND testUnits)
-
+CORSIKA_ADD_TEST(testUnits)
diff --git a/Framework/Utilities/CMakeLists.txt b/Framework/Utilities/CMakeLists.txt
index 5ba7827b..5b21e927 100644
--- a/Framework/Utilities/CMakeLists.txt
+++ b/Framework/Utilities/CMakeLists.txt
@@ -58,6 +58,5 @@ target_link_libraries (
   CORSIKAutilities
   CORSIKAthirdparty # for catch2
   )
-
-add_test (NAME testCOMBoost COMMAND testCOMBoost)
+CORSIKA_ADD_TEST(testCOMBoost)
 
diff --git a/Processes/NullModel/CMakeLists.txt b/Processes/NullModel/CMakeLists.txt
index 300e3b57..c3355c77 100644
--- a/Processes/NullModel/CMakeLists.txt
+++ b/Processes/NullModel/CMakeLists.txt
@@ -60,6 +60,4 @@ target_link_libraries (
   CORSIKAunits
   CORSIKAthirdparty # for catch2
   )
-
-add_test (NAME testNullModel COMMAND testNullModel)
-
+CORSIKA_ADD_TEST(testNullModel)
diff --git a/Processes/Sibyll/CMakeLists.txt b/Processes/Sibyll/CMakeLists.txt
index 9224d9fe..ee28a30b 100644
--- a/Processes/Sibyll/CMakeLists.txt
+++ b/Processes/Sibyll/CMakeLists.txt
@@ -101,6 +101,4 @@ target_link_libraries (
   CORSIKAunits
   CORSIKAthirdparty # for catch2
   )
-
-add_test (NAME testSibyll COMMAND testSibyll)
-
+CORSIKA_ADD_TEST(testSibyll)
diff --git a/Processes/StackInspector/CMakeLists.txt b/Processes/StackInspector/CMakeLists.txt
index f87cc137..9711c422 100644
--- a/Processes/StackInspector/CMakeLists.txt
+++ b/Processes/StackInspector/CMakeLists.txt
@@ -60,6 +60,4 @@ target_link_libraries (
   CORSIKAunits
   CORSIKAthirdparty # for catch2
   )
-
-add_test (NAME testStackInspector COMMAND testStackInspector)
-
+CORSIKA_ADD_TEST(testStackInspector)
diff --git a/Processes/TrackWriter/CMakeLists.txt b/Processes/TrackWriter/CMakeLists.txt
index e9c73d68..67b99083 100644
--- a/Processes/TrackWriter/CMakeLists.txt
+++ b/Processes/TrackWriter/CMakeLists.txt
@@ -60,6 +60,5 @@ install (
 #  CORSIKAunits
 #  CORSIKAthirdparty # for catch2
 #  )
-
-#add_test (NAME testNullModel COMMAND testNullModel)
+# CORSIKA_ADD_TEST(testNullModel)
 
diff --git a/Processes/TrackingLine/CMakeLists.txt b/Processes/TrackingLine/CMakeLists.txt
index b68564bf..ce19ed67 100644
--- a/Processes/TrackingLine/CMakeLists.txt
+++ b/Processes/TrackingLine/CMakeLists.txt
@@ -37,5 +37,4 @@ target_link_libraries (
    CORSIKAgeometry
    CORSIKAthirdparty # for catch2
 )
-
-add_test (NAME testTrackingLine COMMAND testTrackingLine)
+CORSIKA_ADD_TEST(testTrackingLine)
diff --git a/Stack/SuperStupidStack/CMakeLists.txt b/Stack/SuperStupidStack/CMakeLists.txt
index b9634f1d..de96527d 100644
--- a/Stack/SuperStupidStack/CMakeLists.txt
+++ b/Stack/SuperStupidStack/CMakeLists.txt
@@ -44,8 +44,4 @@ target_link_libraries (
   CORSIKAunits
   CORSIKAthirdparty # for catch2
   )
-
-add_test (
-  NAME testSuperStupidStack
-  COMMAND testSuperStupidStack
-  )
+CORSIKA_ADD_TEST(testSuperStupidStack)
-- 
GitLab