39 lines
1.7 KiB
C++
39 lines
1.7 KiB
C++
#include <catch2/catch_test_macros.hpp>
|
|
#include <chrono>
|
|
#include <vector>
|
|
|
|
#include "fold/cli/detector_profile_accum.hpp"
|
|
#include "fold/cli/profile.hpp"
|
|
|
|
TEST_CASE("findDetectorProfile returns the match or nullptr", "[detector-profile-accum]") {
|
|
std::vector<fold::cli::DetectorProfile> profiles;
|
|
profiles.push_back(fold::cli::DetectorProfile{.name = "clone"});
|
|
profiles.push_back(fold::cli::DetectorProfile{.name = "complexity"});
|
|
|
|
REQUIRE(fold::cli::findDetectorProfile(profiles, "clone") == &profiles[0]);
|
|
REQUIRE(fold::cli::findDetectorProfile(profiles, "complexity") == &profiles[1]);
|
|
REQUIRE(fold::cli::findDetectorProfile(profiles, "missing") == nullptr);
|
|
}
|
|
|
|
TEST_CASE("accumulateDetectorRun folds emitted-finding counts", "[detector-profile-accum]") {
|
|
std::vector<fold::cli::DetectorProfile> profiles;
|
|
profiles.push_back(fold::cli::DetectorProfile{.name = "complexity"});
|
|
|
|
const auto start = std::chrono::steady_clock::now();
|
|
fold::cli::accumulateDetectorRun(profiles, "complexity", start, 2, 5);
|
|
REQUIRE(profiles[0].findings_emitted == 3);
|
|
|
|
// A second run accumulates rather than overwrites.
|
|
fold::cli::accumulateDetectorRun(profiles, "complexity", start, 5, 6);
|
|
REQUIRE(profiles[0].findings_emitted == 4);
|
|
}
|
|
|
|
TEST_CASE("accumulateDetectorRun is a no-op for an unknown detector", "[detector-profile-accum]") {
|
|
std::vector<fold::cli::DetectorProfile> profiles;
|
|
profiles.push_back(fold::cli::DetectorProfile{.name = "complexity"});
|
|
|
|
const auto start = std::chrono::steady_clock::now();
|
|
// Must not crash and must not touch the existing profile.
|
|
fold::cli::accumulateDetectorRun(profiles, "not-enabled", start, 0, 100);
|
|
REQUIRE(profiles[0].findings_emitted == 0);
|
|
}
|