2018-06-27 22:56:12 +08:00
|
|
|
//===- unittest/StaticAnalyzer/AnalyzerOptionsTest.cpp - SA Options test --===//
|
2015-03-05 01:59:34 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
2015-03-05 01:59:34 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
|
|
|
|
#include "clang/StaticAnalyzer/Core/Checker.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace ento {
|
|
|
|
|
2016-11-08 15:23:32 +08:00
|
|
|
TEST(StaticAnalyzerOptions, getRegisteredCheckers) {
|
|
|
|
auto IsDebugChecker = [](StringRef CheckerName) {
|
|
|
|
return CheckerName.startswith("debug");
|
|
|
|
};
|
|
|
|
auto IsAlphaChecker = [](StringRef CheckerName) {
|
|
|
|
return CheckerName.startswith("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));
|
|
|
|
}
|
|
|
|
|
2015-03-05 01:59:34 +08:00
|
|
|
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";
|
|
|
|
|
|
|
|
struct CheckerOneMock : CheckerBase {
|
|
|
|
StringRef getTagDescription() const override {
|
|
|
|
return "Outer.Inner.CheckerOne";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
struct CheckerTwoMock : CheckerBase {
|
|
|
|
StringRef getTagDescription() const override {
|
|
|
|
return "Outer.Inner.CheckerTwo";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-03-04 08:28:16 +08:00
|
|
|
// CheckerTwo one has Option specified as true. It should read true regardless
|
|
|
|
// of search mode.
|
2015-03-05 01:59:34 +08:00
|
|
|
CheckerOneMock CheckerOne;
|
[analyzer] Remove the default value arg from getChecker*Option
Since D57922, the config table contains every checker option, and it's default
value, so having it as an argument for getChecker*Option is redundant.
By the time any of the getChecker*Option function is called, we verified the
value in CheckerRegistry (after D57860), so we can confidently assert here, as
any irregularities detected at this point must be a programmer error. However,
in compatibility mode, verification won't happen, so the default value must be
restored.
This implies something else, other than adding removing one more potential point
of failure -- debug.ConfigDumper will always contain valid values for
checker/package options!
Differential Revision: https://reviews.llvm.org/D59195
llvm-svn: 361042
2019-05-17 23:52:13 +08:00
|
|
|
EXPECT_TRUE(Opts.getCheckerBooleanOption(&CheckerOne, "Option"));
|
2018-02-06 21:12:29 +08:00
|
|
|
// The package option is overridden with a checker option.
|
[analyzer] Remove the default value arg from getChecker*Option
Since D57922, the config table contains every checker option, and it's default
value, so having it as an argument for getChecker*Option is redundant.
By the time any of the getChecker*Option function is called, we verified the
value in CheckerRegistry (after D57860), so we can confidently assert here, as
any irregularities detected at this point must be a programmer error. However,
in compatibility mode, verification won't happen, so the default value must be
restored.
This implies something else, other than adding removing one more potential point
of failure -- debug.ConfigDumper will always contain valid values for
checker/package options!
Differential Revision: https://reviews.llvm.org/D59195
llvm-svn: 361042
2019-05-17 23:52:13 +08:00
|
|
|
EXPECT_TRUE(Opts.getCheckerBooleanOption(&CheckerOne, "Option", true));
|
2018-02-06 21:12:29 +08:00
|
|
|
// The Outer package option is overridden by the Inner package option. No
|
2015-03-05 01:59:34 +08:00
|
|
|
// package option is specified.
|
2019-03-04 08:28:16 +08:00
|
|
|
EXPECT_TRUE(Opts.getCheckerBooleanOption(&CheckerOne, "Option2", true));
|
[analyzer] Remove the default value arg from getChecker*Option
Since D57922, the config table contains every checker option, and it's default
value, so having it as an argument for getChecker*Option is redundant.
By the time any of the getChecker*Option function is called, we verified the
value in CheckerRegistry (after D57860), so we can confidently assert here, as
any irregularities detected at this point must be a programmer error. However,
in compatibility mode, verification won't happen, so the default value must be
restored.
This implies something else, other than adding removing one more potential point
of failure -- debug.ConfigDumper will always contain valid values for
checker/package options!
Differential Revision: https://reviews.llvm.org/D59195
llvm-svn: 361042
2019-05-17 23:52:13 +08:00
|
|
|
// 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");
|
2015-03-05 01:59:34 +08:00
|
|
|
|
[analyzer] Remove the default value arg from getChecker*Option
Since D57922, the config table contains every checker option, and it's default
value, so having it as an argument for getChecker*Option is redundant.
By the time any of the getChecker*Option function is called, we verified the
value in CheckerRegistry (after D57860), so we can confidently assert here, as
any irregularities detected at this point must be a programmer error. However,
in compatibility mode, verification won't happen, so the default value must be
restored.
This implies something else, other than adding removing one more potential point
of failure -- debug.ConfigDumper will always contain valid values for
checker/package options!
Differential Revision: https://reviews.llvm.org/D59195
llvm-svn: 361042
2019-05-17 23:52:13 +08:00
|
|
|
// Checker true has no option specified. It should get false when search in
|
|
|
|
// parents turned on.
|
2015-03-05 01:59:34 +08:00
|
|
|
CheckerTwoMock CheckerTwo;
|
[analyzer] Remove the default value arg from getChecker*Option
Since D57922, the config table contains every checker option, and it's default
value, so having it as an argument for getChecker*Option is redundant.
By the time any of the getChecker*Option function is called, we verified the
value in CheckerRegistry (after D57860), so we can confidently assert here, as
any irregularities detected at this point must be a programmer error. However,
in compatibility mode, verification won't happen, so the default value must be
restored.
This implies something else, other than adding removing one more potential point
of failure -- debug.ConfigDumper will always contain valid values for
checker/package options!
Differential Revision: https://reviews.llvm.org/D59195
llvm-svn: 361042
2019-05-17 23:52:13 +08:00
|
|
|
EXPECT_FALSE(Opts.getCheckerBooleanOption(&CheckerTwo, "Option", true));
|
|
|
|
// In any other case, we should assert, that we cannot test unfortunately.
|
|
|
|
//Opts.getCheckerBooleanOption(&CheckerTwo, "Option");
|
|
|
|
//Opts.getCheckerBooleanOption(&CheckerTwo, "Option");
|
2015-03-05 01:59:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(StaticAnalyzerOptions, StringOptions) {
|
|
|
|
AnalyzerOptions Opts;
|
|
|
|
Opts.Config["Outer.Inner.CheckerOne:Option"] = "StringValue";
|
|
|
|
|
|
|
|
struct CheckerOneMock : CheckerBase {
|
|
|
|
StringRef getTagDescription() const override {
|
|
|
|
return "Outer.Inner.CheckerOne";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
CheckerOneMock CheckerOne;
|
|
|
|
EXPECT_TRUE("StringValue" ==
|
[analyzer] Remove the default value arg from getChecker*Option
Since D57922, the config table contains every checker option, and it's default
value, so having it as an argument for getChecker*Option is redundant.
By the time any of the getChecker*Option function is called, we verified the
value in CheckerRegistry (after D57860), so we can confidently assert here, as
any irregularities detected at this point must be a programmer error. However,
in compatibility mode, verification won't happen, so the default value must be
restored.
This implies something else, other than adding removing one more potential point
of failure -- debug.ConfigDumper will always contain valid values for
checker/package options!
Differential Revision: https://reviews.llvm.org/D59195
llvm-svn: 361042
2019-05-17 23:52:13 +08:00
|
|
|
Opts.getCheckerStringOption(&CheckerOne, "Option"));
|
2015-03-05 01:59:34 +08:00
|
|
|
}
|
2019-03-04 08:28:16 +08:00
|
|
|
|
|
|
|
TEST(StaticAnalyzerOptions, SubCheckerOptions) {
|
|
|
|
AnalyzerOptions Opts;
|
|
|
|
Opts.Config["Outer.Inner.CheckerOne:Option"] = "StringValue";
|
|
|
|
EXPECT_TRUE("StringValue" == Opts.getCheckerStringOption(
|
[analyzer] Remove the default value arg from getChecker*Option
Since D57922, the config table contains every checker option, and it's default
value, so having it as an argument for getChecker*Option is redundant.
By the time any of the getChecker*Option function is called, we verified the
value in CheckerRegistry (after D57860), so we can confidently assert here, as
any irregularities detected at this point must be a programmer error. However,
in compatibility mode, verification won't happen, so the default value must be
restored.
This implies something else, other than adding removing one more potential point
of failure -- debug.ConfigDumper will always contain valid values for
checker/package options!
Differential Revision: https://reviews.llvm.org/D59195
llvm-svn: 361042
2019-05-17 23:52:13 +08:00
|
|
|
"Outer.Inner.CheckerOne", "Option"));
|
2019-03-04 08:28:16 +08:00
|
|
|
}
|
|
|
|
|
2015-03-05 01:59:34 +08:00
|
|
|
} // end namespace ento
|
|
|
|
} // end namespace clang
|