From: Teemu Murtola Date: Wed, 3 Jun 2015 19:17:20 +0000 (+0300) Subject: Resolve one TODO for command line help tests X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=0b8ea39f7c607708c71a08084b8591f54c5a84e7;p=alexxy%2Fgromacs.git Resolve one TODO for command line help tests Make [PROGRAM] replacement respect the binary name passed to CommandLineModuleManager, giving the tests full control over the help output. There are complications making this work nicely in the selection help (requires some effort in propagating the information), so change the wording there for now to avoid this tag. Can be revisited at a later time if/when the help writing context is more uniform for different cases that can trigger the selection help ('gmx help ...' vs. 'help ...' in the selection prompt). Change-Id: I93e7dd8279d3730d38122c212174e533420859b9 --- diff --git a/src/gromacs/commandline/cmdlinehelpcontext.cpp b/src/gromacs/commandline/cmdlinehelpcontext.cpp index d18951146a..cfe32fbf38 100644 --- a/src/gromacs/commandline/cmdlinehelpcontext.cpp +++ b/src/gromacs/commandline/cmdlinehelpcontext.cpp @@ -97,9 +97,11 @@ class CommandLineHelpContext::Impl }; CommandLineHelpContext::CommandLineHelpContext( - File *file, HelpOutputFormat format, const HelpLinks *links) + File *file, HelpOutputFormat format, const HelpLinks *links, + const std::string &programName) : impl_(new Impl(file, format, links)) { + impl_->writerContext_.setReplacement("[PROGRAM]", programName); } CommandLineHelpContext::CommandLineHelpContext( diff --git a/src/gromacs/commandline/cmdlinehelpcontext.h b/src/gromacs/commandline/cmdlinehelpcontext.h index e5e48e003c..330f20aa6f 100644 --- a/src/gromacs/commandline/cmdlinehelpcontext.h +++ b/src/gromacs/commandline/cmdlinehelpcontext.h @@ -43,6 +43,8 @@ #ifndef GMX_COMMANDLINE_CMDLINEHELPCONTEXT_H #define GMX_COMMANDLINE_CMDLINEHELPCONTEXT_H +#include + #include "gromacs/onlinehelp/helpwritercontext.h" #include "gromacs/utility/classhelpers.h" @@ -75,7 +77,8 @@ class CommandLineHelpContext * Wraps the constructor of HelpWriterContext. */ CommandLineHelpContext(File *file, HelpOutputFormat format, - const HelpLinks *links); + const HelpLinks *links, + const std::string &programName); //! Creates a context for a particular HelpWriterContext. explicit CommandLineHelpContext(const HelpWriterContext &writerContext); /*! \brief diff --git a/src/gromacs/commandline/cmdlinehelpmodule.cpp b/src/gromacs/commandline/cmdlinehelpmodule.cpp index bc883a0849..1183ce68f2 100644 --- a/src/gromacs/commandline/cmdlinehelpmodule.cpp +++ b/src/gromacs/commandline/cmdlinehelpmodule.cpp @@ -298,7 +298,6 @@ void RootHelpTopic::writeHelp(const HelpWriterContext &context) const // to determine such a set... writeSubTopicList(context, "Additional help is available on the following topics:"); - // TODO: Make these respect the binary name passed in, to make tests work better. context.writeTextBlock("To access the help, use '[PROGRAM] help '."); context.writeTextBlock("For help on a command, use '[PROGRAM] help '."); } @@ -564,7 +563,7 @@ void HelpExportReStructuredText::exportModuleHelp( } file.writeLine(); - CommandLineHelpContext context(&file, eHelpOutputFormat_Rst, &links_); + CommandLineHelpContext context(&file, eHelpOutputFormat_Rst, &links_, binaryName_); context.enterSubSection(displayName); context.setModuleDisplayName(displayName); module.writeHelp(context); @@ -651,10 +650,11 @@ void HelpExportReStructuredText::finishModuleGroupExport() void HelpExportReStructuredText::exportTopic(const HelpTopicInterface &topic) { - const std::string path("onlinehelp/" + std::string(topic.name()) + ".rst"); - File file(outputRedirector_->openFileForWriting(path)); - HelpWriterContext context(&file, eHelpOutputFormat_Rst, &links_); - HelpManager manager(topic, context); + const std::string path("onlinehelp/" + std::string(topic.name()) + ".rst"); + File file(outputRedirector_->openFileForWriting(path)); + CommandLineHelpContext context(&file, eHelpOutputFormat_Rst, &links_, + binaryName_); + HelpManager manager(topic, context.writerContext()); manager.writeCurrentTopic(); } @@ -853,7 +853,8 @@ int CommandLineHelpModule::run(int argc, char *argv[]) File &outputFile = impl_->outputRedirector_->standardOutput(); HelpLinks links(eHelpOutputFormat_Console); initProgramLinks(&links, *impl_); - CommandLineHelpContext context(&outputFile, eHelpOutputFormat_Console, &links); + CommandLineHelpContext context(&outputFile, eHelpOutputFormat_Console, &links, + impl_->binaryName_); context.setShowHidden(impl_->bHidden_); if (impl_->moduleOverride_ != NULL) { diff --git a/src/gromacs/commandline/tests/cmdlinehelpwriter.cpp b/src/gromacs/commandline/tests/cmdlinehelpwriter.cpp index a545dcc835..317cc4c9ab 100644 --- a/src/gromacs/commandline/tests/cmdlinehelpwriter.cpp +++ b/src/gromacs/commandline/tests/cmdlinehelpwriter.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by + * Copyright (c) 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. @@ -79,7 +79,8 @@ void CommandLineHelpWriterTest::checkHelp(gmx::CommandLineHelpWriter *writer) { std::string filename = tempFiles_.getTemporaryFilePath("helptext.txt"); gmx::File file(filename, "w"); - gmx::CommandLineHelpContext context(&file, gmx::eHelpOutputFormat_Console, NULL); + gmx::CommandLineHelpContext context(&file, gmx::eHelpOutputFormat_Console, + NULL, "test"); context.setShowHidden(bHidden_); writer->writeHelp(context); file.close(); diff --git a/src/gromacs/commandline/tests/refdata/CommandLineHelpModuleTest_ExportsHelp.xml b/src/gromacs/commandline/tests/refdata/CommandLineHelpModuleTest_ExportsHelp.xml index 2f4103fdcc..f92487f6eb 100644 --- a/src/gromacs/commandline/tests/refdata/CommandLineHelpModuleTest_ExportsHelp.xml +++ b/src/gromacs/commandline/tests/refdata/CommandLineHelpModuleTest_ExportsHelp.xml @@ -168,7 +168,7 @@ Other options: test commands ------------- -The following commands are available. Please refer to their individual man pages or ``commandline-test help `` for further details. +The following commands are available. Please refer to their individual man pages or ``test help `` for further details. .. include:: /fragments/bytopic-man.rst ]]> diff --git a/src/gromacs/commandline/tests/refdata/CommandLineHelpModuleTest_PrintsGeneralHelp.xml b/src/gromacs/commandline/tests/refdata/CommandLineHelpModuleTest_PrintsGeneralHelp.xml index 4c8cf2a720..b8c655d7fa 100644 --- a/src/gromacs/commandline/tests/refdata/CommandLineHelpModuleTest_PrintsGeneralHelp.xml +++ b/src/gromacs/commandline/tests/refdata/CommandLineHelpModuleTest_PrintsGeneralHelp.xml @@ -21,7 +21,7 @@ Other options: Additional help is available on the following topics: commands List of available commands topic Test topic -To access the help, use 'commandline-test help '. -For help on a command, use 'commandline-test help '. +To access the help, use 'test help '. +For help on a command, use 'test help '. ]]> diff --git a/src/gromacs/onlinehelp/helpwritercontext.cpp b/src/gromacs/onlinehelp/helpwritercontext.cpp index 0c3c37abf3..1f3101db4c 100644 --- a/src/gromacs/onlinehelp/helpwritercontext.cpp +++ b/src/gromacs/onlinehelp/helpwritercontext.cpp @@ -470,11 +470,8 @@ class HelpWriterContext::Impl Impl(const StatePointer &state, int sectionDepth) : state_(state), sectionDepth_(sectionDepth) { - initDefaultReplacements(); } - //! Initializes default replacements for the chosen output format. - void initDefaultReplacements(); //! Adds a new replacement. void addReplacement(const std::string &search, const std::string &replace) @@ -508,12 +505,6 @@ class HelpWriterContext::Impl GMX_DISALLOW_ASSIGN(Impl); }; -void HelpWriterContext::Impl::initDefaultReplacements() -{ - const char *program = getProgramContext().programName(); - addReplacement("[PROGRAM]", program); -} - std::string HelpWriterContext::Impl::replaceLinks(const std::string &input) const { std::string result(input); diff --git a/src/gromacs/selection/selhelp.cpp b/src/gromacs/selection/selhelp.cpp index 891e927509..e96a955f71 100644 --- a/src/gromacs/selection/selhelp.cpp +++ b/src/gromacs/selection/selhelp.cpp @@ -127,7 +127,7 @@ const char *const CmdLineHelpText::text[] = { "if they are complex or for scripting.[PAR]", "Each tool has different command-line arguments for specifying selections", - "(listed by [TT][PROGRAM] help [tt]).", + "(see the help for the individual tools).", "You can either pass a single string containing all selections (separated", "by semicolons), or multiple strings, each containing one selection.", "Note that you need to quote the selections to protect them from the", diff --git a/src/testutils/testinit.cpp b/src/testutils/testinit.cpp index 4bfdd9e203..0fd8d1100b 100644 --- a/src/testutils/testinit.cpp +++ b/src/testutils/testinit.cpp @@ -138,12 +138,13 @@ class TestProgramContext : public ProgramContextInterface //! Prints the command-line options for the unit test binary. void printHelp(const Options &options) { + const std::string &program = getProgramContext().displayName(); std::fprintf(stderr, "\nYou can use the following GROMACS-specific command-line flags\n" "to control the behavior of the tests:\n\n"); CommandLineHelpContext context(&File::standardError(), - eHelpOutputFormat_Console, NULL); - context.setModuleDisplayName(getProgramContext().displayName()); + eHelpOutputFormat_Console, NULL, program); + context.setModuleDisplayName(program); CommandLineHelpWriter(options).writeHelp(context); }