2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017,2018,2019, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
37 * Tests gmx::CommandLineModuleManager.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
40 * \ingroup module_commandline
44 #include "gromacs/commandline/cmdlinemodulemanager.h"
46 #include <gmock/gmock.h>
48 #include "testutils/cmdlinetest.h"
49 #include "testutils/testasserts.h"
51 #include "cmdlinemodulemanagertest.h"
56 using gmx::test::CommandLine;
57 using gmx::test::MockModule;
59 //! Test fixture for the tests.
60 typedef gmx::test::CommandLineModuleManagerTestBase CommandLineModuleManagerTest;
62 TEST_F(CommandLineModuleManagerTest, RunsModule)
64 const char* const cmdline[] = { "test", "module", "-flag", "yes" };
65 CommandLine args(cmdline);
66 initManager(args, "test");
67 MockModule& mod1 = addModule("module", "First module");
68 addModule("other", "Second module");
70 using ::testing::Args;
71 using ::testing::ElementsAreArray;
72 EXPECT_CALL(mod1, init(_));
73 EXPECT_CALL(mod1, run(_, _)).With(Args<1, 0>(ElementsAreArray(args.argv() + 1, args.argc() - 1)));
75 ASSERT_NO_THROW_GMX(rc = manager().run(args.argc(), args.argv()));
79 TEST_F(CommandLineModuleManagerTest, RunsModuleHelp)
81 const char* const cmdline[] = { "test", "help", "module" };
82 CommandLine args(cmdline);
83 initManager(args, "test");
84 MockModule& mod1 = addModule("module", "First module");
85 addModule("other", "Second module");
87 EXPECT_CALL(mod1, writeHelp(_));
88 mod1.setExpectedDisplayName("test module");
90 ASSERT_NO_THROW_GMX(rc = manager().run(args.argc(), args.argv()));
94 TEST_F(CommandLineModuleManagerTest, RunsModuleHelpAfterQuiet)
96 const char* const cmdline[] = { "test", "-quiet", "help", "module" };
97 CommandLine args(cmdline);
98 initManager(args, "test");
99 MockModule& mod1 = addModule("module", "First module");
100 addModule("other", "Second module");
102 EXPECT_CALL(mod1, writeHelp(_));
103 mod1.setExpectedDisplayName("test module");
105 ASSERT_NO_THROW_GMX(rc = manager().run(args.argc(), args.argv()));
109 TEST_F(CommandLineModuleManagerTest, RunsModuleHelpWithDashH)
111 const char* const cmdline[] = { "test", "module", "-h" };
112 CommandLine args(cmdline);
113 initManager(args, "test");
114 MockModule& mod1 = addModule("module", "First module");
115 addModule("other", "Second module");
117 EXPECT_CALL(mod1, writeHelp(_));
118 mod1.setExpectedDisplayName("test module");
120 ASSERT_NO_THROW_GMX(rc = manager().run(args.argc(), args.argv()));
124 TEST_F(CommandLineModuleManagerTest, RunsModuleHelpWithDashHWithSingleModule)
126 const char* const cmdline[] = { "g_module", "-h" };
127 CommandLine args(cmdline);
128 initManager(args, "g_module");
129 MockModule mod(nullptr, nullptr);
130 manager().setSingleModule(&mod);
132 EXPECT_CALL(mod, writeHelp(_));
133 mod.setExpectedDisplayName("g_module");
135 ASSERT_NO_THROW_GMX(rc = manager().run(args.argc(), args.argv()));
139 TEST_F(CommandLineModuleManagerTest, HandlesConflictingBinaryAndModuleNames)
141 const char* const cmdline[] = { "test", "test", "-flag", "yes" };
142 CommandLine args(cmdline);
143 initManager(args, "test");
144 MockModule& mod1 = addModule("test", "Test module");
145 addModule("other", "Second module");
147 using ::testing::Args;
148 using ::testing::ElementsAreArray;
149 EXPECT_CALL(mod1, init(_));
150 EXPECT_CALL(mod1, run(_, _)).With(Args<1, 0>(ElementsAreArray(args.argv() + 1, args.argc() - 1)));
152 ASSERT_NO_THROW_GMX(rc = manager().run(args.argc(), args.argv()));