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