
The virtual method `ProgramPointTag::getTagDescription` had two very distinct use cases: - It is printed in the DOT graph visualization of the exploded graph (that is, a debug printout). - The checker option handling code used it to query the name of a checker, which relied on the coincidence that in `CheckerBase` this method is defined to be equivalent with `getName()`. This commit switches to using `getName` in the second use case, because this way we will be able to properly support checkers that have multiple (separately named) parts. The method `reportInvalidCheckerOptionName` is extended with an additional overload that allows specifying the `CheckerPartIdx`. The methods `getChecker*Option` could be extended analogously in the future, but they are just convenience wrappers around the variants that directly take `StringRef CheckerName`, so I'll only do this extension if it's needed.
73 lines
2.9 KiB
C++
73 lines
2.9 KiB
C++
//===- unittest/StaticAnalyzer/AnalyzerOptionsTest.cpp - SA Options test --===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
|
|
#include "clang/StaticAnalyzer/Core/Checker.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
namespace clang {
|
|
namespace ento {
|
|
|
|
TEST(StaticAnalyzerOptions, getRegisteredCheckers) {
|
|
auto IsDebugChecker = [](StringRef CheckerName) {
|
|
return CheckerName.starts_with("debug");
|
|
};
|
|
auto IsAlphaChecker = [](StringRef CheckerName) {
|
|
return CheckerName.starts_with("alpha");
|
|
};
|
|
const auto &AllCheckers =
|
|
AnalyzerOptions::getRegisteredCheckers(/*IncludeExperimental=*/true);
|
|
EXPECT_FALSE(llvm::any_of(AllCheckers, IsDebugChecker));
|
|
EXPECT_TRUE(llvm::any_of(AllCheckers, IsAlphaChecker));
|
|
|
|
const auto &StableCheckers = AnalyzerOptions::getRegisteredCheckers();
|
|
EXPECT_FALSE(llvm::any_of(StableCheckers, IsDebugChecker));
|
|
EXPECT_FALSE(llvm::any_of(StableCheckers, IsAlphaChecker));
|
|
}
|
|
|
|
TEST(StaticAnalyzerOptions, SearchInParentPackageTests) {
|
|
AnalyzerOptions Opts;
|
|
Opts.Config["Outer.Inner.CheckerOne:Option"] = "true";
|
|
Opts.Config["Outer.Inner:Option"] = "false";
|
|
Opts.Config["Outer.Inner:Option2"] = "true";
|
|
Opts.Config["Outer:Option2"] = "false";
|
|
|
|
StringRef CheckerOneName = "Outer.Inner.CheckerOne";
|
|
StringRef CheckerTwoName = "Outer.Inner.CheckerTwo";
|
|
|
|
// CheckerTwo one has Option specified as true. It should read true regardless
|
|
// of search mode.
|
|
EXPECT_TRUE(Opts.getCheckerBooleanOption(CheckerOneName, "Option"));
|
|
// The package option is overridden with a checker option.
|
|
EXPECT_TRUE(Opts.getCheckerBooleanOption(CheckerOneName, "Option", true));
|
|
// The Outer package option is overridden by the Inner package option. No
|
|
// package option is specified.
|
|
EXPECT_TRUE(Opts.getCheckerBooleanOption(CheckerOneName, "Option2", true));
|
|
// No package option is specified and search in packages is turned off. We
|
|
// should assert here, but we can't test that.
|
|
//Opts.getCheckerBooleanOption(&CheckerOne, "Option2");
|
|
//Opts.getCheckerBooleanOption(&CheckerOne, "Option2");
|
|
|
|
// Checker true has no option specified. It should get false when search in
|
|
// parents turned on.
|
|
EXPECT_FALSE(Opts.getCheckerBooleanOption(CheckerTwoName, "Option", true));
|
|
// In any other case, we should assert, that we cannot test unfortunately.
|
|
//Opts.getCheckerBooleanOption(&CheckerTwo, "Option");
|
|
//Opts.getCheckerBooleanOption(&CheckerTwo, "Option");
|
|
}
|
|
|
|
TEST(StaticAnalyzerOptions, StringOptions) {
|
|
AnalyzerOptions Opts;
|
|
Opts.Config["Outer.Inner.CheckerOne:Option"] = "StringValue";
|
|
EXPECT_TRUE("StringValue" == Opts.getCheckerStringOption(
|
|
"Outer.Inner.CheckerOne", "Option"));
|
|
}
|
|
|
|
} // end namespace ento
|
|
} // end namespace clang
|