Skip to content

Commit

Permalink
[fix,test] check return values of system() calls in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
h-2 committed Sep 22, 2022
1 parent 1737d3b commit bcf01bd
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions test/cli/search_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@

struct search_test : public cli_test
{
std::string md5_cmd;

void determine_md5_cmd()
{
if (std::system("echo foo | md5sum > /dev/null") == 0)
md5_cmd = "md5sum";
else if (std::system("echo foo | md5 > /dev/null") == 0)
md5_cmd = "md5";

ASSERT_FALSE(md5_cmd.empty());
}

void run_search_test(std::string const & index_command,
std::string const & db_file,
std::string const & index_file,
Expand All @@ -31,10 +43,17 @@ struct search_test : public cli_test

EXPECT_EQ(result_search.exit_code, 0);

int ret = 0;

if (output_type == "bam")
{
std::system(("md5sum " + output_file + " > md5sum_test.txt").c_str());
std::system(("md5sum " + (std::string) data(control_file) + " > md5sum_control.txt").c_str());
if (md5_cmd.empty())
determine_md5_cmd();

ret = std::system((md5_cmd + " " + output_file + " > md5sum_test.txt").c_str());
ASSERT_TRUE(ret == 0);
ret = std::system((md5_cmd + " " + (std::string) data(control_file) + " > md5sum_control.txt").c_str());
ASSERT_TRUE(ret == 0);

std::ifstream test_output ("md5sum_test.txt");
std::ifstream control_output ("md5sum_control.txt");
Expand All @@ -56,12 +75,14 @@ struct search_test : public cli_test

if (output_type == "m9_gz")
{
system(("gunzip " + output_file).c_str());
ret = system(("gunzip " + output_file).c_str());
ASSERT_TRUE(ret == 0);
test_output.open(output_file.substr(0, output_file.length() - 3));
}
else if (output_type == "sam_bz2")
{
system(("bzip2 -d " + output_file).c_str());
ret = system(("bzip2 -d " + output_file).c_str());
ASSERT_TRUE(ret == 0);
test_output.open(output_file.substr(0, output_file.length() - 4));
}
else
Expand Down

0 comments on commit bcf01bd

Please sign in to comment.