blob: ab530042ccf192f03dccee374fd8c74b4b8dbd2a [file] [log] [blame]
Davide Pesavento2a588152018-02-19 18:10:03 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014-2018, Regents of the University of California,
4 * 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
30namespace nfd {
31namespace tools {
32namespace nfdc {
33namespace tests {
34
35using namespace nfd::tests;
36
37BOOST_AUTO_TEST_SUITE(Nfdc)
38BOOST_FIXTURE_TEST_SUITE(TestHelp, BaseFixture)
39
40BOOST_AUTO_TEST_CASE(Basic)
41{
42 CommandParser parser;
43 ExecuteCommand dummyExecute = [] (ExecuteContext&) { BOOST_ERROR("should not be called"); };
44
45 boost::test_tools::output_test_stream out;
46 const std::string header("nfdc [-h|--help] [-V|--version] <command> [<args>]\n\n");
47 const std::string trailer("\nSee 'nfdc help <command>' to read about a specific subcommand.\n");
48
49 helpList(out, parser);
50 BOOST_CHECK(out.is_equal(header + "All subcommands:\n"
51 " (none)\n"));
52
53 parser.addCommand(CommandDefinition("status", "show"), dummyExecute);
54 parser.addCommand(CommandDefinition("face", "list"), dummyExecute);
55 parser.addCommand(CommandDefinition("route", "list"), dummyExecute);
56 parser.addCommand(CommandDefinition("route", "add"), dummyExecute);
57 parser.addCommand(CommandDefinition("batch", "command"), dummyExecute,
58 AVAILABLE_IN_BATCH | AVAILABLE_IN_HELP);
59
60 helpList(out, parser);
61 BOOST_CHECK(out.is_equal(header +
62 "All subcommands:\n"
63 " status show \n"
64 " face list \n"
65 " route list \n"
66 " route add \n" + trailer));
67
68 helpList(out, parser, ParseMode::ONE_SHOT, "route");
69 BOOST_CHECK(out.is_equal(header +
70 "Subcommands starting with route:\n"
71 " route list \n"
72 " route add \n" + trailer));
73
74 helpList(out, parser, ParseMode::ONE_SHOT, "hello");
75 BOOST_CHECK(out.is_equal(header +
76 "Subcommands starting with hello:\n"
77 " (none)\n"));
78
79 helpList(out, parser, ParseMode::BATCH);
80 BOOST_CHECK(out.is_equal(header +
81 "All subcommands:\n"
82 " status show \n"
83 " face list \n"
84 " route list \n"
85 " route add \n"
86 " batch command \n" + trailer));
87
88 BOOST_CHECK_EQUAL(help(out, parser, {}), 2);
89 BOOST_CHECK(out.is_empty());
90
91 BOOST_CHECK_EQUAL(help(out, parser, {"help"}), 0);
92 BOOST_CHECK(out.is_equal(header +
93 "All subcommands:\n"
94 " status show \n"
95 " face list \n"
96 " route list \n"
97 " route add \n" + trailer));
98}
99
100BOOST_AUTO_TEST_SUITE_END() // TestCommandParser
101BOOST_AUTO_TEST_SUITE_END() // Nfdc
102
103} // namespace tests
104} // namespace nfdc
105} // namespace tools
106} // namespace nfd