Skip to content

Commit

Permalink
Play with tests
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Agüero <[email protected]>
  • Loading branch information
caguero committed Feb 3, 2024
1 parent b4d6377 commit 157311e
Showing 1 changed file with 58 additions and 64 deletions.
122 changes: 58 additions & 64 deletions src/cmd/gz_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,6 @@ TEST(gzTest, TopicListSub)
node.Subscribe("/no", topicCB);
node.Unsubscribe("/no");

// Check the 'gz topic -l' command.
std::string gz = std::string(GZ_PATH);

unsigned int retries = 0u;
bool topicFound = false;

auto output = exec_with_retry({"topic", "-l"},
[](auto procOut){
return procOut.cout.find("/foo\n") != std::string::npos &&
Expand Down Expand Up @@ -406,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, 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;
// }
// }

//////////////////////////////////////////////////
/// \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, 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;
// }
// }

/// Main
int main(int argc, char **argv)
Expand Down

0 comments on commit 157311e

Please sign in to comment.