From 660a03acebaf0d18f9b92defffd6b19c7e818d93 Mon Sep 17 00:00:00 2001 From: Teemu Murtola Date: Wed, 17 Jun 2015 13:53:54 +0300 Subject: [PATCH] Minor clean up for refdata.* - Remove global functions that are no longer necessary. All the state about the reference data mode is stored internally in refdata.cpp. These were remnants from an old implementation where the code was split into multiple .cpp files to support compilation of testutils/ without libxml2 dependencies. - Make the self-tests for the reference data code not use the source tree as a location for the transient data they create. In addition to clarifying the code, these should make it harder to misuse the constructor intended for self-testing, since it will be difficult to pass Jenkins if someone tries to use it for other tests. Change-Id: I204ddadfc224a79c587f0588a4d510b7b8486f9b --- .gitignore | 1 + src/testutils/refdata.cpp | 34 ++++++++++++++-------------------- src/testutils/refdata.h | 34 ++++++++++------------------------ src/testutils/tests/.gitignore | 1 - 4 files changed, 25 insertions(+), 45 deletions(-) delete mode 100644 src/testutils/tests/.gitignore diff --git a/.gitignore b/.gitignore index e2d9763327..42b80429af 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ lib*.pc .cproject CMakeLists.txt.user /VersionInfo*.cmake +Testing diff --git a/src/testutils/refdata.cpp b/src/testutils/refdata.cpp index 9221676e63..f9bab1ecf3 100644 --- a/src/testutils/refdata.cpp +++ b/src/testutils/refdata.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2011,2012,2013,2014, by the GROMACS development team, led by + * Copyright (c) 2011,2012,2013,2014,2015, 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. @@ -84,6 +84,12 @@ class TestReferenceDataEnvironment : public ::testing::Environment // TODO: Make this a real enum; requires solving a TODO in StringOption. int g_referenceDataMode = gmx::test::erefdataCompare; +//! Returns the global reference data mode. +gmx::test::ReferenceDataMode getReferenceDataMode() +{ + return static_cast(g_referenceDataMode); +} + } // namespace namespace gmx @@ -91,21 +97,6 @@ namespace gmx namespace test { -ReferenceDataMode getReferenceDataMode() -{ - return static_cast(g_referenceDataMode); -} - -void setReferenceDataMode(ReferenceDataMode mode) -{ - g_referenceDataMode = mode; -} - -std::string getReferenceDataPath() -{ - return TestFileManager::getInputFilePath("refdata"); -} - void initReferenceData(Options *options) { // Needs to correspond to the enum order in refdata.h. @@ -177,9 +168,12 @@ const xmlChar * const TestReferenceData::Impl::cRootNodeName = TestReferenceData::Impl::Impl(ReferenceDataMode mode, bool bSelfTestMode) : refDoc_(NULL), bWrite_(false), bSelfTestMode_(bSelfTestMode), bInUse_(false) { - std::string dirname = getReferenceDataPath(); - std::string filename = TestFileManager::getTestSpecificFileName(".xml"); - fullFilename_ = Path::join(dirname, filename); + const std::string dirname = + bSelfTestMode + ? TestFileManager::getGlobalOutputTempDirectory() + : TestFileManager::getInputDataDirectory(); + const std::string filename = TestFileManager::getTestSpecificFileName(".xml"); + fullFilename_ = Path::join(dirname, "refdata", filename); bWrite_ = true; if (mode != erefdataUpdateAll) @@ -232,7 +226,7 @@ TestReferenceData::Impl::~Impl() { if (bWrite_ && bInUse_ && refDoc_ != NULL) { - std::string dirname = getReferenceDataPath(); + std::string dirname = Path::getParentPath(fullFilename_); if (!Directory::exists(dirname)) { if (Directory::create(dirname) != 0) diff --git a/src/testutils/refdata.h b/src/testutils/refdata.h index 215514142a..acd1d9364b 100644 --- a/src/testutils/refdata.h +++ b/src/testutils/refdata.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2011,2012,2013,2014, by the GROMACS development team, led by + * Copyright (c) 2011,2012,2013,2014,2015, 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. @@ -63,6 +63,8 @@ class FloatingPointTolerance; * Mode of operation for reference data handling. * * There should be no need to use this type outside the test utility module. + * + * \ingroup module_testutils */ enum ReferenceDataMode { @@ -90,36 +92,19 @@ enum ReferenceDataMode erefdataUpdateAll }; -/*! \libinternal \brief - * Returns the global reference data mode. - * - * There should be no need to use this function outside the test utility module. - */ -ReferenceDataMode getReferenceDataMode(); -/*! \libinternal \brief - * Sets the global reference data mode. - * - * There should be no need to use this function outside the test utility module. - */ -void setReferenceDataMode(ReferenceDataMode mode); -/*! \libinternal \brief - * Returns the directory where reference data files are stored. - * - * There should be no need to use this function outside the test utility module. - */ -std::string getReferenceDataPath(); /*! \libinternal \brief * Initializes reference data handling. * * Adds command-line options to \p options to set the reference data mode. - * By default, ::erefdataCompare is used, but \c "--ref-data create" or - * \c "--ref-data update" can be used to change it. + * By default, ::erefdataCompare is used, but ``--ref-data create`` or + * ``--ref-data update`` can be used to change it. * * This function is automatically called by initTestUtils(). + * + * \ingroup module_testutils */ void initReferenceData(Options *options); - class TestReferenceChecker; /*! \libinternal \brief @@ -180,10 +165,11 @@ class TestReferenceData /*! \brief * Initializes the reference data in a specific mode. * - * This function is mainly useful for self-testing the reference data + * This function is only useful for self-testing the reference data * framework. As such, it also puts the framework in a state where it * logs additional internal information for failures to help diagnosing - * problems in the framework. + * problems in the framework, and stores the reference data in a + * temporary directory instead of the source tree. * The default constructor should be used in tests utilizing this class. */ explicit TestReferenceData(ReferenceDataMode mode); diff --git a/src/testutils/tests/.gitignore b/src/testutils/tests/.gitignore deleted file mode 100644 index 4236747b4e..0000000000 --- a/src/testutils/tests/.gitignore +++ /dev/null @@ -1 +0,0 @@ -refdata -- 2.22.0