Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,20 @@ jobs:
zip \
libstdc++-15-dev \
clang-${{ matrix.clang-version }} \
libclang-${{ matrix.clang-version }}-dev
libclang-${{ matrix.clang-version }}-dev \
llvm-${{ matrix.clang-version }}-tools

- name: Build
- name: Build and test
run: |
mkdir build
cd build
cmake \
-DCMAKE_C_COMPILER=/usr/bin/clang-${{matrix.clang-version}} \
-DCMAKE_CXX_COMPILER=/usr/bin/clang++-${{matrix.clang-version}} \
-DCMAKE_PREFIX_PATH=/usr/lib/llvm-${{matrix.clang-version}} \
-DBUILD_TESTING=On \
..
make -j"$(nproc)"
make -j"$(nproc)" check-chatterino-clang-tidy-module

- name: Generate tag
id: gen-tag
Expand Down
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ project(chatterino-clang-tidy-module
find_package(LLVM REQUIRED CONFIG)
find_package(Clang REQUIRED CONFIG)

message(STATUS "Using LLVM from ${LLVM_DIR}")
message(STATUS "Using Clang from ${Clang_DIR}")

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_subdirectory(src)
if (BUILD_TESTING)
add_subdirectory(tests)
endif()
13 changes: 13 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
find_file(llvm_lit_py_path
NAMES lit.py llvm-lit llvm-lit.py
HINTS "${LLVM_INSTALL_PREFIX}/build/utils/lit"
REQUIRED
)

configure_file(lit.site.cfg.py.in lit.site.cfg.py @ONLY)

add_custom_target(check-chatterino-clang-tidy-module
COMMAND "${llvm_lit_py_path}" "${CMAKE_CURRENT_BINARY_DIR}" -v
DEPENDS chatterino-clang-tidy-module)

add_dependencies(check-chatterino-clang-tidy-module chatterino-clang-tidy-module)
12 changes: 0 additions & 12 deletions tests/a.cpp

This file was deleted.

19 changes: 0 additions & 19 deletions tests/base.cpp

This file was deleted.

16 changes: 16 additions & 0 deletions tests/explicit-this/a.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// RUN: %c2-clang-tidy %s -- | FileCheck %s

class Foo
{
int a;
void xd();
};

void Foo::xd()
{
a = 5;
// CHECK: :[[@LINE-1]]:5: warning: use explicit 'this->' for member access [chatterino-explicit-this]

this->a = 4;
// CHECK-NOT: :[[@LINE-1]]
}
24 changes: 24 additions & 0 deletions tests/explicit-this/base.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// RUN: %c2-clang-tidy %s -- | FileCheck %s

class Base
{
protected:
virtual void c();
};

class Derived : Base
{
void xd();
};

void Derived::xd()
{
this->c();
// CHECK-NOT: :[[@LINE-1]]

c();
// CHECK: :[[@LINE-1]]:5: warning: use explicit 'this->' for member access [chatterino-explicit-this]

Base::c();
// CHECK-NOT: :[[@LINE-1]]
}
18 changes: 18 additions & 0 deletions tests/explicit-this/sharedfromthis.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// RUN: %c2-clang-tidy %s -- | FileCheck %s

#include <memory>

class Foo : std::enable_shared_from_this<Foo>
{
int a;
void xd();
};

void Foo::xd()
{
auto b = shared_from_this();
// CHECK-NOT: :[[@LINE-1]]

a = 1;
// CHECK: :[[@LINE-1]]:5: warning: use explicit 'this->' for member access [chatterino-explicit-this]
}
45 changes: 45 additions & 0 deletions tests/explicit-this/static.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// RUN: %c2-clang-tidy %s -- | FileCheck %s

class Base
{
protected:
static void a();
};

class Derived : Base
{
static void b();

static int c;

int d;

void xd();
};

void Derived::xd()
{
Base::a();
// CHECK-NOT: :[[@LINE-1]]

Derived::a();
// CHECK-NOT: :[[@LINE-1]]

Derived::b();
// CHECK-NOT: :[[@LINE-1]]

Derived::c = 1;
// CHECK-NOT: :[[@LINE-1]]

c = 1;
// CHECK-NOT: :[[@LINE-1]]

d = 3;
// CHECK: :[[@LINE-1]]:5: warning: use explicit 'this->' for member access [chatterino-explicit-this]

a();
// CHECK-NOT: :[[@LINE-1]]

b();
// CHECK-NOT: :[[@LINE-1]]
}
38 changes: 38 additions & 0 deletions tests/lit.cfg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import lit.formats
import sys

match sys.platform:
case "linux":
shlibext = ".so"
case "darwin":
shlibext = ".dylib"
case "win32":
shlibext = ".dll"
case _:
raise NotImplementedError()


config.name = "Chatterino clang-tidy-module"
config.test_format = lit.formats.ShTest(True)

config.suffixes = [".cpp", ".test"]

config.test_source_root = os.path.dirname(__file__)
config.test_exec_root = os.path.join(config.c2_obj_root, "test")

c2_module = os.path.join(
config.c2_obj_root, "src", f"chatterino-clang-tidy-module{shlibext}"
)
config.substitutions.append(
(
"%c2-module",
c2_module,
)
)
config.substitutions.append(
("%c2-clang-tidy", f"clang-tidy -load={c2_module} --checks='chatterino-*'")
)

config.environment["PATH"] = os.path.pathsep.join(
(config.llvm_tools_binary_dir, config.environment.get("PATH", ""))
)
7 changes: 7 additions & 0 deletions tests/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import os

config.c2_src_root = r'@CMAKE_SOURCE_DIR@'
config.c2_obj_root = r'@CMAKE_BINARY_DIR@'
config.llvm_tools_binary_dir = r'@LLVM_TOOLS_BINARY_DIR@'

lit_config.load_config(config, os.path.join(config.c2_src_root, "tests/lit.cfg.py"))
12 changes: 0 additions & 12 deletions tests/sharedfromthis.cpp

This file was deleted.

31 changes: 0 additions & 31 deletions tests/static.cpp

This file was deleted.