[Test] Make deprecation warnings fatal in test suites
This ensures that deprecated methods aren't being called anywhere in the test suite, without having to manually scan the test output for warning messages.
This commit is contained in:
parent
9a848fbd0e
commit
7124385292
12 changed files with 33 additions and 2 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<std::string> warnings;
|
||||
|
||||
bool m_suppress_deprecation_warnings;
|
||||
bool m_fatal_deprecation_warnings;
|
||||
|
||||
ThreadMessages pMessenger;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue