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 auto& arg : cmdline)
{
- char *argCopy = strdup(arg);
+ char* argCopy = strdup(arg);
if (argCopy == nullptr)
{
throw std::bad_alloc();
{
//! 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()
{
* 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 char* arg)
{
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);
+ char* newArg = strdup(arg);
if (newArg == nullptr)
{
throw std::bad_alloc();
impl_->argc_ = static_cast<int>(newSize);
}
-void CommandLine::addOption(const char *name)
+void CommandLine::addOption(const char* name)
{
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 char* name, int value)
{
append(name);
append(gmx::toString(value));
}
-void CommandLine::addOption(const char *name, double value)
+void CommandLine::addOption(const char* name, double value)
{
append(name);
append(gmx::toString(value));
}
-void CommandLine::merge(const CommandLine &args)
+void CommandLine::merge(const CommandLine& args)
{
if (args.argc() > 0)
{
}
}
-int &CommandLine::argc()
+int& CommandLine::argc()
{
return impl_->argc_;
}
-char **CommandLine::argv()
+char** CommandLine::argv()
{
return &impl_->argv_[0];
}
{
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 char* CommandLine::arg(int i) const
{
return impl_->argv_[i];
}
return CommandLineProgramContext(argc(), argv()).commandLine();
}
-bool CommandLine::contains(const char *name) const
+bool CommandLine::contains(const char* name) const
{
for (int i = 0; i < impl_->argc_; ++i)
{
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_;
};
/********************************************************************
*/
// static
-int CommandLineTestHelper::runModuleDirect(
- ICommandLineModule *module, CommandLine *commandLine)
+int CommandLineTestHelper::runModuleDirect(ICommandLineModule* module, CommandLine* commandLine)
{
CommandLineModuleSettings settings;
module->init(&settings);
}
// 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(
// 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 char* const>::const_iterator i;
for (i = contents.begin(); i != contents.end(); ++i)
{
file.writeLine(*i);
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, "."))
{
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);
}
}
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);
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);
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);
impl_->helper_.setOutputFile(&impl_->cmdline_, option, filename, matcher);
}
-CommandLine &CommandLineTestBase::commandLine()
+CommandLine& CommandLineTestBase::commandLine()
{
return impl_->cmdline_;
}
-TestFileManager &CommandLineTestBase::fileManager()
+TestFileManager& CommandLineTestBase::fileManager()
{
return impl_->tempFiles_;
}
return impl_->data_.rootChecker();
}
-void CommandLineTestBase::setDefaultTolerance(const FloatingPointTolerance &tolerance)
+void CommandLineTestBase::setDefaultTolerance(const FloatingPointTolerance& tolerance)
{
impl_->data_.rootChecker().setDefaultTolerance(tolerance);
}
-void CommandLineTestBase::testWriteHelp(ICommandLineModule *module)
+void CommandLineTestBase::testWriteHelp(ICommandLineModule* module)
{
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");
}