Skip to content

Commit

Permalink
[INFRA] Make execute_app generic
Browse files Browse the repository at this point in the history
  • Loading branch information
eseiler committed Jan 29, 2024
1 parent 13f161e commit 0d9328c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ file (MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/output)
add_definitions (-DOUTPUTDIR=\"${CMAKE_CURRENT_BINARY_DIR}/output/\")
add_definitions (-DDATADIR=\"${CMAKE_CURRENT_BINARY_DIR}/data/\")
add_definitions (-DBINDIR=\"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/\")
add_definitions (-DAPPNAME=\"${PROJECT_NAME}\")

# Test executables and libraries should not mix with the application files.
# This must happen after setting the output directories.
Expand Down
6 changes: 3 additions & 3 deletions test/app_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct app_test : public ::testing::Test
// Holds the original work directory where Gtest has been started.
std::filesystem::path original_workdir{};

public:
protected:
// Result struct for captured streams and exit code.
struct app_test_result
{
Expand All @@ -45,8 +45,8 @@ struct app_test : public ::testing::Test
result.command = [&command_items...]()
{
std::ostringstream command{};
command << "SHARG_NO_VERSION_CHECK=1 " << BINDIR;
(void)((command << command_items << ' '), ...); // (void) silences "state has no effect" warning if no items
command << "SHARG_NO_VERSION_CHECK=1 " << BINDIR << APPNAME;
(void)((command << ' ' << command_items), ...); // (void) silences "state has no effect" warning if no items
return command.str();
}();

Expand Down
14 changes: 7 additions & 7 deletions test/cli/fastq_to_fasta_options_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ struct fastq_to_fasta : public app_test

TEST_F(fastq_to_fasta, no_options)
{
app_test_result const result = execute_app("app-template");
app_test_result const result = execute_app();
std::string_view const expected{"Fastq-to-Fasta-Converter\n"
"========================\n"
" Try -h or --help for more information.\n"};
Expand All @@ -18,7 +18,7 @@ TEST_F(fastq_to_fasta, no_options)

TEST_F(fastq_to_fasta, fail_no_argument)
{
app_test_result const result = execute_app("app-template", "-v");
app_test_result const result = execute_app("-v");
std::string_view const expected{"Parsing error. Not enough positional arguments provided (Need at least 1). "
"See -h/--help for more information.\n"};

Expand All @@ -29,7 +29,7 @@ TEST_F(fastq_to_fasta, fail_no_argument)

TEST_F(fastq_to_fasta, with_argument)
{
app_test_result const result = execute_app("app-template", data("in.fastq"));
app_test_result const result = execute_app(data("in.fastq"));

EXPECT_SUCCESS(result);
EXPECT_EQ(result.out, ">seq1\nACGTTTGATTCGCG\n>seq2\nTCGGGGGATTCGCG\n");
Expand All @@ -38,7 +38,7 @@ TEST_F(fastq_to_fasta, with_argument)

TEST_F(fastq_to_fasta, with_argument_verbose)
{
app_test_result const result = execute_app("app-template", data("in.fastq"), "-v");
app_test_result const result = execute_app(data("in.fastq"), "-v");

EXPECT_SUCCESS(result);
EXPECT_EQ(result.out, ">seq1\nACGTTTGATTCGCG\n>seq2\nTCGGGGGATTCGCG\n");
Expand All @@ -47,7 +47,7 @@ TEST_F(fastq_to_fasta, with_argument_verbose)

TEST_F(fastq_to_fasta, with_out_file)
{
app_test_result const result = execute_app("app-template", data("in.fastq"), "-o", "out.fasta");
app_test_result const result = execute_app(data("in.fastq"), "-o", "out.fasta");
std::string const expected = string_from_file(data("out.fasta"));
ASSERT_TRUE(std::filesystem::exists("out.fasta")); // check whether out.fasta exists
std::string const actual = string_from_file("out.fasta");
Expand All @@ -60,7 +60,7 @@ TEST_F(fastq_to_fasta, with_out_file)

TEST_F(fastq_to_fasta, missing_path)
{
app_test_result const result = execute_app("app-template", data("in.fastq"), "-o", "");
app_test_result const result = execute_app(data("in.fastq"), "-o", "");

EXPECT_FAILURE(result);
EXPECT_EQ(result.out, "");
Expand All @@ -69,7 +69,7 @@ TEST_F(fastq_to_fasta, missing_path)

TEST_F(fastq_to_fasta, invalid_path)
{
app_test_result const result = execute_app("app-template", data("in.fastq"), "-o", "does_not_exist/out.fasta");
app_test_result const result = execute_app(data("in.fastq"), "-o", "does_not_exist/out.fasta");

EXPECT_FAILURE(result);
EXPECT_EQ(result.out, "");
Expand Down

0 comments on commit 0d9328c

Please sign in to comment.