Add tests for SamParser and RAMNTupleUtils to improve coverage (fixes…#42
Add tests for SamParser and RAMNTupleUtils to improve coverage (fixes…#42swetank18 wants to merge 1 commit intocompiler-research:developfrom
Conversation
| @@ -0,0 +1,246 @@ | |||
| #include <gtest/gtest.h> | |||
| #include <fstream> | |||
| #include <cstdio> | |||
There was a problem hiding this comment.
warning: #includes are not sorted properly [llvm-include-order]
| #include <cstdio> | |
| #include <cstdio> | |
| #include <fstream> |
|
|
||
| ramcore::SamParser parser; | ||
| std::vector<std::string> tags; | ||
| parser.ParseFile(kSamFile, |
There was a problem hiding this comment.
warning: member variable 'kSamFile' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes]
t char *kSamFile = "parser_test.sam";
^| ramcore::SamParser parser; | ||
| std::vector<std::string> tags; | ||
| parser.ParseFile(kSamFile, | ||
| [&](const std::string &tag, const std::string &) { tags.push_back(tag); }, |
There was a problem hiding this comment.
warning: invalid case style for protected member 'kSamFile' [readability-identifier-naming]
| [&](const std::string &tag, const std::string &) { tags.push_back(tag); }, | |
| t char *m_kSamFile = "parser_test.sam"; | |
| t.sam";m_kSamFile |
test/samparsertest.cxx:62:
- llback.
- File,
+ llback.
+ File,m_kSamFiletest/samparsertest.cxx:68:
- arser.ParseFile(kSamFile,
+ arser.ParseFile(m_kSamFile,test/samparsertest.cxx:79:
- allbackFiredForEachAlignment)
+ allbackFiredForEachAlignment)m_kSamFiletest/samparsertest.cxx:86:
- count = 0;
+ count = 0;m_kSamFiletest/samparsertest.cxx:94:
- )
+ )m_kSamFiletest/samparsertest.cxx:100:
- red;
+ red;m_kSamFiletest/samparsertest.cxx:124:
- FileParseSucceeds)
+ FileParseSucceeds)m_kSamFiletest/samparsertest.cxx:127:
- rseFile(kSamFile, nullptr, nullptr);
+ rseFile(m_kSamFile, nullptr, nullptr);test/samparsertest.cxx:134:
- WriteSAM(kSamFile,
+ WriteSAM(m_kSamFile,test/samparsertest.cxx:139:
- ze_t count = 0;
+ ze_t count = 0;m_kSamFiletest/samparsertest.cxx:145:
- Test, OptionalFieldsCaptured)
+ Test, OptionalFieldsCaptured)m_kSamFiletest/samparsertest.cxx:153:
- (kSamFile, nullptr,
+ (m_kSamFile, nullptr,test/samparsertest.cxx:165:
- AM(kSamFile,
+ AM(m_kSamFile,test/samparsertest.cxx:170:
- ramcore::SamParser parser;
+ ramcore::SamParser parser;m_kSamFile| EXPECT_EQ(tags[1], "@SQ"); | ||
| } | ||
|
|
||
| /// Record callback must fire once per alignment line. |
There was a problem hiding this comment.
warning: argument comment missing for literal argument 'filename' [bugprone-argument-comment]
| /// Record callback must fire once per alignment line. | |
| ser parser;/*filename=*/ |
| EXPECT_EQ(parser.GetRecordsProcessed(), 2u); | ||
| } | ||
|
|
||
| /// Parsed record fields must match the SAM columns exactly. |
There was a problem hiding this comment.
warning: integer literal has suffix 'u', which is not uppercase [readability-uppercase-literal-suffix]
| /// Parsed record fields must match the SAM columns exactly. | |
| ags.size(), 2U); |
| EXPECT_EQ(captured.qname, "myread"); | ||
| EXPECT_EQ(captured.flag, 99); | ||
| EXPECT_EQ(captured.rname, "chr2"); | ||
| EXPECT_EQ(captured.pos, 500); |
There was a problem hiding this comment.
warning: integer literal has suffix 'u', which is not uppercase [readability-uppercase-literal-suffix]
| EXPECT_EQ(captured.pos, 500); | |
| EXPECT_EQ(count, 2U); |
| EXPECT_EQ(captured.flag, 99); | ||
| EXPECT_EQ(captured.rname, "chr2"); | ||
| EXPECT_EQ(captured.pos, 500); | ||
| EXPECT_EQ(captured.mapq, 30); |
There was a problem hiding this comment.
warning: integer literal has suffix 'u', which is not uppercase [readability-uppercase-literal-suffix]
| EXPECT_EQ(captured.mapq, 30); | |
| parser.GetRecordsProcessed(), 2U); |
| { | ||
| WriteSAM(kSamFile, | ||
| "@HD\tVN:1.6\n" | ||
| "read1\t0\tchr1\t100\t60\t10M\t*\t0\t0\tACGTACGTAC\t*\tNM:i:0\tRG:Z:sample1\n"); |
There was a problem hiding this comment.
warning: integer literal has suffix 'u', which is not uppercase [readability-uppercase-literal-suffix]
| "read1\t0\tchr1\t100\t60\t10M\t*\t0\t0\tACGTACGTAC\t*\tNM:i:0\tRG:Z:sample1\n"); | |
| E(ok);U |
| /// Lines processed counter must include both header and record lines. | ||
| TEST_F(SamParserTest, LinesProcessedCountIsCorrect) | ||
| { | ||
| WriteSAM(kSamFile, |
There was a problem hiding this comment.
warning: integer literal has suffix 'u', which is not uppercase [readability-uppercase-literal-suffix]
| WriteSAM(kSamFile, | |
| T_EQ(count, 0U); |
| ramcore::StripCRLF(buf1); | ||
| EXPECT_STREQ(buf1, "hello"); | ||
|
|
||
| char buf2[] = "world\n"; |
There was a problem hiding this comment.
warning: integer literal has suffix 'u', which is not uppercase [readability-uppercase-literal-suffix]
| char buf2[] = "world\n"; | |
| ), 1U); |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #42 +/- ##
===========================================
+ Coverage 55.85% 63.86% +8.00%
===========================================
Files 16 17 +1
Lines 1425 1558 +133
Branches 752 631 -121
===========================================
+ Hits 796 995 +199
+ Misses 521 488 -33
+ Partials 108 75 -33
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 7 files with indirect coverage changes
🚀 New features to boost your workflow:
|
… #26)
Summary
Adds direct tests for the existing
SamParserclass which had zero testcoverage before this PR.
Closes #26
Tests Added (
test/samparsertest.cxx)NonExistentFileReturnsFalse— graceful failure on missing fileHeaderCallbackFired— header lines trigger callback correctlyRecordCallbackFiredForEachAlignment— one callback per alignment lineRecordFieldsParsedCorrectly— all 11 SAM fields parsed accuratelyEmptyFileParseSucceeds— empty file handled without crashHeaderOnlyFileProducesNoRecords— zero record callbacks for header-only SAMOptionalFieldsCaptured— auxiliary tags stored in recordLinesProcessedCountIsCorrect— line counter includes headers + recordsWhat This Does NOT Include
New tool functionality (ramstats, ramsort) is in separate PRs #28 and #30.