-
Notifications
You must be signed in to change notification settings - Fork 253
Description
When using lcov to generate coverage reports, the --filter branch,exception options don't work properly with ternary operators. A single line with ternary operator generates multiple coverage branches that cannot be properly filtered, while the same logic written as if-else shows correct branch count.
Environment:
lcov version: 2.3.1-1
gcc/g++ version: 9.3.0
Test Code:
Item.h :
#ifndef ITEM_H
#define ITEM_H
#include
class Item {
public:
void setSummary(const std::string& summary);
void setSummaryIfElse(const std::string& summary);
std::string getSummary() const;
private:
std::string summary;
};
#endif // ITEM_H
Item.cpp:
#include "Item.h"
void Item::setSummary(const std::string& summary) {
this->summary = "** " + (summary.empty() ? "-" : summary);
}
void Item::setSummaryIfElse(const std::string& summary) {
if(summary.empty()) {
this->summary = "** -";
} else {
this->summary = "** " + summary;
}
}
std::string Item::getSummary() const {
return summary;
}
test_Item.cpp :
<gtest/gtest.h>
#include "Item.h"
TEST(ItemTest, SummaryTest) {
Item item;
item.setSummary("");
EXPECT_EQ(item.getSummary(), "** -");
item.setSummary("Test content");
EXPECT_EQ(item.getSummary(), "** Test content");
item.setSummaryIfElse("");
EXPECT_EQ(item.getSummary(), "** -");
item.setSummaryIfElse("Test content");
EXPECT_EQ(item.getSummary(), "** Test content");
item.setSummaryIfElse(" ");
EXPECT_EQ(item.getSummary(), "** ");
}