Skip to content

Commit

Permalink
Re-enable tests of bash completion functions for gz
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll committed Feb 12, 2024
1 parent 502f519 commit ab4912e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 58 deletions.
116 changes: 58 additions & 58 deletions src/cmd/gz_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -400,68 +400,68 @@ TEST(gzTest, TopicEchoNum)
//////////////////////////////////////////////////
/// \brief Check 'gz service --help' message and bash completion script for
/// consistent flags
// TEST(gzTest, ServiceHelpVsCompletionFlags)
// {
// // Flags in help message
// std::string helpOutput = custom_exec_str("gz service --help");

// // Call the output function in the bash completion script
// std::filesystem::path scriptPath = PROJECT_SOURCE_DIR;
// scriptPath = scriptPath / "src" / "cmd" / "transport.bash_completion.sh";

// // Equivalent to:
// // sh -c "bash -c \". /path/to/transport.bash_completion.sh;
// // _gz_service_flags\""
// std::string cmd = "bash -c \". " + scriptPath.string() +
// "; _gz_service_flags\"";
// std::string scriptOutput = custom_exec_str(cmd);

// // Tokenize script output
// std::istringstream iss(scriptOutput);
// std::vector<std::string> flags((std::istream_iterator<std::string>(iss)),
// std::istream_iterator<std::string>());

// EXPECT_GT(flags.size(), 0u);

// // Match each flag in script output with help message
// for (const auto &flag : flags)
// {
// EXPECT_NE(std::string::npos, helpOutput.find(flag)) << helpOutput;
// }
// }
TEST(gzTest, GZ_UTILS_TEST_DISABLED_ON_WIN32(ServiceHelpVsCompletionFlags))
{
// Flags in help message
auto helpOutput = custom_exec_str({"service", "--help"});

// Equivalent to:
// sh -c "bash -c \". /path/to/transport.bash_completion.sh;
// _gz_service_flags\""
auto proc = gz::utils::Subprocess(
{"/usr/bin/bash", "-c",
"\"\". " + std::string(kTransportBashCompletion) +
"; _gz_service_flags\"\""});
auto return_code = proc.Join();
EXPECT_EQ(0u, return_code);

// Tokenize script output
std::istringstream iss(proc.Stdout());
std::vector<std::string> flags(
(std::istream_iterator<std::string>(iss)),
std::istream_iterator<std::string>());

EXPECT_GT(flags.size(), 0u);

// Match each flag in script output with help message
for (const auto &flag : flags)
{
EXPECT_NE(std::string::npos, helpOutput.cout.find(flag)) << helpOutput.cout;
}
}

//////////////////////////////////////////////////
/// \brief Check 'gz topic --help' message and bash completion script for
/// consistent flags
// TEST(gzTest, TopicHelpVsCompletionFlags)
// {
// // Flags in help message
// std::string helpOutput = custom_exec_str("gz topic --help");

// // Call the output function in the bash completion script
// std::filesystem::path scriptPath = PROJECT_SOURCE_DIR;
// scriptPath = scriptPath / "src" / "cmd" / "transport.bash_completion.sh";

// // Equivalent to:
// // sh -c "bash -c \". /path/to/transport.bash_completion.sh;
// // _gz_topic_flags\""
// std::string cmd = "bash -c \". " + scriptPath.string() +
// "; _gz_topic_flags\"";
// std::string scriptOutput = custom_exec_str(cmd);

// // Tokenize script output
// std::istringstream iss(scriptOutput);
// std::vector<std::string> flags((std::istream_iterator<std::string>(iss)),
// std::istream_iterator<std::string>());

// EXPECT_GT(flags.size(), 0u);

// // Match each flag in script output with help message
// for (const auto &flag : flags)
// {
// EXPECT_NE(std::string::npos, helpOutput.find(flag)) << helpOutput;
// }
// }
TEST(gzTest, GZ_UTILS_TEST_DISABLED_ON_WIN32(TopicHelpVsCompletionFlags))
{
// Flags in help message
auto helpOutput = custom_exec_str({"topic", "--help"});

// Equivalent to:
// sh -c "bash -c \". /path/to/transport.bash_completion.sh;
// _gz_topic_flags\""
auto proc = gz::utils::Subprocess(
{"/usr/bin/bash", "-c",
"\"\". " + std::string(kTransportBashCompletion) +
"; _gz_topic_flags\"\""});
auto return_code = proc.Join();
EXPECT_EQ(0u, return_code);

// Tokenize script output
std::istringstream iss(proc.Stdout());
std::vector<std::string> flags(
(std::istream_iterator<std::string>(iss)),
std::istream_iterator<std::string>());

EXPECT_GT(flags.size(), 0u);

// Match each flag in script output with help message
for (const auto &flag : flags)
{
EXPECT_NE(std::string::npos, helpOutput.cout.find(flag)) << helpOutput.cout;
}
}

/// Main
int main(int argc, char **argv)
Expand Down
Empty file modified src/cmd/transport.bash_completion.sh
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ target_include_directories(test_config INTERFACE
target_compile_definitions(test_config INTERFACE
# Location of the "gz" command
"GZ_EXE=\"${HAVE_GZ_TOOLS}\""
"TRANSPORT_BASH_COMPLETION_SH=\"${PROJECT_SOURCE_DIR}/src/cmd/transport.bash_completion.sh\""
# Auxillary executables for test
"AUTH_PUB_SUB_SUBSCRIBER_INVALID_EXE=\"$<TARGET_FILE:authPubSubSubscriberInvalid_aux>\""
"FAST_PUB_EXE=\"$<TARGET_FILE:fastPub_aux>\""
Expand Down
4 changes: 4 additions & 0 deletions test/test_config.hh.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

constexpr const char * kGzVersion = "@PROJECT_VERSION_FULL@";

#ifdef TRANSPORT_BASH_COMPLETION_SH
constexpr const char* kTransportBashCompletion = TRANSPORT_BASH_COMPLETION_SH;
#endif // TRANSPORT_BASH_COMPLETION_SH

namespace test_executables
{

Expand Down

0 comments on commit ab4912e

Please sign in to comment.