* This file is part of the GROMACS molecular simulation package.
*
* Copyright (c) 2011-2018, The GROMACS development team.
- * Copyright (c) 2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2019,2020,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
* Implements classes and functions from refdata.h.
*
* \author Teemu Murtola <teemu.murtola@gmail.com>
+ * \author Mark Abraham <mark.j.abraham@gmail.com>
* \ingroup module_testutils
*/
#include "gmxpre.h"
#include <algorithm>
#include <limits>
+#include <optional>
#include <string>
#include <gtest/gtest.h>
{
public:
//! Initializes a checker in the given mode.
- TestReferenceDataImpl(ReferenceDataMode mode, bool bSelfTestMode);
+ TestReferenceDataImpl(ReferenceDataMode mode, bool bSelfTestMode, std::optional<std::string> testNameOverride);
//! Performs final reference data processing when test ends.
- void onTestEnd(bool testPassed);
+ void onTestEnd(bool testPassed) const;
//! Full path of the reference data file.
std::string fullFilename_;
}
//! Returns a reference to the global reference data object.
-TestReferenceDataImplPointer initReferenceDataInstance()
+TestReferenceDataImplPointer initReferenceDataInstance(std::optional<std::string> testNameOverride)
{
GMX_RELEASE_ASSERT(!g_referenceData, "Test cannot create multiple TestReferenceData instances");
- g_referenceData.reset(new internal::TestReferenceDataImpl(getReferenceDataMode(), false));
+ g_referenceData.reset(new internal::TestReferenceDataImpl(
+ getReferenceDataMode(), false, std::move(testNameOverride)));
return g_referenceData;
}
g_referenceData->onTestEnd(true);
g_referenceData.reset();
}
- g_referenceData.reset(new internal::TestReferenceDataImpl(mode, true));
+ g_referenceData.reset(new internal::TestReferenceDataImpl(mode, true, std::nullopt));
return g_referenceData;
}
namespace internal
{
-TestReferenceDataImpl::TestReferenceDataImpl(ReferenceDataMode mode, bool bSelfTestMode) :
- updateMismatchingEntries_(false),
- bSelfTestMode_(bSelfTestMode),
- bInUse_(false)
+TestReferenceDataImpl::TestReferenceDataImpl(ReferenceDataMode mode,
+ bool bSelfTestMode,
+ std::optional<std::string> testNameOverride) :
+ updateMismatchingEntries_(false), bSelfTestMode_(bSelfTestMode), bInUse_(false)
{
- const std::string dirname = bSelfTestMode ? TestFileManager::getGlobalOutputTempDirectory()
- : TestFileManager::getInputDataDirectory();
- const std::string filename = TestFileManager::getTestSpecificFileName(".xml");
+ const std::string dirname = bSelfTestMode ? TestFileManager::getGlobalOutputTempDirectory()
+ : TestFileManager::getInputDataDirectory();
+ const std::string filename = testNameOverride.has_value()
+ ? testNameOverride.value()
+ : TestFileManager::getTestSpecificFileName(".xml");
fullFilename_ = Path::join(dirname, "refdata", filename);
switch (mode)
}
}
-void TestReferenceDataImpl::onTestEnd(bool testPassed)
+void TestReferenceDataImpl::onTestEnd(bool testPassed) const
{
if (!bInUse_)
{
* TestReferenceData
*/
-TestReferenceData::TestReferenceData() : impl_(initReferenceDataInstance()) {}
+TestReferenceData::TestReferenceData() : impl_(initReferenceDataInstance(std::nullopt)) {}
+
+TestReferenceData::TestReferenceData(std::string testNameOverride) :
+ impl_(initReferenceDataInstance(std::move(testNameOverride)))
+{
+}
TestReferenceData::TestReferenceData(ReferenceDataMode mode) :
impl_(initReferenceDataInstanceForSelfTest(mode))