Sort includes outside src/gromacs
[alexxy/gromacs.git] / src / testutils / testoptions.cpp
index b442b0411a4cc5efde5483de94b14f989f59ab65..a46d8875c37797a55813eb2eefff52aad683f464 100644 (file)
@@ -1,10 +1,10 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013, by the GROMACS development team, led by
- * David van der Spoel, Berk Hess, Erik Lindahl, and including many
- * others, as listed in the AUTHORS file in the top-level source
- * directory and at http://www.gromacs.org.
+ * Copyright (c) 2012,2013,2014, 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.
  *
  * GROMACS is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
@@ -39,6 +39,8 @@
  * \author Teemu Murtola <teemu.murtola@gmail.com>
  * \ingroup module_testutils
  */
+#include "gmxpre.h"
+
 #include "testoptions.h"
 
 #include <cstdio>
 
 #include <gmock/gmock.h>
 
-#include "gromacs/legacyheaders/thread_mpi/mutex.h"
+#include "thread_mpi/mutex.h"
 
+#include "gromacs/commandline/cmdlinehelpcontext.h"
 #include "gromacs/commandline/cmdlinehelpwriter.h"
+#include "gromacs/commandline/cmdlineinit.h"
 #include "gromacs/commandline/cmdlineparser.h"
-#include "gromacs/onlinehelp/helpwritercontext.h"
 #include "gromacs/options/basicoptions.h"
 #include "gromacs/options/options.h"
 #include "gromacs/utility/common.h"
 #include "gromacs/utility/errorcodes.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/file.h"
-#include "gromacs/utility/programinfo.h"
+#include "gromacs/utility/programcontext.h"
 
-#include "refdata.h"
-#include "testfilemanager.h"
+#include "testutils/mpi-printer.h"
+#include "testutils/refdata.h"
+#include "testutils/testfilemanager.h"
 
 namespace gmx
 {
@@ -73,7 +77,7 @@ namespace
 {
 
 /*! \brief
- * Singleton registry for test options added with GMX_TEST_OPTIONS.
+ * Singleton registry for test options added with #GMX_TEST_OPTIONS.
  *
  * \ingroup module_testutils
  */
@@ -113,7 +117,7 @@ void TestOptionsRegistry::initOptions(Options *options)
     // TODO: Have some deterministic order for the options; now it depends on
     // the order in which the global initializers are run.
     tMPI::lock_guard<tMPI::mutex> lock(listMutex_);
-    ProviderList::const_iterator i;
+    ProviderList::const_iterator  i;
     for (i = providerList_.begin(); i != providerList_.end(); ++i)
     {
         (*i)->initOptions(options);
@@ -126,29 +130,34 @@ void printHelp(const Options &options)
     std::fprintf(stderr,
                  "\nYou can use the following GROMACS-specific command-line flags\n"
                  "to control the behavior of the tests:\n\n");
-    HelpWriterContext context(&File::standardError(),
-                              eHelpOutputFormat_Console);
+    CommandLineHelpContext context(&File::standardError(),
+                                   eHelpOutputFormat_Console, NULL);
+    context.setModuleDisplayName(getProgramContext().displayName());
     CommandLineHelpWriter(options).writeHelp(context);
 }
 
-} // namespace
+}       // namespace
 
 void registerTestOptions(const char *name, TestOptionsProvider *provider)
 {
     TestOptionsRegistry::getInstance().add(name, provider);
 }
 
-void initTestUtils(const char *dataPath, int *argc, char *argv[])
+void initTestUtils(const char *dataPath, const char *tempPath, int *argc, char ***argv)
 {
+    gmx::initForCommandLine(argc, argv);
     try
     {
-        ProgramInfo::init(*argc, argv);
-        ::testing::InitGoogleMock(argc, argv);
+        ::testing::InitGoogleMock(argc, *argv);
         if (dataPath != NULL)
         {
             TestFileManager::setInputDataDirectory(dataPath);
         }
-        bool bHelp = false;
+        if (tempPath != NULL)
+        {
+            TestFileManager::setGlobalOutputTempDirectory(tempPath);
+        }
+        bool    bHelp = false;
         Options options(NULL, NULL);
         // TODO: A single option that accepts multiple names would be nicer.
         // Also, we recognize -help, but GTest doesn't, which leads to a bit
@@ -162,7 +171,7 @@ void initTestUtils(const char *dataPath, int *argc, char *argv[])
         TestOptionsRegistry::getInstance().initOptions(&options);
         try
         {
-            CommandLineParser(&options).parse(argc, argv);
+            CommandLineParser(&options).parse(argc, *argv);
             options.finish();
         }
         catch (const UserInputError &)
@@ -175,13 +184,19 @@ void initTestUtils(const char *dataPath, int *argc, char *argv[])
             printHelp(options);
         }
         setFatalErrorHandler(NULL);
+        initMPIOutput();
     }
     catch (const std::exception &ex)
     {
         printFatalErrorMessage(stderr, ex);
-        std::exit(1);
+        std::exit(processExceptionAtExit(ex));
     }
 }
 
+void finalizeTestUtils()
+{
+    gmx::finalizeForCommandLine();
+}
+
 } // namespace test
 } // namespace gmx