From f3262d97120a440358de3391da20601e4e5a0527 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com>
Date: Mon, 2 Nov 2020 10:46:52 +0100
Subject: [PATCH] Add tests for BuildInfo

---
 tests/CMakeLists.txt     |  1 +
 tests/test_BuildInfo.cpp | 70 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+)
 create mode 100644 tests/test_BuildInfo.cpp

diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 11680e00f..81d7553d5 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -45,6 +45,7 @@ add_executable (unit_tests
   test_BinaryExpressionProcessor_equality.cpp
   test_BinaryExpressionProcessor_logic.cpp
   test_BiCGStab.cpp
+  test_BuildInfo.cpp
   test_BuiltinFunctionEmbedder.cpp
   test_BuiltinFunctionEmbedderTable.cpp
   test_BuiltinFunctionProcessor.cpp
diff --git a/tests/test_BuildInfo.cpp b/tests/test_BuildInfo.cpp
new file mode 100644
index 000000000..36c8c79aa
--- /dev/null
+++ b/tests/test_BuildInfo.cpp
@@ -0,0 +1,70 @@
+#ifndef TEST_BUILD_INFO_HPP
+#define TEST_BUILD_INFO_HPP
+
+#include <catch2/catch.hpp>
+
+#include <utils/BuildInfo.hpp>
+#include <utils/pugs_build_info.hpp>
+#include <utils/pugs_config.hpp>
+
+#include <sstream>
+
+#ifdef PUGS_HAS_MPI
+#include <mpi.h>
+#endif   //  PUGS_HAS_MPI
+
+#ifdef PUGS_HAS_PETSC
+#include <petsc.h>
+#endif   // PUGS_HAS_PETSC
+
+// clazy:excludeall=non-pod-global-static
+
+TEST_CASE("BuildInfo", "[utils]")
+{
+  SECTION("type")
+  {
+    REQUIRE(BuildInfo::type() == PUGS_BUILD_TYPE);
+  }
+
+  SECTION("compiler")
+  {
+    std::stringstream compiler_info;
+    compiler_info << PUGS_BUILD_COMPILER << " (" << PUGS_BUILD_COMPILER_VERSION << ")" << std::ends;
+    REQUIRE(BuildInfo::compiler() == compiler_info.str());
+  }
+
+  SECTION("kokkos")
+  {
+    REQUIRE(BuildInfo::kokkosDevices() == PUGS_BUILD_KOKKOS_DEVICES);
+  }
+
+  SECTION("mpi")
+  {
+#ifdef PUGS_HAS_MPI
+    const std::string mpi_library = []() {
+      int length;
+      char mpi_version[MPI_MAX_LIBRARY_VERSION_STRING];
+      MPI_Get_library_version(mpi_version, &length);
+      return std::string(mpi_version);
+    }();
+
+    REQUIRE(BuildInfo::mpiLibrary() == mpi_library);
+#else
+    REQUIRE(BuildInfo::mpiLibrary() == "none");
+#endif   // PUGS_HAS_MPI
+  }
+
+  SECTION("petsc")
+  {
+#ifdef PUGS_HAS_PETSC
+    const std::string petsc_library = std::to_string(PETSC_VERSION_MAJOR) + "." + std::to_string(PETSC_VERSION_MINOR) +
+                                      "." + std::to_string(PETSC_VERSION_SUBMINOR);
+
+    REQUIRE(BuildInfo::petscLibrary() == petsc_library);
+#else
+    REQUIRE(BuildInfo::petscLibrary() == "none");
+#endif   // PUGS_HAS_PETSC
+  }
+}
+
+#endif   // TEST_BUILD_INFO_HPP
-- 
GitLab