diff --git a/include/cantera/base/global.h b/include/cantera/base/global.h index 64c379edc..4734e7713 100644 --- a/include/cantera/base/global.h +++ b/include/cantera/base/global.h @@ -26,6 +26,8 @@ namespace Cantera class XML_Node; class Logger; + + //! Return the number of errors that have been encountered so far /*! * @ingroup errorhandling @@ -199,6 +201,9 @@ void warn_deprecated(const std::string& method, const std::string& extra=""); //! @copydoc Application::suppress_deprecation_warnings void suppress_deprecation_warnings(); +//! @copydoc Application::make_deprecation_warnings_fatal +void make_deprecation_warnings_fatal(); + //! @copydoc Application::Messages::setLogger void setLogger(Logger* logwriter); diff --git a/interfaces/cython/cantera/_cantera.pxd b/interfaces/cython/cantera/_cantera.pxd index bec4d84c0..91de2b0c2 100644 --- a/interfaces/cython/cantera/_cantera.pxd +++ b/interfaces/cython/cantera/_cantera.pxd @@ -40,6 +40,7 @@ cdef extern from "cantera/base/global.h" namespace "Cantera": cdef void CxxAppdelete "Cantera::appdelete" () cdef XML_Node* CxxGetXmlFile "Cantera::get_XML_File" (string) except + cdef XML_Node* CxxGetXmlFromString "Cantera::get_XML_from_string" (string) except + + cdef void Cxx_make_deprecation_warnings_fatal "Cantera::make_deprecation_warnings_fatal" () cdef extern from "cantera/thermo/mix_defs.h": cdef int thermo_type_ideal_gas "Cantera::cIdealGas" diff --git a/interfaces/cython/cantera/utils.pyx b/interfaces/cython/cantera/utils.pyx index d37f645d9..36fa8f917 100644 --- a/interfaces/cython/cantera/utils.pyx +++ b/interfaces/cython/cantera/utils.pyx @@ -34,6 +34,9 @@ def appdelete(): """ Delete all global Cantera C++ objects """ CxxAppdelete() +def make_deprecation_warnings_fatal(): + Cxx_make_deprecation_warnings_fatal() + cdef Composition comp_map(X) except *: if isinstance(X, (str, unicode, bytes)): return parseCompString(stringify(X)) diff --git a/src/base/application.cpp b/src/base/application.cpp index 0201480c0..bdf75f2f0 100644 --- a/src/base/application.cpp +++ b/src/base/application.cpp @@ -138,7 +138,8 @@ void Application::ThreadMessages::removeThreadMessages() } Application::Application() : - m_suppress_deprecation_warnings(false) + m_suppress_deprecation_warnings(false), + m_fatal_deprecation_warnings(false) { // install a default logwriter that writes to standard // output / standard error @@ -176,7 +177,9 @@ void Application::ApplicationDestroy() void Application::warn_deprecated(const std::string& method, const std::string& extra) { - if (m_suppress_deprecation_warnings || warnings.count(method)) { + if (m_fatal_deprecation_warnings) { + throw CanteraError(method, "Deprecated: " + extra); + } else if (m_suppress_deprecation_warnings || warnings.count(method)) { return; } warnings.insert(method); diff --git a/src/base/application.h b/src/base/application.h index aab56d088..32daac461 100644 --- a/src/base/application.h +++ b/src/base/application.h @@ -318,6 +318,12 @@ public: m_suppress_deprecation_warnings = true; } + //! Turns deprecation warnings into exceptions. Activated within the test + //! suite to make sure that no deprecated methods are being used. + void make_deprecation_warnings_fatal() { + m_fatal_deprecation_warnings = true; + } + //! @copydoc Messages::setLogger void setLogger(Logger* logwriter) { pMessenger->setLogger(logwriter); @@ -373,6 +379,7 @@ protected: std::set warnings; bool m_suppress_deprecation_warnings; + bool m_fatal_deprecation_warnings; ThreadMessages pMessenger; diff --git a/src/base/global.cpp b/src/base/global.cpp index bd151f216..259ee4ed1 100644 --- a/src/base/global.cpp +++ b/src/base/global.cpp @@ -58,6 +58,11 @@ void suppress_deprecation_warnings() app()->suppress_deprecation_warnings(); } +void make_deprecation_warnings_fatal() +{ + app()->make_deprecation_warnings_fatal(); +} + // **************** Global Data **************** Unit* Unit::s_u = 0; diff --git a/test/equil/equil_gas.cpp b/test/equil/equil_gas.cpp index 600400497..36209432a 100644 --- a/test/equil/equil_gas.cpp +++ b/test/equil/equil_gas.cpp @@ -299,6 +299,7 @@ int main(int argc, char** argv) { printf("Running main() from equil_gas.cpp\n"); testing::InitGoogleTest(&argc, argv); + make_deprecation_warnings_fatal(); int result = RUN_ALL_TESTS(); appdelete(); return result; diff --git a/test/general/string_processing.cpp b/test/general/string_processing.cpp index 6a6c28b42..578a0b937 100644 --- a/test/general/string_processing.cpp +++ b/test/general/string_processing.cpp @@ -74,6 +74,7 @@ int main(int argc, char** argv) { printf("Running main() from string_processing.cpp\n"); testing::InitGoogleTest(&argc, argv); + Cantera::make_deprecation_warnings_fatal(); int result = RUN_ALL_TESTS(); Cantera::appdelete(); return result; diff --git a/test/kinetics/pdep.cpp b/test/kinetics/pdep.cpp index bccfe67a9..683831b32 100644 --- a/test/kinetics/pdep.cpp +++ b/test/kinetics/pdep.cpp @@ -229,6 +229,7 @@ TEST_F(PdepTest, ChebyshevEdgeCases) int main(int argc, char** argv) { printf("Running main() from pdep.cpp\n"); + Cantera::make_deprecation_warnings_fatal(); testing::InitGoogleTest(&argc, argv); int result = RUN_ALL_TESTS(); Cantera::appdelete(); diff --git a/test/python/runCythonTests.py b/test/python/runCythonTests.py index 5a757d67b..df6407f9d 100644 --- a/test/python/runCythonTests.py +++ b/test/python/runCythonTests.py @@ -40,6 +40,8 @@ from cantera.test.utilities import unittest import cantera import cantera.test +cantera.make_deprecation_warnings_fatal() + class TestResult(unittest.TextTestResult): def __init__(self, *args, **kwargs): unittest.TextTestResult.__init__(self, *args, **kwargs) diff --git a/test/thermo/nasapoly.cpp b/test/thermo/nasapoly.cpp index 8864d9c57..2154eb67d 100644 --- a/test/thermo/nasapoly.cpp +++ b/test/thermo/nasapoly.cpp @@ -143,6 +143,7 @@ TEST(Nasa9Test, Nasa9Thermo) { int main(int argc, char** argv) { printf("Running main() from nasapoly.cpp\n"); + Cantera::make_deprecation_warnings_fatal(); testing::InitGoogleTest(&argc, argv); int result = RUN_ALL_TESTS(); Cantera::appdelete(); diff --git a/test/transport/transportFromScratch.cpp b/test/transport/transportFromScratch.cpp index 14e4b663e..149b6eaf2 100644 --- a/test/transport/transportFromScratch.cpp +++ b/test/transport/transportFromScratch.cpp @@ -169,6 +169,7 @@ TEST_F(TransportFromScratch, thermalConductivityMulti) int main(int argc, char** argv) { printf("Running main() from transportFromScratch.cpp\n"); + Cantera::make_deprecation_warnings_fatal(); testing::InitGoogleTest(&argc, argv); int result = RUN_ALL_TESTS(); appdelete();