Apply clang-format to source tree
[alexxy/gromacs.git] / src / testutils / cmdlinetest.cpp
index 1db63fc70891d6e4fbd4552c92498c209056c824..32051396b4926305866a823649085467dd7a645d 100644 (file)
@@ -78,24 +78,24 @@ namespace test
 
 class CommandLine::Impl
 {
-    public:
-        Impl(const ArrayRef<const char *const> &cmdline);
-        Impl(const ArrayRef<const std::string> &cmdline);
-        ~Impl();
-
-        std::vector<char *>     args_;
-        std::vector<char *>     argv_;
-        int                     argc_;
+public:
+    Impl(const ArrayRef<const char* const>& cmdline);
+    Impl(const ArrayRef<const std::string>& cmdline);
+    ~Impl();
+
+    std::vector<char*> args_;
+    std::vector<char*> argv_;
+    int                argc_;
 };
 
-CommandLine::Impl::Impl(const ArrayRef<const char *const> &cmdline)
+CommandLine::Impl::Impl(const ArrayRef<const char* const>& cmdline)
 {
     args_.reserve(cmdline.size());
     argv_.reserve(cmdline.size() + 1);
     argc_ = ssize(cmdline);
-    for (const auto &arg : cmdline)
+    for (const autoarg : cmdline)
     {
-        char *argCopy = strdup(arg);
+        charargCopy = strdup(arg);
         if (argCopy == nullptr)
         {
             throw std::bad_alloc();
@@ -110,20 +110,23 @@ namespace
 {
 
 //! Helper function so we can delegate from the std::string constructor to the const char * one.
-std::vector<const char*> convertFromStringArrayRef(const ArrayRef<const std::string> &cmdline)
+std::vector<const char*> convertFromStringArrayRef(const ArrayRef<const std::string>cmdline)
 {
     std::vector<const char*> v(cmdline.size());
-    std::transform(cmdline.begin(), cmdline.end(), v.begin(), [](const std::string &s){return s.c_str(); });
+    std::transform(cmdline.begin(), cmdline.end(), v.begin(),
+                   [](const std::string& s) { return s.c_str(); });
     return v;
 }
 
-}       // namespace
+} // namespace
 
 // This makes a new temporary vector of views of the const char * in
 // the view passed in. Those are then deep copied in the constructor
 // delegated to.
-CommandLine::Impl::Impl(const ArrayRef<const std::string> &cmdline)
-    : Impl(convertFromStringArrayRef(cmdline)) {}
+CommandLine::Impl::Impl(const ArrayRef<const std::string>& cmdline) :
+    Impl(convertFromStringArrayRef(cmdline))
+{
+}
 
 CommandLine::Impl::~Impl()
 {
@@ -137,43 +140,32 @@ CommandLine::Impl::~Impl()
  * CommandLine
  */
 
-CommandLine::CommandLine()
-    : impl_(new Impl(ArrayRef<const char *>{}))
-{
-}
+CommandLine::CommandLine() : impl_(new Impl(ArrayRef<const char*>{})) {}
 
-CommandLine::CommandLine(const ArrayRef<const char *const> &cmdline)
-    : impl_(new Impl(cmdline))
-{
-}
+CommandLine::CommandLine(const ArrayRef<const char* const>& cmdline) : impl_(new Impl(cmdline)) {}
 
-CommandLine::CommandLine(const ArrayRef<const std::string> &cmdline)
-    : impl_(new Impl(cmdline))
-{
-}
+CommandLine::CommandLine(const ArrayRef<const std::string>& cmdline) : impl_(new Impl(cmdline)) {}
 
-CommandLine::CommandLine(const CommandLine &other)
-    impl_(new Impl(arrayRefFromArray(other.argv(), other.argc())))
+CommandLine::CommandLine(const CommandLine& other) :
+    impl_(new Impl(arrayRefFromArray(other.argv(), other.argc())))
 {
 }
 
-CommandLine::~CommandLine()
-{
-}
+CommandLine::~CommandLine() {}
 
-void CommandLine::initFromArray(const ArrayRef<const char *const> &cmdline)
+void CommandLine::initFromArray(const ArrayRef<const char* const>& cmdline)
 {
     impl_.reset(new Impl(cmdline));
 }
 
-void CommandLine::append(const char *arg)
+void CommandLine::append(const chararg)
 {
     GMX_RELEASE_ASSERT(impl_->argc_ == ssize(impl_->args_),
                        "Command-line has been modified externally");
     size_t newSize = impl_->args_.size() + 1;
     impl_->args_.reserve(newSize);
     impl_->argv_.reserve(newSize + 1);
-    char *newArg = strdup(arg);
+    charnewArg = strdup(arg);
     if (newArg == nullptr)
     {
         throw std::bad_alloc();
@@ -185,35 +177,35 @@ void CommandLine::append(const char *arg)
     impl_->argc_ = static_cast<int>(newSize);
 }
 
-void CommandLine::addOption(const char *name)
+void CommandLine::addOption(const charname)
 {
     append(name);
 }
 
-void CommandLine::addOption(const char *name, const char *value)
+void CommandLine::addOption(const char* name, const char* value)
 {
     append(name);
     append(value);
 }
 
-void CommandLine::addOption(const char *name, const std::string &value)
+void CommandLine::addOption(const char* name, const std::string& value)
 {
     addOption(name, value.c_str());
 }
 
-void CommandLine::addOption(const char *name, int value)
+void CommandLine::addOption(const charname, int value)
 {
     append(name);
     append(gmx::toString(value));
 }
 
-void CommandLine::addOption(const char *name, double value)
+void CommandLine::addOption(const charname, double value)
 {
     append(name);
     append(gmx::toString(value));
 }
 
-void CommandLine::merge(const CommandLine &args)
+void CommandLine::merge(const CommandLineargs)
 {
     if (args.argc() > 0)
     {
@@ -226,11 +218,11 @@ void CommandLine::merge(const CommandLine &args)
     }
 }
 
-int &CommandLine::argc()
+intCommandLine::argc()
 {
     return impl_->argc_;
 }
-char **CommandLine::argv()
+char** CommandLine::argv()
 {
     return &impl_->argv_[0];
 }
@@ -238,11 +230,11 @@ int CommandLine::argc() const
 {
     return impl_->argc_;
 }
-const char *const *CommandLine::argv() const
+const char* const* CommandLine::argv() const
 {
     return &impl_->argv_[0];
 }
-const char *CommandLine::arg(int i) const
+const charCommandLine::arg(int i) const
 {
     return impl_->argv_[i];
 }
@@ -252,7 +244,7 @@ std::string CommandLine::toString() const
     return CommandLineProgramContext(argc(), argv()).commandLine();
 }
 
-bool CommandLine::contains(const char *name) const
+bool CommandLine::contains(const charname) const
 {
     for (int i = 0; i < impl_->argc_; ++i)
     {
@@ -270,29 +262,27 @@ bool CommandLine::contains(const char *name) const
 
 class CommandLineTestHelper::Impl
 {
-    public:
-        struct OutputFileInfo
+public:
+    struct OutputFileInfo
+    {
+        OutputFileInfo(const char* option, const std::string& path, FileMatcherPointer matcher) :
+            option(option),
+            path(path),
+            matcher(move(matcher))
         {
-            OutputFileInfo(const char *option, const std::string &path,
-                           FileMatcherPointer matcher)
-                : option(option), path(path), matcher(move(matcher))
-            {
-            }
+        }
 
-            std::string              option;
-            std::string              path;
-            FileMatcherPointer       matcher;
-        };
+        std::string        option;
+        std::string        path;
+        FileMatcherPointer matcher;
+    };
 
-        typedef std::vector<OutputFileInfo>        OutputFileList;
+    typedef std::vector<OutputFileInfo> OutputFileList;
 
-        explicit Impl(TestFileManager *fileManager)
-            : fileManager_(*fileManager)
-        {
-        }
+    explicit Impl(TestFileManager* fileManager) : fileManager_(*fileManager) {}
 
-        TestFileManager &fileManager_;
-        OutputFileList   outputFiles_;
+    TestFileManager& fileManager_;
+    OutputFileList   outputFiles_;
 };
 
 /********************************************************************
@@ -300,8 +290,7 @@ class CommandLineTestHelper::Impl
  */
 
 // static
-int CommandLineTestHelper::runModuleDirect(
-        ICommandLineModule *module, CommandLine *commandLine)
+int CommandLineTestHelper::runModuleDirect(ICommandLineModule* module, CommandLine* commandLine)
 {
     CommandLineModuleSettings settings;
     module->init(&settings);
@@ -309,8 +298,8 @@ int CommandLineTestHelper::runModuleDirect(
 }
 
 // static
-int CommandLineTestHelper::runModuleDirect(
-        std::unique_ptr<ICommandLineOptionsModule> module, CommandLine *commandLine)
+int CommandLineTestHelper::runModuleDirect(std::unique_ptr<ICommandLineOptionsModule> module,
+                                           CommandLine*                               commandLine)
 {
     // The name and description are not used in the tests, so they can be NULL.
     const std::unique_ptr<ICommandLineModule> wrapperModule(
@@ -320,41 +309,41 @@ int CommandLineTestHelper::runModuleDirect(
 
 // static
 int CommandLineTestHelper::runModuleFactory(
-        const std::function<std::unique_ptr<ICommandLineOptionsModule>()> &factory,
-        CommandLine                                                       *commandLine)
+        const std::function<std::unique_ptr<ICommandLineOptionsModule>()>factory,
+        CommandLine*                                                       commandLine)
 {
     return runModuleDirect(factory(), commandLine);
 }
 
-CommandLineTestHelper::CommandLineTestHelper(TestFileManager *fileManager)
-    impl_(new Impl(fileManager))
+CommandLineTestHelper::CommandLineTestHelper(TestFileManager* fileManager) :
+    impl_(new Impl(fileManager))
 {
 }
 
-CommandLineTestHelper::~CommandLineTestHelper()
-{
-}
+CommandLineTestHelper::~CommandLineTestHelper() {}
 
-void CommandLineTestHelper::setInputFileContents(
-        CommandLine *args, const char *option, const char *extension,
-        const std::string &contents)
+void CommandLineTestHelper::setInputFileContents(CommandLine*       args,
+                                                 const char*        option,
+                                                 const char*        extension,
+                                                 const std::string& contents)
 {
     GMX_ASSERT(extension[0] != '.', "Extension should not contain a dot");
-    std::string fullFilename = impl_->fileManager_.getTemporaryFilePath(
-                formatString("%d.%s", args->argc(), extension));
+    std::string fullFilename =
+            impl_->fileManager_.getTemporaryFilePath(formatString("%d.%s", args->argc(), extension));
     TextWriter::writeFileFromString(fullFilename, contents);
     args->addOption(option, fullFilename);
 }
 
-void CommandLineTestHelper::setInputFileContents(
-        CommandLine *args, const char *option, const char *extension,
-        const ArrayRef<const char *const> &contents)
+void CommandLineTestHelper::setInputFileContents(CommandLine*                       args,
+                                                 const char*                        option,
+                                                 const char*                        extension,
+                                                 const ArrayRef<const char* const>& contents)
 {
     GMX_ASSERT(extension[0] != '.', "Extension should not contain a dot");
-    std::string fullFilename = impl_->fileManager_.getTemporaryFilePath(
-                formatString("%d.%s", args->argc(), extension));
-    TextWriter  file(fullFilename);
-    ArrayRef<const char *const>::const_iterator i;
+    std::string fullFilename =
+            impl_->fileManager_.getTemporaryFilePath(formatString("%d.%s", args->argc(), extension));
+    TextWriter                                  file(fullFilename);
+    ArrayRef<const charconst>::const_iterator i;
     for (i = contents.begin(); i != contents.end(); ++i)
     {
         file.writeLine(*i);
@@ -363,16 +352,18 @@ void CommandLineTestHelper::setInputFileContents(
     args->addOption(option, fullFilename);
 }
 
-void CommandLineTestHelper::setOutputFile(
-        CommandLine *args, const char *option, const char *filename,
-        const ITextBlockMatcherSettings &matcher)
+void CommandLineTestHelper::setOutputFile(CommandLine*                     args,
+                                          const char*                      option,
+                                          const char*                      filename,
+                                          const ITextBlockMatcherSettings& matcher)
 {
     setOutputFile(args, option, filename, TextFileMatch(matcher));
 }
 
-void CommandLineTestHelper::setOutputFile(
-        CommandLine *args, const char *option, const char *filename,
-        const IFileMatcherSettings &matcher)
+void CommandLineTestHelper::setOutputFile(CommandLine*                args,
+                                          const char*                 option,
+                                          const char*                 filename,
+                                          const IFileMatcherSettings& matcher)
 {
     std::string suffix(filename);
     if (startsWith(filename, "."))
@@ -388,12 +379,10 @@ void CommandLineTestHelper::checkOutputFiles(TestReferenceChecker checker) const
 {
     if (!impl_->outputFiles_.empty())
     {
-        TestReferenceChecker                 outputChecker(
-                checker.checkCompound("OutputFiles", "Files"));
-        for (const auto &outfile : impl_->outputFiles_)
+        TestReferenceChecker outputChecker(checker.checkCompound("OutputFiles", "Files"));
+        for (const auto& outfile : impl_->outputFiles_)
         {
-            TestReferenceChecker fileChecker(
-                    outputChecker.checkCompound("File", outfile.option.c_str()));
+            TestReferenceChecker fileChecker(outputChecker.checkCompound("File", outfile.option.c_str()));
             outfile.matcher->checkFile(outfile.path, &fileChecker);
         }
     }
@@ -405,51 +394,39 @@ void CommandLineTestHelper::checkOutputFiles(TestReferenceChecker checker) const
 
 class CommandLineTestBase::Impl
 {
-    public:
-        Impl() : helper_(&tempFiles_)
-        {
-            cmdline_.append("module");
-        }
+public:
+    Impl() : helper_(&tempFiles_) { cmdline_.append("module"); }
 
-        TestReferenceData     data_;
-        TestFileManager       tempFiles_;
-        CommandLineTestHelper helper_;
-        CommandLine           cmdline_;
+    TestReferenceData     data_;
+    TestFileManager       tempFiles_;
+    CommandLineTestHelper helper_;
+    CommandLine           cmdline_;
 };
 
 /********************************************************************
  * CommandLineTestBase
  */
 
-CommandLineTestBase::CommandLineTestBase()
-    : impl_(new Impl)
-{
-}
+CommandLineTestBase::CommandLineTestBase() : impl_(new Impl) {}
 
-CommandLineTestBase::~CommandLineTestBase()
-{
-}
+CommandLineTestBase::~CommandLineTestBase() {}
 
-void CommandLineTestBase::setInputFile(
-        const char *option, const char *filename)
+void CommandLineTestBase::setInputFile(const char* option, const char* filename)
 {
     impl_->cmdline_.addOption(option, TestFileManager::getInputFilePath(filename));
 }
 
-void CommandLineTestBase::setInputFile(
-        const char *option, const std::string &filename)
+void CommandLineTestBase::setInputFile(const char* option, const std::string& filename)
 {
     setInputFile(option, filename.c_str());
 }
 
-void CommandLineTestBase::setModifiableInputFile(
-        const char *option, const std::string &filename)
+void CommandLineTestBase::setModifiableInputFile(const char* option, const std::string& filename)
 {
     setModifiableInputFile(option, filename.c_str());
 }
 
-void CommandLineTestBase::setModifiableInputFile(
-        const char *option, const char *filename)
+void CommandLineTestBase::setModifiableInputFile(const char* option, const char* filename)
 {
     std::string originalFileName   = gmx::test::TestFileManager::getInputFilePath(filename);
     std::string modifiableFileName = fileManager().getTemporaryFilePath(filename);
@@ -457,38 +434,37 @@ void CommandLineTestBase::setModifiableInputFile(
     impl_->cmdline_.addOption(option, modifiableFileName);
 }
 
-void CommandLineTestBase::setInputFileContents(
-        const char *option, const char *extension, const std::string &contents)
+void CommandLineTestBase::setInputFileContents(const char*        option,
+                                               const char*        extension,
+                                               const std::string& contents)
 {
-    impl_->helper_.setInputFileContents(&impl_->cmdline_, option, extension,
-                                        contents);
+    impl_->helper_.setInputFileContents(&impl_->cmdline_, option, extension, contents);
 }
 
-void CommandLineTestBase::setInputFileContents(
-        const char *option, const char *extension,
-        const ArrayRef<const char *const> &contents)
+void CommandLineTestBase::setInputFileContents(const char*                        option,
+                                               const char*                        extension,
+                                               const ArrayRef<const char* const>& contents)
 {
-    impl_->helper_.setInputFileContents(&impl_->cmdline_, option, extension,
-                                        contents);
+    impl_->helper_.setInputFileContents(&impl_->cmdline_, option, extension, contents);
 }
 
-void CommandLineTestBase::setOutputFile(
-        const char *option, const char *filename,
-        const ITextBlockMatcherSettings &matcher)
+void CommandLineTestBase::setOutputFile(const char*                      option,
+                                        const char*                      filename,
+                                        const ITextBlockMatcherSettings& matcher)
 {
     impl_->helper_.setOutputFile(&impl_->cmdline_, option, filename, matcher);
 }
 
-void CommandLineTestBase::setOutputFile(
-        const char *option, const char *filename,
-        const IFileMatcherSettings &matcher)
+void CommandLineTestBase::setOutputFile(const char*                 option,
+                                        const char*                 filename,
+                                        const IFileMatcherSettings& matcher)
 {
     impl_->helper_.setOutputFile(&impl_->cmdline_, option, filename, matcher);
 }
 
-void CommandLineTestBase::setInputAndOutputFile(
-        const char *option, const char *filename,
-        const ITextBlockMatcherSettings &matcher)
+void CommandLineTestBase::setInputAndOutputFile(const char*                      option,
+                                                const char*                      filename,
+                                                const ITextBlockMatcherSettings& matcher)
 {
     std::string originalFileName   = gmx::test::TestFileManager::getInputFilePath(filename);
     std::string modifiableFileName = fileManager().getTemporaryFilePath(filename);
@@ -496,9 +472,9 @@ void CommandLineTestBase::setInputAndOutputFile(
     impl_->helper_.setOutputFile(&impl_->cmdline_, option, filename, matcher);
 }
 
-void CommandLineTestBase::setInputAndOutputFile(
-        const char *option, const char *filename,
-        const IFileMatcherSettings &matcher)
+void CommandLineTestBase::setInputAndOutputFile(const char*                 option,
+                                                const char*                 filename,
+                                                const IFileMatcherSettings& matcher)
 {
     std::string originalFileName   = gmx::test::TestFileManager::getInputFilePath(filename);
     std::string modifiableFileName = fileManager().getTemporaryFilePath(filename);
@@ -506,12 +482,12 @@ void CommandLineTestBase::setInputAndOutputFile(
     impl_->helper_.setOutputFile(&impl_->cmdline_, option, filename, matcher);
 }
 
-CommandLine &CommandLineTestBase::commandLine()
+CommandLineCommandLineTestBase::commandLine()
 {
     return impl_->cmdline_;
 }
 
-TestFileManager &CommandLineTestBase::fileManager()
+TestFileManagerCommandLineTestBase::fileManager()
 {
     return impl_->tempFiles_;
 }
@@ -521,19 +497,19 @@ TestReferenceChecker CommandLineTestBase::rootChecker()
     return impl_->data_.rootChecker();
 }
 
-void CommandLineTestBase::setDefaultTolerance(const FloatingPointTolerance &tolerance)
+void CommandLineTestBase::setDefaultTolerance(const FloatingPointTolerancetolerance)
 {
     impl_->data_.rootChecker().setDefaultTolerance(tolerance);
 }
 
-void CommandLineTestBase::testWriteHelp(ICommandLineModule *module)
+void CommandLineTestBase::testWriteHelp(ICommandLineModulemodule)
 {
     StringOutputStream     stream;
     TextWriter             writer(&stream);
     CommandLineHelpContext context(&writer, eHelpOutputFormat_Console, nullptr, "test");
     context.setModuleDisplayName(formatString("%s %s", "test", module->name()));
     module->writeHelp(context);
-    TestReferenceChecker   checker(rootChecker());
+    TestReferenceChecker checker(rootChecker());
     checker.checkTextBlock(stream.toString(), "HelpOutput");
 }