Resolve one TODO for command line help tests
authorTeemu Murtola <teemu.murtola@gmail.com>
Wed, 3 Jun 2015 19:17:20 +0000 (22:17 +0300)
committerMark Abraham <mark.j.abraham@gmail.com>
Tue, 9 Jun 2015 04:41:28 +0000 (06:41 +0200)
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

src/gromacs/commandline/cmdlinehelpcontext.cpp
src/gromacs/commandline/cmdlinehelpcontext.h
src/gromacs/commandline/cmdlinehelpmodule.cpp
src/gromacs/commandline/tests/cmdlinehelpwriter.cpp
src/gromacs/commandline/tests/refdata/CommandLineHelpModuleTest_ExportsHelp.xml
src/gromacs/commandline/tests/refdata/CommandLineHelpModuleTest_PrintsGeneralHelp.xml
src/gromacs/onlinehelp/helpwritercontext.cpp
src/gromacs/selection/selhelp.cpp
src/testutils/testinit.cpp

index d18951146a7dbe98dc4c34385be6dc42f2cce18d..cfe32fbf38905227976a8f86633fd6fdb9ace6d6 100644 (file)
@@ -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(
index e5e48e003c448530b5fec3ef0ba18c31686367fd..330f20aa6f486572d71bbf11c57abd27698c4876 100644 (file)
@@ -43,6 +43,8 @@
 #ifndef GMX_COMMANDLINE_CMDLINEHELPCONTEXT_H
 #define GMX_COMMANDLINE_CMDLINEHELPCONTEXT_H
 
+#include <string>
+
 #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
index bc883a084974685adb2028d45d22d2379b3c2d72..1183ce68f23054f647673f2051d9b8792739a8a0 100644 (file)
@@ -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 <topic>'.");
         context.writeTextBlock("For help on a command, use '[PROGRAM] help <command>'.");
     }
@@ -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)
     {
index a545dcc835556abd1b4c2bfaf3883ed2c7c55bf7..317cc4c9ab8c5dec62e564fb9c3278bd85c7a0a8 100644 (file)
@@ -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();
index 2f4103fdcc162471a6d19b6cbd1bf87352cfdcf3..f92487f6eb7ccc90ff0fb14a07e58c41147d92ee 100644 (file)
@@ -168,7 +168,7 @@ Other options:
 
 test commands
 -------------
-The following commands are available. Please refer to their individual man pages or ``commandline-test help <command>`` for further details.
+The following commands are available. Please refer to their individual man pages or ``test help <command>`` for further details.
 
 .. include:: /fragments/bytopic-man.rst
 ]]></String>
index 4c8cf2a720dabc2551ee68181a9d9a11170145c4..b8c655d7fa7017870eb3bf959c07a3fd88b03543 100644 (file)
@@ -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 <topic>'.
-For help on a command, use 'commandline-test help <command>'.
+To access the help, use 'test help <topic>'.
+For help on a command, use 'test help <command>'.
 ]]></String>
 </ReferenceData>
index 0c3c37abf373baedc9d9b6a656610c08f913a4cc..1f3101db4ca1ef4bdd703856205f92c9be40fa9e 100644 (file)
@@ -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);
index 891e927509aaca89e6252e7d8a7190d51eb43e02..e96a955f716b7198179e1e9b130efd1b3918c217 100644 (file)
@@ -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 <tool>[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",
index 4bfdd9e2030c690451170887d3bef209064bc609..0fd8d1100b1784407475280e25f382c6930a47f9 100644 (file)
@@ -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);
 }