Skip to content

Add tests for SamParser and RAMNTupleUtils to improve coverage (fixes…#42

Open
swetank18 wants to merge 1 commit intocompiler-research:developfrom
swetank18:fix-issue-26-samparser-coverage
Open

Add tests for SamParser and RAMNTupleUtils to improve coverage (fixes…#42
swetank18 wants to merge 1 commit intocompiler-research:developfrom
swetank18:fix-issue-26-samparser-coverage

Conversation

@swetank18
Copy link
Copy Markdown

#26)

Summary

Adds direct tests for the existing SamParser class which had zero test
coverage before this PR.

Closes #26

Tests Added (test/samparsertest.cxx)

  • NonExistentFileReturnsFalse — graceful failure on missing file
  • HeaderCallbackFired — header lines trigger callback correctly
  • RecordCallbackFiredForEachAlignment — one callback per alignment line
  • RecordFieldsParsedCorrectly — all 11 SAM fields parsed accurately
  • EmptyFileParseSucceeds — empty file handled without crash
  • HeaderOnlyFileProducesNoRecords — zero record callbacks for header-only SAM
  • OptionalFieldsCaptured — auxiliary tags stored in record
  • LinesProcessedCountIsCorrect — line counter includes headers + records

What This Does NOT Include

New tool functionality (ramstats, ramsort) is in separate PRs #28 and #30.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 25. Check the log or trigger a new build to see more.

Comment thread test/samparsertest.cxx
@@ -0,0 +1,246 @@
#include <gtest/gtest.h>
#include <fstream>
#include <cstdio>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: #includes are not sorted properly [llvm-include-order]

Suggested change
#include <cstdio>
#include <cstdio>
#include <fstream>

Comment thread test/samparsertest.cxx

ramcore::SamParser parser;
std::vector<std::string> tags;
parser.ParseFile(kSamFile,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member variable 'kSamFile' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes]

t char *kSamFile = "parser_test.sam";
        ^

Comment thread test/samparsertest.cxx
ramcore::SamParser parser;
std::vector<std::string> tags;
parser.ParseFile(kSamFile,
[&](const std::string &tag, const std::string &) { tags.push_back(tag); },
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: invalid case style for protected member 'kSamFile' [readability-identifier-naming]

Suggested change
[&](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_kSamFile

test/samparsertest.cxx:68:

- arser.ParseFile(kSamFile,
+ arser.ParseFile(m_kSamFile,

test/samparsertest.cxx:79:

- allbackFiredForEachAlignment)
+ allbackFiredForEachAlignment)m_kSamFile

test/samparsertest.cxx:86:

-  count = 0;
+  count = 0;m_kSamFile

test/samparsertest.cxx:94:

- )
+ )m_kSamFile

test/samparsertest.cxx:100:

- red;
+ red;m_kSamFile

test/samparsertest.cxx:124:

- FileParseSucceeds)
+ FileParseSucceeds)m_kSamFile

test/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_kSamFile

test/samparsertest.cxx:145:

- Test, OptionalFieldsCaptured)
+ Test, OptionalFieldsCaptured)m_kSamFile

test/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

Comment thread test/samparsertest.cxx
EXPECT_EQ(tags[1], "@SQ");
}

/// Record callback must fire once per alignment line.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: argument comment missing for literal argument 'filename' [bugprone-argument-comment]

Suggested change
/// Record callback must fire once per alignment line.
ser parser;/*filename=*/

Comment thread test/samparsertest.cxx
EXPECT_EQ(parser.GetRecordsProcessed(), 2u);
}

/// Parsed record fields must match the SAM columns exactly.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: integer literal has suffix 'u', which is not uppercase [readability-uppercase-literal-suffix]

Suggested change
/// Parsed record fields must match the SAM columns exactly.
ags.size(), 2U);

Comment thread test/samparsertest.cxx
EXPECT_EQ(captured.qname, "myread");
EXPECT_EQ(captured.flag, 99);
EXPECT_EQ(captured.rname, "chr2");
EXPECT_EQ(captured.pos, 500);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: integer literal has suffix 'u', which is not uppercase [readability-uppercase-literal-suffix]

Suggested change
EXPECT_EQ(captured.pos, 500);
EXPECT_EQ(count, 2U);

Comment thread test/samparsertest.cxx
EXPECT_EQ(captured.flag, 99);
EXPECT_EQ(captured.rname, "chr2");
EXPECT_EQ(captured.pos, 500);
EXPECT_EQ(captured.mapq, 30);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: integer literal has suffix 'u', which is not uppercase [readability-uppercase-literal-suffix]

Suggested change
EXPECT_EQ(captured.mapq, 30);
parser.GetRecordsProcessed(), 2U);

Comment thread test/samparsertest.cxx
{
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");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: integer literal has suffix 'u', which is not uppercase [readability-uppercase-literal-suffix]

Suggested change
"read1\t0\tchr1\t100\t60\t10M\t*\t0\t0\tACGTACGTAC\t*\tNM:i:0\tRG:Z:sample1\n");
E(ok);U

Comment thread test/samparsertest.cxx
/// Lines processed counter must include both header and record lines.
TEST_F(SamParserTest, LinesProcessedCountIsCorrect)
{
WriteSAM(kSamFile,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: integer literal has suffix 'u', which is not uppercase [readability-uppercase-literal-suffix]

Suggested change
WriteSAM(kSamFile,
T_EQ(count, 0U);

Comment thread test/samparsertest.cxx
ramcore::StripCRLF(buf1);
EXPECT_STREQ(buf1, "hello");

char buf2[] = "world\n";
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: integer literal has suffix 'u', which is not uppercase [readability-uppercase-literal-suffix]

Suggested change
char buf2[] = "world\n";
), 1U);

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.86%. Comparing base (3a3873a) to head (2b6aca7).
⚠️ Report is 20 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             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     
Flag Coverage Δ
unittests 63.86% <100.00%> (+8.00%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
test/samparsertest.cxx 100.00% <100.00%> (ø)

... and 7 files with indirect coverage changes

Files with missing lines Coverage Δ
test/samparsertest.cxx 100.00% <100.00%> (ø)

... and 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve testing coverage

2 participants