From 775e1d49a6955dd32cc23f840d4eec72594fdc4c Mon Sep 17 00:00:00 2001 From: Jeff Henning <17114032+henningjp@users.noreply.github.com> Date: Thu, 9 Apr 2026 21:12:20 -0400 Subject: [PATCH] Skip REFPROP tests when not available during CI (#2710) * Try loading REFPROP backend and only warn on failure * Skip REFPROP related tests when not available using a single helper routine in CoolProp:: namespace --- .gitignore | 1 + include/CoolProp.h | 3 +++ src/AbstractState.cpp | 12 +++++++++++- src/Backends/REFPROP/REFPROPMixtureBackend.cpp | 5 +++++ src/CoolProp.cpp | 12 ++++++++++++ src/Tests/CoolProp-Tests.cpp | 11 +++++++++++ 6 files changed, 43 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f1187784..ff5a080f 100644 --- a/.gitignore +++ b/.gitignore @@ -59,6 +59,7 @@ Web/fluid_properties/fluids/molecule_sdf/ /include/pcsaft_fluids_schema_JSON.h /include/version.h /include/catch.hpp +/install_root/ /build*/ /dev/hashes.json /include/cpversion.h diff --git a/include/CoolProp.h b/include/CoolProp.h index 21400c4c..421f7a63 100644 --- a/include/CoolProp.h +++ b/include/CoolProp.h @@ -192,5 +192,8 @@ std::string extract_fractions(const std::string& fluid_string, std::vector(CoolProp::AbstractState::factory("INCOMP", "DEB"))); } + // SECTION("good backend - REFPROP") { + // CHECK_NOTHROW(shared_ptr(CoolProp::AbstractState::factory("REFPROP", "Water"))); + // } + // Code below lets the test suite continue with REFPROP isn't present while still reporting a visile warning from CATCH2 SECTION("good backend - REFPROP") { - CHECK_NOTHROW(shared_ptr(CoolProp::AbstractState::factory("REFPROP", "Water"))); + try { + auto s = shared_ptr(CoolProp::AbstractState::factory("REFPROP", "Water")); + CHECK(s); // assert we got a non-null pointer when REFPROP is present + } + catch (const std::exception& e) { + WARN(std::string("REFPROP backend unavailable. All tests requiring REFPROP will be skipped.")); + } } } diff --git a/src/Backends/REFPROP/REFPROPMixtureBackend.cpp b/src/Backends/REFPROP/REFPROPMixtureBackend.cpp index 6d0e6e4f..3c1ab493 100644 --- a/src/Backends/REFPROP/REFPROPMixtureBackend.cpp +++ b/src/Backends/REFPROP/REFPROPMixtureBackend.cpp @@ -2225,6 +2225,8 @@ void REFPROP_SETREF(char hrf[3], int ixflag, double x0[1], double& h0, double& s # include TEST_CASE("Check REFPROP and CoolProp values agree", "[REFPROP]") { + CoolProp::Skip_if_No_REFPROP(); + SECTION("Saturation densities agree within 0.5% at T/Tc = 0.9") { std::vector ss = strsplit(CoolProp::get_global_param_string("FluidsList"), ','); @@ -2340,6 +2342,8 @@ TEST_CASE("Check REFPROP and CoolProp values agree", "[REFPROP]") { } TEST_CASE("Check trivial inputs for REFPROP work", "[REFPROP_trivial]") { + CoolProp::Skip_if_No_REFPROP(); + const int num_inputs = 6; std::string inputs[num_inputs] = {"T_triple", "T_critical", "p_critical", "molar_mass", "rhomolar_critical", "rhomass_critical"}; for (int i = 0; i < num_inputs; ++i) { @@ -2358,6 +2362,7 @@ TEST_CASE("Check trivial inputs for REFPROP work", "[REFPROP_trivial]") { } TEST_CASE("Check PHI0 derivatives", "[REFPROP_PHI0]") { + CoolProp::Skip_if_No_REFPROP(); const int num_inputs = 3; std::string inputs[num_inputs] = {"DALPHA0_DDELTA_CONSTTAU", "D2ALPHA0_DDELTA2_CONSTTAU", "D3ALPHA0_DDELTA3_CONSTTAU"}; diff --git a/src/CoolProp.cpp b/src/CoolProp.cpp index 2838e973..56cc3e9a 100644 --- a/src/CoolProp.cpp +++ b/src/CoolProp.cpp @@ -675,7 +675,17 @@ bool add_fluids_as_JSON(const std::string& backend, const std::string& fluidstri } } +// Simple function to check if REFPROPMixtureBackend is supported in this environment, so that we can skip +// tests that require it in environments where it is not supported (e.g., CI builds on GitHub) +void Skip_if_No_REFPROP() { #if defined(ENABLE_CATCH) + if (!CoolProp::REFPROPMixtureBackend::REFPROP_supported()) SKIP("Skipping: REFPROP not supported in this environment."); +#endif + // Otherwise, in non-testing environments, this is a no-op. +} + +#if defined(ENABLE_CATCH) + TEST_CASE("Check inputs to PropsSI", "[PropsSI]") { SECTION("Single state, single output") { CHECK(ValidNumber(CoolProp::PropsSI("T", "P", 101325, "Q", 0, "Water"))); @@ -705,9 +715,11 @@ TEST_CASE("Check inputs to PropsSI", "[PropsSI]") { CHECK(ValidNumber(CoolProp::PropsSI("T", "P", 101325, "Q", 0, "R410A.mix"))); }; SECTION("Single state, single output, predefined mixture from REFPROP") { + Skip_if_No_REFPROP(); CHECK(ValidNumber(CoolProp::PropsSI("T", "P", 101325, "Q", 0, "REFPROP::R410A.MIX"))); }; SECTION("Single state, single output, bad predefined mixture from REFPROP") { + Skip_if_No_REFPROP(); CHECK(!ValidNumber(CoolProp::PropsSI("T", "P", 101325, "Q", 0, "REFPROP::RRRRRR.mix"))); }; SECTION("Predefined mixture") { diff --git a/src/Tests/CoolProp-Tests.cpp b/src/Tests/CoolProp-Tests.cpp index b26129b8..452b8aaf 100644 --- a/src/Tests/CoolProp-Tests.cpp +++ b/src/Tests/CoolProp-Tests.cpp @@ -1329,6 +1329,8 @@ TEST_CASE("Humid air auxiliary functions: physical validity and monotonicity", TEST_CASE("Test consistency between Gernert models in CoolProp and Gernert models in REFPROP", "[Gernert]") { // See https://groups.google.com/forum/?fromgroups#!topic/catch-forum/mRBKqtTrITU + Skip_if_No_REFPROP(); // Skip this test if REFPROPMixture backend is not available + std::string mixes[] = {"CO2[0.7]&Argon[0.3]", "CO2[0.7]&Water[0.3]", "CO2[0.7]&Nitrogen[0.3]"}; for (int i = 0; i < 3; ++i) { const char* ykey = mixes[i].c_str(); @@ -1805,6 +1807,8 @@ TEST_CASE("Test second partial derivatives", "[derivatives]") { } TEST_CASE("REFPROP names for coolprop fluids", "[REFPROPName]") { + Skip_if_No_REFPROP(); // Skip this test if REFPROPMixture backend is not available + std::vector fluids = strsplit(CoolProp::get_global_param_string("fluids_list"), ','); for (std::size_t i = 0; i < fluids.size(); ++i) { std::ostringstream ss1; @@ -1822,6 +1826,8 @@ TEST_CASE("REFPROP names for coolprop fluids", "[REFPROPName]") { } } TEST_CASE("Backwards compatibility for REFPROP v4 fluid name convention", "[REFPROP_backwards_compatibility]") { + Skip_if_No_REFPROP(); // Skip this test if REFPROPMixture backend is not available + SECTION("REFPROP-", "") { double val = Props1SI("REFPROP-Water", "Tcrit"); std::string err = get_global_param_string("errstring"); @@ -3080,6 +3086,8 @@ TEST_CASE("CoolProp.jl tests", "[2598]") { } TEST_CASE("Check methanol EOS matches REFPROP 10", "[2538]") { + Skip_if_No_REFPROP(); // Skip this test if REFPROPMixture backend is not available + auto TNBP_RP = PropsSI("T", "P", 101325, "Q", 0, "REFPROP::METHANOL"); auto TNBP_CP = PropsSI("T", "P", 101325, "Q", 0, "HEOS::METHANOL"); CHECK(TNBP_RP == Catch::Approx(TNBP_CP).epsilon(1e-6)); @@ -3294,6 +3302,7 @@ TEST_CASE_METHOD(SuperAncillaryOnFixture, "Check throws for R410A", "[superanc]" } TEST_CASE_METHOD(SuperAncillaryOnFixture, "Check throws for REFPROP", "[superanc]") { + Skip_if_No_REFPROP(); // Skip this test if REFPROPMixture backend is not available shared_ptr AS(CoolProp::AbstractState::factory("REFPROP", "WATER")); CHECK_THROWS(AS->update_QT_pure_superanc(1.0, 300.0)); } @@ -3445,6 +3454,8 @@ std::vector> MSA22values = { }; TEST_CASE("Ideal gas thermodynamic properties", "[2589]") { + Skip_if_No_REFPROP(); // Skip this test if REFPROPMixture backend is not available + shared_ptr AS(CoolProp::AbstractState::factory("HEOS", "Air")); shared_ptr RP(CoolProp::AbstractState::factory("REFPROP", "Air"));