Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TEST] Print command on failure #115

Merged
merged 1 commit into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/cli/build/cli_build_hibf_chopper_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ TEST_F(build_hibf_chopper, pipeline)

EXPECT_EQ(result.out, std::string{});
EXPECT_EQ(result.err, std::string{});
ASSERT_EQ(result.exit_code, 0);
RAPTOR_ASSERT_RESULT(result);
}

{ // check with search if index contains expected input
Expand All @@ -91,7 +91,7 @@ TEST_F(build_hibf_chopper, pipeline)
"--query", data("query.fq"));
EXPECT_EQ(result.out, std::string{});
EXPECT_EQ(result.err, std::string{});
ASSERT_EQ(result.exit_code, 0);
RAPTOR_ASSERT_RESULT(result);
}

std::ifstream search_result{search_filename.get_path()};
Expand Down
6 changes: 3 additions & 3 deletions test/cli/build/cli_build_hibf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ TEST_P(build_hibf, with_file)
pack_path(number_of_repeated_bins));
EXPECT_EQ(result.out, std::string{});
EXPECT_EQ(result.err, std::string{});
ASSERT_EQ(result.exit_code, 0);
RAPTOR_ASSERT_RESULT(result);

compare_results<raptor::index_structure::hibf>(ibf_path(number_of_repeated_bins, window_size, false, true), "raptor.index");
}
Expand All @@ -44,7 +44,7 @@ TEST_P(build_hibf, with_shape)
pack_path(number_of_repeated_bins));
EXPECT_EQ(result.out, std::string{});
EXPECT_EQ(result.err, std::string{});
ASSERT_EQ(result.exit_code, 0);
RAPTOR_ASSERT_RESULT(result);

compare_results<raptor::index_structure::hibf>(ibf_path(number_of_repeated_bins, window_size, false, true), "raptor.index");
}
Expand Down Expand Up @@ -73,7 +73,7 @@ TEST_F(build_hibf, three_levels)
data("three_levels.pack"));
EXPECT_EQ(result.out, std::string{});
EXPECT_EQ(result.err, std::string{});
ASSERT_EQ(result.exit_code, 0);
RAPTOR_ASSERT_RESULT(result);

compare_results<raptor::index_structure::hibf>(data("three_levels.hibf"), "raptor.index");
}
4 changes: 2 additions & 2 deletions test/cli/build/cli_build_ibf_compressed_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ TEST_P(build_ibf_compressed, pipeline)
"--query ", data("query.fq"));
EXPECT_EQ(result2.out, std::string{});
EXPECT_EQ(result2.err, std::string{});
ASSERT_EQ(result2.exit_code, 0);
RAPTOR_ASSERT_RESULT(result2);

std::string const expected = [&] ()
{
Expand Down Expand Up @@ -111,7 +111,7 @@ TEST_P(build_ibf_compressed, pipeline_socks)
"--query ", data("query_socks.fq"));
EXPECT_EQ(result2.out, std::string{});
EXPECT_EQ(result2.err, std::string{});
ASSERT_EQ(result2.exit_code, 0);
RAPTOR_ASSERT_RESULT(result2);

std::string const expected = string_from_file(search_result_path(number_of_repeated_bins,
window_size,
Expand Down
2 changes: 1 addition & 1 deletion test/cli/build/cli_build_ibf_partitioned_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ TEST_P(build_ibf_partitioned, pipeline)
"--query ", data("query.fq"));
EXPECT_EQ(result2.out, std::string{});
EXPECT_EQ(result2.err, std::string{});
ASSERT_EQ(result2.exit_code, 0);
RAPTOR_ASSERT_RESULT(result2);

std::string const expected = [&] ()
{
Expand Down
6 changes: 3 additions & 3 deletions test/cli/build/cli_build_ibf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ TEST_P(build_ibf, with_file)
"raptor_cli_test.txt");
EXPECT_EQ(result.out, std::string{});
EXPECT_EQ(result.err, std::string{});
ASSERT_EQ(result.exit_code, 0);
RAPTOR_ASSERT_RESULT(result);

compare_results(ibf_path(number_of_repeated_bins, window_size), "raptor.index");
}
Expand All @@ -56,7 +56,7 @@ TEST_P(build_ibf, with_shape)
"raptor_cli_test.txt");
EXPECT_EQ(result.out, std::string{});
EXPECT_EQ(result.err, std::string{});
ASSERT_EQ(result.exit_code, 0);
RAPTOR_ASSERT_RESULT(result);

compare_results(ibf_path(number_of_repeated_bins, window_size), "raptor.index");
}
Expand Down Expand Up @@ -89,7 +89,7 @@ TEST_P(build_ibf, with_socks_file)
"raptor_cli_test.txt");
EXPECT_EQ(result.out, std::string{});
EXPECT_EQ(result.err, std::string{});
ASSERT_EQ(result.exit_code, 0);
RAPTOR_ASSERT_RESULT(result);

compare_results(ibf_path(number_of_repeated_bins, window_size), "raptor.index");
}
Expand Down
22 changes: 17 additions & 5 deletions test/cli/cli_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@

#include <raptor/index.hpp>

#ifndef RAPTOR_ASSERT_RESULT
#define RAPTOR_ASSERT_RESULT(arg) ASSERT_EQ(arg.exit_code, 0) << "Command: " << arg.command
#endif
#ifndef RAPTOR_EXPECT_RESULT
#define RAPTOR_EXPECT_RESULT(arg) EXPECT_EQ(arg.exit_code, 0) << "Command: " << arg.command
#endif

// Provides functions for CLI test implementation.
struct cli_test : public ::testing::Test
{
Expand All @@ -30,6 +37,7 @@ struct cli_test : public ::testing::Test
{
std::string out{};
std::string err{};
std::string command{};
int exit_code{};
};

Expand All @@ -40,17 +48,21 @@ struct cli_test : public ::testing::Test
cli_test_result result{};

// Assemble the command string and disable version check.
std::ostringstream command{};
command << "SEQAN3_NO_VERSION_CHECK=1 " << BINDIR;
int a[] = {0, ((void)(command << command_items << ' '), 0) ... };
(void) a;
result.command = [&command_items...] ()
{
std::ostringstream command{};
command << "SEQAN3_NO_VERSION_CHECK=1 " << BINDIR;
int a[] = {0, ((void)(command << command_items << ' '), 0) ... };
(void) a;
return command.str();
}();

// Always capture the output streams.
testing::internal::CaptureStdout();
testing::internal::CaptureStderr();

// Run the command and return results.
result.exit_code = std::system(command.str().c_str());
result.exit_code = std::system(result.command.c_str());
result.out = testing::internal::GetCapturedStdout();
result.err = testing::internal::GetCapturedStderr();
return result;
Expand Down
6 changes: 3 additions & 3 deletions test/cli/search/cli_search_ibf_preprocessing_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ TEST_P(search_ibf_preprocessing, pipeline)
"raptor_cli_test.minimiser");
EXPECT_EQ(result2.out, std::string{});
EXPECT_EQ(result2.err, std::string{});
ASSERT_EQ(result2.exit_code, 0);
RAPTOR_ASSERT_RESULT(result2);

compare_results(ibf_path(number_of_repeated_bins, window_size), "raptor.index", false);

Expand Down Expand Up @@ -137,7 +137,7 @@ TEST_P(search_ibf_preprocessing, pipeline_compressed_bins)
"raptor_cli_test.minimiser");
EXPECT_EQ(result2.out, std::string{});
EXPECT_EQ(result2.err, std::string{});
ASSERT_EQ(result2.exit_code, 0);
RAPTOR_ASSERT_RESULT(result2);

compare_results(ibf_path(number_of_repeated_bins, window_size), "raptor.index", false);

Expand Down Expand Up @@ -208,7 +208,7 @@ TEST_F(search_ibf_preprocessing, pipeline_compressed_index)
"raptor_cli_test.minimiser");
EXPECT_EQ(result2.out, std::string{});
EXPECT_EQ(result2.err, std::string{});
ASSERT_EQ(result2.exit_code, 0);
RAPTOR_ASSERT_RESULT(result2);

compare_results<raptor::index_structure::ibf_compressed>(ibf_path(16, 23, true), "raptor.index", false);
}
Expand Down
8 changes: 4 additions & 4 deletions test/cli/search/cli_search_ibf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TEST_P(search_ibf, with_error)
"--error ", std::to_string(number_of_errors),
"--index ", ibf_path(number_of_repeated_bins, window_size),
"--query ", data("query.fq"));
EXPECT_EQ(result.exit_code, 0);
RAPTOR_EXPECT_RESULT(result);
EXPECT_EQ(result.out, std::string{});
EXPECT_EQ(result.err, std::string{});

Expand All @@ -45,7 +45,7 @@ TEST_P(search_ibf, socks)
"--output search.out",
"--index ", ibf_path(number_of_repeated_bins, window_size),
"--query ", data("query_socks.fq"));
EXPECT_EQ(result.exit_code, 0);
RAPTOR_EXPECT_RESULT(result);
EXPECT_EQ(result.out, std::string{});
EXPECT_EQ(result.err, std::string{});

Expand All @@ -68,7 +68,7 @@ TEST_P(search_ibf, threshold)
"--threshold 0.50",
"--index ", ibf_path(number_of_repeated_bins, window_size),
"--query ", data("query.fq"));
EXPECT_EQ(result.exit_code, 0);
RAPTOR_EXPECT_RESULT(result);
EXPECT_EQ(result.out, std::string{});
EXPECT_EQ(result.err, std::string{});

Expand Down Expand Up @@ -117,7 +117,7 @@ TEST_P(search_ibf, no_hits)
"--error ", std::to_string(number_of_errors),
"--index ", ibf_path(number_of_repeated_bins, window_size),
"--query ", data("query_empty.fq"));
EXPECT_EQ(result.exit_code, 0);
RAPTOR_EXPECT_RESULT(result);
EXPECT_EQ(result.out, std::string{});
EXPECT_EQ(result.err, std::string{});

Expand Down
6 changes: 3 additions & 3 deletions test/cli/upgrade/cli_upgrade_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ TEST_F(upgrade, ibf)
"--output raptor.index");
EXPECT_EQ(result.out, std::string{});
EXPECT_EQ(result.err, std::string{});
ASSERT_EQ(result.exit_code, 0);
RAPTOR_ASSERT_RESULT(result);

compare_results(ibf_path(16, 23), "raptor.index");
}
Expand All @@ -53,7 +53,7 @@ TEST_F(upgrade, compressed_ibf)
"--output raptor.index");
EXPECT_EQ(result.out, std::string{});
EXPECT_EQ(result.err, std::string{});
ASSERT_EQ(result.exit_code, 0);
RAPTOR_ASSERT_RESULT(result);

compare_results<raptor::index_structure::ibf_compressed>(ibf_path(16, 23, true), "raptor.index");
}
Expand Down Expand Up @@ -92,7 +92,7 @@ TEST_F(upgrade, partitioned_ibf)
"--query ", data("query.fq"));
EXPECT_EQ(result2.out, std::string{});
EXPECT_EQ(result2.err, std::string{});
ASSERT_EQ(result2.exit_code, 0);
RAPTOR_ASSERT_RESULT(result2);

std::string const expected = [&] ()
{
Expand Down