Introduce SimulatorBuilder
[gromacs.git] / src / gromacs / commandline / tests / cmdlinemodulemanager.cpp
blob6558a8da8a8e3d02ff0387e08847550a044033c9
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017,2018, 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.
35 /*! \internal \file
36 * \brief
37 * Tests gmx::CommandLineModuleManager.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
40 * \ingroup module_commandline
42 #include "gmxpre.h"
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"
53 namespace
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[] = {
65 "test", "module", "-flag", "yes"
67 CommandLine args(cmdline);
68 initManager(args, "test");
69 MockModule &mod1 = addModule("module", "First module");
70 addModule("other", "Second module");
71 using ::testing::_;
72 using ::testing::Args;
73 using ::testing::ElementsAreArray;
74 EXPECT_CALL(mod1, init(_));
75 EXPECT_CALL(mod1, run(_, _))
76 .With(Args<1, 0>(ElementsAreArray(args.argv() + 1, args.argc() - 1)));
77 int rc = 0;
78 ASSERT_NO_THROW_GMX(rc = manager().run(args.argc(), args.argv()));
79 ASSERT_EQ(0, rc);
82 TEST_F(CommandLineModuleManagerTest, RunsModuleHelp)
84 const char *const cmdline[] = {
85 "test", "help", "module"
87 CommandLine args(cmdline);
88 initManager(args, "test");
89 MockModule &mod1 = addModule("module", "First module");
90 addModule("other", "Second module");
91 using ::testing::_;
92 EXPECT_CALL(mod1, writeHelp(_));
93 mod1.setExpectedDisplayName("test module");
94 int rc = 0;
95 ASSERT_NO_THROW_GMX(rc = manager().run(args.argc(), args.argv()));
96 ASSERT_EQ(0, rc);
99 TEST_F(CommandLineModuleManagerTest, RunsModuleHelpAfterQuiet)
101 const char *const cmdline[] = {
102 "test", "-quiet", "help", "module"
104 CommandLine args(cmdline);
105 initManager(args, "test");
106 MockModule &mod1 = addModule("module", "First module");
107 addModule("other", "Second module");
108 using ::testing::_;
109 EXPECT_CALL(mod1, writeHelp(_));
110 mod1.setExpectedDisplayName("test module");
111 int rc = 0;
112 ASSERT_NO_THROW_GMX(rc = manager().run(args.argc(), args.argv()));
113 ASSERT_EQ(0, rc);
116 TEST_F(CommandLineModuleManagerTest, RunsModuleHelpWithDashH)
118 const char *const cmdline[] = {
119 "test", "module", "-h"
121 CommandLine args(cmdline);
122 initManager(args, "test");
123 MockModule &mod1 = addModule("module", "First module");
124 addModule("other", "Second module");
125 using ::testing::_;
126 EXPECT_CALL(mod1, writeHelp(_));
127 mod1.setExpectedDisplayName("test module");
128 int rc = 0;
129 ASSERT_NO_THROW_GMX(rc = manager().run(args.argc(), args.argv()));
130 ASSERT_EQ(0, rc);
133 TEST_F(CommandLineModuleManagerTest, RunsModuleHelpWithDashHWithSingleModule)
135 const char *const cmdline[] = {
136 "g_module", "-h"
138 CommandLine args(cmdline);
139 initManager(args, "g_module");
140 MockModule mod(nullptr, nullptr);
141 manager().setSingleModule(&mod);
142 using ::testing::_;
143 EXPECT_CALL(mod, writeHelp(_));
144 mod.setExpectedDisplayName("g_module");
145 int rc = 0;
146 ASSERT_NO_THROW_GMX(rc = manager().run(args.argc(), args.argv()));
147 ASSERT_EQ(0, rc);
150 TEST_F(CommandLineModuleManagerTest, HandlesConflictingBinaryAndModuleNames)
152 const char *const cmdline[] = {
153 "test", "test", "-flag", "yes"
155 CommandLine args(cmdline);
156 initManager(args, "test");
157 MockModule &mod1 = addModule("test", "Test module");
158 addModule("other", "Second module");
159 using ::testing::_;
160 using ::testing::Args;
161 using ::testing::ElementsAreArray;
162 EXPECT_CALL(mod1, init(_));
163 EXPECT_CALL(mod1, run(_, _))
164 .With(Args<1, 0>(ElementsAreArray(args.argv() + 1, args.argc() - 1)));
165 int rc = 0;
166 ASSERT_NO_THROW_GMX(rc = manager().run(args.argc(), args.argv()));
167 ASSERT_EQ(0, rc);
170 } // namespace