Skip to content

Commit 1df55f0

Browse files
committed
add helper since selfcheck complains both ways
1 parent 74999d5 commit 1df55f0

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

test/testsarif.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ class TestSarif : public TestFixture
4444
{}
4545

4646
private:
47+
// Helper function to check if a string starts with a prefix (C++17 compatible)
48+
static bool startsWith(const std::string& str, const std::string& prefix) {
49+
return str.size() >= prefix.size() && str.compare(0, prefix.size(), prefix) == 0;
50+
}
4751
// Shared test code with various error types
4852
const std::string testCode = R"(
4953
#include <cstdio>
@@ -586,7 +590,7 @@ int main() {
586590
{
587591
hasSecurityTag = true;
588592
}
589-
else if (tagStr.starts_with("external/cwe/cwe-"))
593+
else if (startsWith(tagStr, "external/cwe/cwe-"))
590594
{
591595
hasCweTag = true;
592596
}
@@ -665,7 +669,7 @@ int main() {
665669
const picojson::object& driver = tool.at("driver").get<picojson::object>();
666670
const picojson::array& rules = driver.at("rules").get<picojson::array>();
667671

668-
ASSERT(rules.empty());
672+
ASSERT(!rules.empty());
669673

670674
// Verify that ALL rule descriptions are empty so GitHub uses instance-specific messages
671675
for (const auto& rule : rules)
@@ -865,7 +869,7 @@ int main() {
865869
{
866870
hasSecurityTag = true;
867871
}
868-
else if (tagStr.starts_with("external/cwe/cwe-"))
872+
else if (startsWith(tagStr, "external/cwe/cwe-"))
869873
{
870874
hasCweTag = true;
871875
foundAnyCweTag = true;
@@ -1056,7 +1060,7 @@ int main() {
10561060
{
10571061
const picojson::array& tags = props.at("tags").get<picojson::array>();
10581062
hasCWE = std::any_of(tags.begin(), tags.end(), [](const picojson::value& tag) {
1059-
return tag.get<std::string>().find("external/cwe/") == 0;
1063+
return startsWith(tag.get<std::string>(), "external/cwe/");
10601064
});
10611065
}
10621066

0 commit comments

Comments
 (0)