CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
113 lines
4.3 KiB
C++
113 lines
4.3 KiB
C++
#include "ClangTidyTest.h"
|
|
#include "google/GlobalNamesInHeadersCheck.h"
|
|
#include "misc/ExplicitConstructorCheck.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
using namespace clang::tidy::google;
|
|
using namespace clang::tidy::misc;
|
|
// TODO: Deprecate this test file in favor of typical lit-tests to avoid
|
|
// cross-module dependencies.
|
|
|
|
namespace clang {
|
|
namespace tidy {
|
|
namespace test {
|
|
|
|
TEST(ExplicitConstructorCheckTest, SingleArgumentConstructorsOnly) {
|
|
EXPECT_NO_CHANGES(ExplicitConstructorCheck, "class C { C(); };");
|
|
EXPECT_NO_CHANGES(ExplicitConstructorCheck, "class C { C(int i, int j); };");
|
|
EXPECT_NO_CHANGES(ExplicitConstructorCheck, "class C { C(const C&); };");
|
|
EXPECT_NO_CHANGES(ExplicitConstructorCheck, "class C { C(C&&); };");
|
|
EXPECT_NO_CHANGES(ExplicitConstructorCheck,
|
|
"class C { C(const C&) = delete; };");
|
|
EXPECT_NO_CHANGES(ExplicitConstructorCheck, "class C { C(int) = delete; };");
|
|
}
|
|
|
|
TEST(ExplicitConstructorCheckTest, Basic) {
|
|
EXPECT_EQ("class C { explicit C(int i); };",
|
|
runCheckOnCode<ExplicitConstructorCheck>("class C { C(int i); };"));
|
|
}
|
|
|
|
TEST(ExplicitConstructorCheckTest, DefaultParameters) {
|
|
EXPECT_EQ("class C { explicit C(int i, int j = 0); };",
|
|
runCheckOnCode<ExplicitConstructorCheck>(
|
|
"class C { C(int i, int j = 0); };"));
|
|
}
|
|
|
|
TEST(ExplicitConstructorCheckTest, OutOfLineDefinitions) {
|
|
EXPECT_EQ("class C { explicit C(int i); }; C::C(int i) {}",
|
|
runCheckOnCode<ExplicitConstructorCheck>(
|
|
"class C { C(int i); }; C::C(int i) {}"));
|
|
}
|
|
|
|
TEST(ExplicitConstructorCheckTest, RemoveExplicit) {
|
|
EXPECT_EQ("class A { A(const A&); };\n"
|
|
"class B { /*asdf*/ B(B&&); };\n"
|
|
"class C { /*asdf*/ C(const C&, int i = 0); };",
|
|
runCheckOnCode<ExplicitConstructorCheck>(
|
|
"class A { explicit A(const A&); };\n"
|
|
"class B { explicit /*asdf*/ B(B&&); };\n"
|
|
"class C { explicit/*asdf*/ C(const C&, int i = 0); };"));
|
|
}
|
|
|
|
TEST(ExplicitConstructorCheckTest, RemoveExplicitWithMacros) {
|
|
EXPECT_EQ(
|
|
"#define A(T) class T##Bar { explicit T##Bar(const T##Bar &b) {} };\n"
|
|
"A(Foo);",
|
|
runCheckOnCode<ExplicitConstructorCheck>(
|
|
"#define A(T) class T##Bar { explicit T##Bar(const T##Bar &b) {} };\n"
|
|
"A(Foo);"));
|
|
}
|
|
|
|
class GlobalNamesInHeadersCheckTest : public ::testing::Test {
|
|
protected:
|
|
bool runCheckOnCode(const std::string &Code, const std::string &Filename) {
|
|
static const char *const Header = "namespace std {\n"
|
|
"class string {};\n"
|
|
"} // namespace std\n"
|
|
"\n"
|
|
"#define SOME_MACRO(x) using x\n";
|
|
std::vector<ClangTidyError> Errors;
|
|
std::vector<std::string> Args;
|
|
if (!StringRef(Filename).ends_with(".cpp")) {
|
|
Args.emplace_back("-xc++-header");
|
|
}
|
|
test::runCheckOnCode<readability::GlobalNamesInHeadersCheck>(
|
|
Header + Code, &Errors, Filename, Args);
|
|
if (Errors.empty())
|
|
return false;
|
|
assert(Errors.size() == 1);
|
|
assert(
|
|
Errors[0].Message.Message ==
|
|
"using declarations in the global namespace in headers are prohibited");
|
|
return true;
|
|
}
|
|
};
|
|
|
|
TEST_F(GlobalNamesInHeadersCheckTest, UsingDeclarations) {
|
|
EXPECT_TRUE(runCheckOnCode("using std::string;", "foo.h"));
|
|
EXPECT_FALSE(runCheckOnCode("using std::string;", "foo.cpp"));
|
|
EXPECT_FALSE(runCheckOnCode("namespace my_namespace {\n"
|
|
"using std::string;\n"
|
|
"} // my_namespace\n",
|
|
"foo.h"));
|
|
EXPECT_FALSE(runCheckOnCode("SOME_MACRO(std::string);", "foo.h"));
|
|
}
|
|
|
|
TEST_F(GlobalNamesInHeadersCheckTest, UsingDirectives) {
|
|
EXPECT_TRUE(runCheckOnCode("using namespace std;", "foo.h"));
|
|
EXPECT_FALSE(runCheckOnCode("using namespace std;", "foo.cpp"));
|
|
EXPECT_FALSE(runCheckOnCode("namespace my_namespace {\n"
|
|
"using namespace std;\n"
|
|
"} // my_namespace\n",
|
|
"foo.h"));
|
|
EXPECT_FALSE(runCheckOnCode("SOME_MACRO(namespace std);", "foo.h"));
|
|
}
|
|
|
|
TEST_F(GlobalNamesInHeadersCheckTest, RegressionAnonymousNamespace) {
|
|
EXPECT_FALSE(runCheckOnCode("namespace {}", "foo.h"));
|
|
}
|
|
|
|
} // namespace test
|
|
} // namespace tidy
|
|
} // namespace clang
|