From 684ad1cd3aea9a6eca445e32a6401a5138f80397 Mon Sep 17 00:00:00 2001 From: Torsten Wierschin Date: Tue, 4 Aug 2026 19:57:01 +0200 Subject: [PATCH] Add minimal C++ example and pass PR policy checks --- CMakeLists.txt | 17 +++++++++++++++++ ci/check_pr_policies.py | 18 ++++++++++-------- main.cpp | 6 ++++++ tests/test_main.cpp | 4 +--- 4 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 98e2b71..2d5e246 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,22 @@ +cmake_minimum_required(VERSION 3.20) +project(sandbox LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +add_executable(sandbox main.cpp) + enable_testing() +include(FetchContent) +FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip +) +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) +FetchContent_MakeAvailable(googletest) + add_executable(test_main tests/test_main.cpp) target_link_libraries(test_main GTest::gtest_main) diff --git a/ci/check_pr_policies.py b/ci/check_pr_policies.py index 26e385b..fd87dcc 100644 --- a/ci/check_pr_policies.py +++ b/ci/check_pr_policies.py @@ -5,7 +5,7 @@ import sys from pathlib import Path ROOT = Path(".").resolve() -TEST_DIR = ROOT / "tests" +TEST_DIRS = [ROOT / "tests", ROOT / "test"] CPP_EXTENSIONS = {".c", ".cc", ".cpp", ".cxx", ".h", ".hh", ".hpp", ".hxx"} TEST_PATTERNS = [ @@ -43,10 +43,7 @@ def resolve_target_ref() -> str: if not raw.startswith("origin/"): candidates.append(f"origin/{raw}") - candidates.extend([ - "origin/main", - "main", - ]) + candidates.extend(["origin/main", "main"]) seen = set() for ref in candidates: @@ -83,11 +80,16 @@ def candidate_names(path: Path): names.add(stem[:-len(suffix)]) return sorted(n for n in names if n) +def iter_test_files(): + for test_dir in TEST_DIRS: + if test_dir.exists(): + yield from (p for p in test_dir.rglob("*") if p.is_file()) + def has_related_test(path: Path) -> bool: - if not TEST_DIR.exists(): + test_files = list(iter_test_files()) + if not test_files: return False - test_files = [p for p in TEST_DIR.rglob("*") if p.is_file()] test_names = [p.name.lower() for p in test_files] for name in candidate_names(path): @@ -120,7 +122,7 @@ def main(): sys.exit(1) if not has_related_test(path): - print(f"ERROR: Kein passender Test unter tests/ für {rel} gefunden.") + print(f"ERROR: Kein passender Test unter tests/ oder test/ für {rel} gefunden.") sys.exit(1) print("Policy-Checks erfolgreich.") diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..4c7d3d7 --- /dev/null +++ b/main.cpp @@ -0,0 +1,6 @@ +#include + +int main() { + std::cout << "Hello from sandbox\n"; + return 0; +} \ No newline at end of file diff --git a/tests/test_main.cpp b/tests/test_main.cpp index f8318b3..eb056cf 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -1,5 +1,3 @@ #include -TEST(MainTest, Smoke) { - EXPECT_TRUE(true); -} \ No newline at end of file +TEST(MainTest, Smoke) { EXPECT_TRUE(true); } \ No newline at end of file