blob: c5d50129249d2905cbf67de144067e473aab85dd [file] [log] [blame]
Davide Pesavento2a588152018-02-19 18:10:03 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Alexander Afanasyevc414ca52021-06-09 12:15:19 -04003 * Copyright (c) 2014-2021, Regents of the University of California,
Davide Pesavento2a588152018-02-19 18:10:03 -05004 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#include "nfdc/help.hpp"
27
28#include "tests/test-common.hpp"
29
Davide Pesaventocf9e1c72019-12-22 17:56:07 -050030#if BOOST_VERSION >= 105900
31#include <boost/test/tools/output_test_stream.hpp>
32#else
33#include <boost/test/output_test_stream.hpp>
34#endif
35
Davide Pesavento2a588152018-02-19 18:10:03 -050036namespace nfd {
37namespace tools {
38namespace nfdc {
39namespace tests {
40
Davide Pesavento2a588152018-02-19 18:10:03 -050041BOOST_AUTO_TEST_SUITE(Nfdc)
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040042BOOST_AUTO_TEST_SUITE(TestHelp)
Davide Pesavento2a588152018-02-19 18:10:03 -050043
44BOOST_AUTO_TEST_CASE(Basic)
45{
46 CommandParser parser;
47 ExecuteCommand dummyExecute = [] (ExecuteContext&) { BOOST_ERROR("should not be called"); };
48
49 boost::test_tools::output_test_stream out;
Alexander Afanasyevc414ca52021-06-09 12:15:19 -040050 const std::string header("nfdc [-h|--help] [-V|--version] [-f|--batch <batch-file>] [<command> [<args>]]\n\n");
Davide Pesavento2a588152018-02-19 18:10:03 -050051 const std::string trailer("\nSee 'nfdc help <command>' to read about a specific subcommand.\n");
52
53 helpList(out, parser);
54 BOOST_CHECK(out.is_equal(header + "All subcommands:\n"
55 " (none)\n"));
56
57 parser.addCommand(CommandDefinition("status", "show"), dummyExecute);
58 parser.addCommand(CommandDefinition("face", "list"), dummyExecute);
59 parser.addCommand(CommandDefinition("route", "list"), dummyExecute);
60 parser.addCommand(CommandDefinition("route", "add"), dummyExecute);
61 parser.addCommand(CommandDefinition("batch", "command"), dummyExecute,
62 AVAILABLE_IN_BATCH | AVAILABLE_IN_HELP);
63
64 helpList(out, parser);
65 BOOST_CHECK(out.is_equal(header +
66 "All subcommands:\n"
67 " status show \n"
68 " face list \n"
69 " route list \n"
70 " route add \n" + trailer));
71
72 helpList(out, parser, ParseMode::ONE_SHOT, "route");
73 BOOST_CHECK(out.is_equal(header +
74 "Subcommands starting with route:\n"
75 " route list \n"
76 " route add \n" + trailer));
77
78 helpList(out, parser, ParseMode::ONE_SHOT, "hello");
79 BOOST_CHECK(out.is_equal(header +
80 "Subcommands starting with hello:\n"
81 " (none)\n"));
82
83 helpList(out, parser, ParseMode::BATCH);
84 BOOST_CHECK(out.is_equal(header +
85 "All subcommands:\n"
86 " status show \n"
87 " face list \n"
88 " route list \n"
89 " route add \n"
90 " batch command \n" + trailer));
91
92 BOOST_CHECK_EQUAL(help(out, parser, {}), 2);
93 BOOST_CHECK(out.is_empty());
94
95 BOOST_CHECK_EQUAL(help(out, parser, {"help"}), 0);
96 BOOST_CHECK(out.is_equal(header +
97 "All subcommands:\n"
98 " status show \n"
99 " face list \n"
100 " route list \n"
101 " route add \n" + trailer));
102}
103
104BOOST_AUTO_TEST_SUITE_END() // TestCommandParser
105BOOST_AUTO_TEST_SUITE_END() // Nfdc
106
107} // namespace tests
108} // namespace nfdc
109} // namespace tools
110} // namespace nfd