|
19 | 19 | #include <seqan3/test/expect_range_eq.hpp> |
20 | 20 | #include <seqan3/test/pretty_printing.hpp> |
21 | 21 | #include <seqan3/test/streambuf.hpp> |
| 22 | +#include <seqan3/test/tmp_directory.hpp> |
22 | 23 |
|
23 | 24 | using seqan3::operator""_cigar_operation; |
24 | 25 | using seqan3::operator""_dna5; |
@@ -356,6 +357,67 @@ TYPED_TEST_P(sam_file_read, issue2423) |
356 | 357 | EXPECT_EQ(fin.header().ref_dict.size(), 64u); |
357 | 358 | } |
358 | 359 |
|
| 360 | +TYPED_TEST_P(sam_file_read, unknown_header_tag) |
| 361 | +{ |
| 362 | + // Default: Warnings to cerr |
| 363 | + { |
| 364 | + typename TestFixture::stream_type istream{this->unknown_tag_header}; |
| 365 | + seqan3::sam_file_input fin{istream, TypeParam{}}; |
| 366 | + testing::internal::CaptureStdout(); |
| 367 | + testing::internal::CaptureStderr(); |
| 368 | + EXPECT_NO_THROW(fin.begin()); |
| 369 | + EXPECT_EQ(testing::internal::GetCapturedStdout(), ""); |
| 370 | + EXPECT_EQ(testing::internal::GetCapturedStderr(), "Unsupported SAM header tag in @HD: pb\n"); |
| 371 | + } |
| 372 | + // Redirect to cout |
| 373 | + { |
| 374 | + typename TestFixture::stream_type istream{this->unknown_tag_header}; |
| 375 | + seqan3::sam_file_input fin{istream, TypeParam{}}; |
| 376 | + fin.options.warning_stream = std::addressof(std::cout); |
| 377 | + testing::internal::CaptureStdout(); |
| 378 | + testing::internal::CaptureStderr(); |
| 379 | + EXPECT_NO_THROW(fin.begin()); |
| 380 | + EXPECT_EQ(testing::internal::GetCapturedStdout(), "Unsupported SAM header tag in @HD: pb\n"); |
| 381 | + EXPECT_EQ(testing::internal::GetCapturedStderr(), ""); |
| 382 | + } |
| 383 | + // Redirect to file |
| 384 | + { |
| 385 | + seqan3::test::tmp_directory tmp{}; |
| 386 | + auto filename = tmp.path() / "warnings.txt"; |
| 387 | + |
| 388 | + // Scope for ofstream-RAII |
| 389 | + { |
| 390 | + std::ofstream warning_file{filename}; |
| 391 | + ASSERT_TRUE(warning_file.good()); |
| 392 | + |
| 393 | + typename TestFixture::stream_type istream{this->unknown_tag_header}; |
| 394 | + seqan3::sam_file_input fin{istream, TypeParam{}}; |
| 395 | + fin.options.warning_stream = std::addressof(warning_file); |
| 396 | + testing::internal::CaptureStdout(); |
| 397 | + testing::internal::CaptureStderr(); |
| 398 | + EXPECT_NO_THROW(fin.begin()); |
| 399 | + EXPECT_EQ(testing::internal::GetCapturedStdout(), ""); |
| 400 | + EXPECT_EQ(testing::internal::GetCapturedStderr(), ""); |
| 401 | + } |
| 402 | + |
| 403 | + std::ifstream warning_file{filename}; |
| 404 | + ASSERT_TRUE(warning_file.good()); |
| 405 | + std::string content{std::istreambuf_iterator<char>(warning_file), std::istreambuf_iterator<char>()}; |
| 406 | + EXPECT_EQ(content, "Unsupported SAM header tag in @HD: pb\n"); |
| 407 | + } |
| 408 | + // Silence |
| 409 | + { |
| 410 | + typename TestFixture::stream_type istream{this->unknown_tag_header}; |
| 411 | + seqan3::sam_file_input fin{istream, TypeParam{}}; |
| 412 | + fin.options.warning_stream = nullptr; |
| 413 | + testing::internal::CaptureStdout(); |
| 414 | + testing::internal::CaptureStderr(); |
| 415 | + EXPECT_NO_THROW(fin.begin()); |
| 416 | + EXPECT_EQ(testing::internal::GetCapturedStdout(), ""); |
| 417 | + EXPECT_EQ(testing::internal::GetCapturedStderr(), ""); |
| 418 | + } |
| 419 | +} |
| 420 | + |
359 | 421 | // ---------------------------------------------------------------------------- |
360 | 422 | // sam_file_write |
361 | 423 | // ---------------------------------------------------------------------------- |
@@ -703,7 +765,8 @@ REGISTER_TYPED_TEST_SUITE_P(sam_file_read, |
703 | 765 | cigar_vector, |
704 | 766 | format_error_ref_id_not_in_reference_information, |
705 | 767 | format_error_uneven_hexadecimal_tag, |
706 | | - issue2423); |
| 768 | + issue2423, |
| 769 | + unknown_header_tag); |
707 | 770 |
|
708 | 771 | REGISTER_TYPED_TEST_SUITE_P(sam_file_write, |
709 | 772 | no_records, |
|
0 commit comments