report filename for invalid fasta files
[mussa.git] / alg / test / test_sequence.cpp
index a3c63b6d87d8c4710a4cb76777a0e9b6775b711f..26b5be981ec1078a001f3eb01361fc8a22ba1efa 100644 (file)
@@ -178,6 +178,27 @@ BOOST_AUTO_TEST_CASE( sequence_load )
                                     "5' flank");
 }
 
+BOOST_AUTO_TEST_CASE( sequence_load_error )
+{
+  fs::path seq_path(fs::path(EXAMPLE_DIR, fs::native)/"seq");
+  seq_path /= "broken.fa";
+  bool exception_thrown = false;
+  std::string exception_filename;
+  Sequence s;
+  try {
+    s.load_fasta(seq_path);
+  } catch(sequence_invalid_load_error e) {
+    exception_thrown = true;
+    size_t native_string_size = seq_path.native_file_string().size();
+    std:string estr(e.what());
+    BOOST_REQUIRE(estr.size() > native_string_size);
+    std::copy(estr.begin(), estr.begin()+native_string_size,
+              std::back_inserter(exception_filename));
+  }
+  BOOST_CHECK_EQUAL(exception_thrown, true);
+  BOOST_CHECK_EQUAL(seq_path.native_file_string(), exception_filename);
+}
+
 BOOST_AUTO_TEST_CASE( sequence_load_dna_reduced )
 {
   std::string reduced_dna_fasta_string(">foo\nAAGGCCTTNN\n");