From 00f60ee83b722cc3f6bbe9d85864efe22c6185ec Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Mar 2026 03:37:21 +0000 Subject: [PATCH 1/2] Initial plan From f0c2a9a10993e3f399388241ed7a47d4d84ffb25 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Mar 2026 03:44:33 +0000 Subject: [PATCH 2/2] Fix README docs, scripts, CI/CD workflow, and Dockerfile - README.md: fix include/ dir name, section numbering, executable paths, build commands, Docker instructions, size output example, add gcovr entry - scripts/run.sh: move shebang to line 1, remove dead code and non-existent private/genid.py reference, quote variable in command -v - scripts/gen_coverage_lcov.sh: use -DENABLE_COVERAGE=ON to match CMakeLists, make xdg-open conditional for headless environments - scripts/gen_coverage_gcovr.sh: same coverage flag and xdg-open fixes - tests/README.md: fix typo "statememts" -> "statements" - CI/CD workflow: add continue-on-error to experimental clang-tidy step - Dockerfile: add missing git package Co-authored-by: urbytes21 <118428350+urbytes21@users.noreply.github.com> --- .github/workflows/cpp-build-test-coverage.yml | 1 + Dockerfile | 3 +- README.md | 35 +++++++++++-------- scripts/gen_coverage_gcovr.sh | 10 ++++-- scripts/gen_coverage_lcov.sh | 10 ++++-- scripts/run.sh | 24 ++----------- tests/README.md | 2 +- 7 files changed, 41 insertions(+), 44 deletions(-) diff --git a/.github/workflows/cpp-build-test-coverage.yml b/.github/workflows/cpp-build-test-coverage.yml index 0495483..e73280d 100644 --- a/.github/workflows/cpp-build-test-coverage.yml +++ b/.github/workflows/cpp-build-test-coverage.yml @@ -103,6 +103,7 @@ jobs: # - Add `--warnings-as-errors=*` to exit code 1 # ------------------------------------------------------- - name: Run clang-tidy + continue-on-error: true # run: | # echo "Running clang-tidy..." # clang-tidy \ diff --git a/Dockerfile b/Dockerfile index 80d4f69..18cab48 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,9 +9,10 @@ FROM ubuntu:24.04 RUN \ # updates the package lists for upgrades for packages that need upgrading, apt-get update && \ - # install cmake, gcc, g++ + # install cmake, gcc, g++, git apt-get install -y cmake && \ apt-get install -y gcc g++ && \ + apt-get install -y git && \ # install cppcheck apt-get install -y cppcheck && \ # install clang tidy diff --git a/README.md b/README.md index 2a05e73..4a344e6 100644 --- a/README.md +++ b/README.md @@ -6,15 +6,18 @@ **Project Hierarchy** ``` -includes/ → Header files (.h, .hpp) +include/ → Header files (.h, .hpp) src/ → Source files (.cpp) tests/ → GoogleTest test cases +scripts/ → Build and coverage helper scripts +cmake/ → CMake dependency modules +docs/ → Documentation and UML diagrams ``` ## 2. Dependencies Make sure the following tools are installed before building the project: - **g++ / gcc** -- **CMake** +- **CMake** (>= 3.14) - **Git** - **lcov** (for code coverage) - **cppcheck** (for static analysis) @@ -36,7 +39,7 @@ Get-ChildItem -Recurse -Include *.cpp, *.h, *.hpp | ForEach-Object { clang-forma ## 3. Setup ### 3.1. Setup the Local Test Environment - **Ubuntu system** - * Install `gcc`, `cmake`, `git`, and `pthread` (Skip this step if you already install) + * Install `gcc`, `cmake`, `git`, and other tools (skip if already installed) ```bash $ sudo apt-get update $ sudo apt-get install g++ @@ -50,18 +53,17 @@ Get-ChildItem -Recurse -Include *.cpp, *.h, *.hpp | ForEach-Object { clang-forma ``` * Build the application and the tests ```bash - $ cd build - $ cmake .. - $ cmake --build . + $ cmake -S . -B build + $ cmake --build build ``` * Run the application and the test ```bash - $ ./bin/cpp_lab_project - $ ./bin/cpp_lab_project_test + $ ./build/bin/cpp_lab_project + $ ./build/bin/cpp_lab_project_unit_test ``` * Detect Memory Leak Using [valgrind](https://valgrind.org/) ```bash - $ valgrind --leak-check=full -v ./cpp-lab + $ valgrind --leak-check=full -v ./build/bin/cpp_lab_project ``` * (Optional) Run static analysis - cppcheck ```bash @@ -75,11 +77,14 @@ Get-ChildItem -Recurse -Include *.cpp, *.h, *.hpp | ForEach-Object { clang-forma ```bash $ ./scripts/gen_coverage_lcov.sh ``` + * (Optional) Run coverage - gcovr + ```bash + $ ./scripts/gen_coverage_gcovr.sh + ``` - **Docker** * Update `Dockerfile` * Build the Docker image ``` - $ cd build $ docker build --tag cpp-lab . ``` * Run an interactive container @@ -234,7 +239,7 @@ Notes: ### 3.3 Documentation with `doxygen` TBD - Refer to this [Documentation with doxygen](https://www.labri.fr/perso/fleury/posts/programming/using-cmake-googletests-and-gcovr-in-a-c-project.html#:~:text=of%20the%C2%A0project.-,Documentation%20with%20doxygen,-Code%20embedded%20documentation) -## 5. Update Docker Image +## 4. Update Docker Image ```bash # Navigate to the project that contain your Dockerfile cd cpp-lab @@ -249,19 +254,19 @@ docker image ls docker push DOCKER_USERNAME/cpp-lab ``` -## 6. TroubleShooting +## 5. TroubleShooting 1. `push access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed` => docker login / Docker Desktop login -## 7. Evaluate Executable +## 6. Evaluate Executable - List all sections: ```bash -$ size ./build/cpp-lab +$ size ./build/bin/cpp_lab_project ``` - The expected output should be the following: ```bash text data bss dec hex filename - 14791 792 280 15863 ./build/cpp-lab + 14791 792 280 15863 3df7 ./build/bin/cpp_lab_project ``` - `.text`: Text Segment - the executable code size, including: complied function, inline, template, constants, string literals diff --git a/scripts/gen_coverage_gcovr.sh b/scripts/gen_coverage_gcovr.sh index 6fda7ab..891297a 100755 --- a/scripts/gen_coverage_gcovr.sh +++ b/scripts/gen_coverage_gcovr.sh @@ -16,7 +16,7 @@ fi if [ ! -d build ]; then cmake -S . -B build \ -DCMAKE_BUILD_TYPE=Debug \ - -DCMAKE_CXX_FLAGS="--coverage -O0 -g" + -DENABLE_COVERAGE=ON fi # ----------------------------------------------------------------------------- @@ -41,6 +41,10 @@ gcovr -r . build \ -o coverage_gcovr/index.html # ----------------------------------------------------------------------------- -# Open coverage report +# Open coverage report (skip in headless environments) # ----------------------------------------------------------------------------- -xdg-open coverage_gcovr/index.html \ No newline at end of file +if command -v xdg-open >/dev/null 2>&1; then + xdg-open coverage_gcovr/index.html +else + echo "Coverage report generated at: coverage_gcovr/index.html" +fi \ No newline at end of file diff --git a/scripts/gen_coverage_lcov.sh b/scripts/gen_coverage_lcov.sh index 64732d3..d643dc8 100755 --- a/scripts/gen_coverage_lcov.sh +++ b/scripts/gen_coverage_lcov.sh @@ -16,7 +16,7 @@ fi if [ ! -d build ]; then cmake -S . -B build \ -DCMAKE_BUILD_TYPE=Debug \ - -DCMAKE_CXX_FLAGS="--coverage -O0 -g" + -DENABLE_COVERAGE=ON fi # ----------------------------------------------------------------------------- @@ -56,6 +56,10 @@ genhtml coverage_lcov/coverage.info \ --output-directory coverage_lcov # ----------------------------------------------------------------------------- -# Open coverage report +# Open coverage report (skip in headless environments) # ----------------------------------------------------------------------------- -xdg-open coverage_lcov/index.html \ No newline at end of file +if command -v xdg-open >/dev/null 2>&1; then + xdg-open coverage_lcov/index.html +else + echo "Coverage report generated at: coverage_lcov/index.html" +fi \ No newline at end of file diff --git a/scripts/run.sh b/scripts/run.sh index 3f264b6..02cd296 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -1,36 +1,22 @@ +#!/usr/bin/env bash ## NOTE: ## This file was initially generated with the assistance of AI. ## The code has been reviewed and may have been modified by the developer ## to ensure correctness, readability, and compliance with project requirements. -#!/usr/bin/env bash set -e # Exit immediately if a command fails PROJECT_EXEC="./build/bin/cpp_lab_project" BUILD_DIR="./build" -# if [ ! -d "build" ]; then -# echo "Build directory not found. Creating build directory..." - -# rm -rf build -# mkdir build -# cd build || exit - -# cmake .. -# cd .. - -# else -# echo "Build directory already exists." -# fi - clear echo "==============================" echo " Starting build pipeline... " echo "==============================" # Check required tools -for tool in cmake cppcheck python3; do - if ! command -v $tool &> /dev/null; then +for tool in cmake cppcheck; do + if ! command -v "$tool" &> /dev/null; then echo "[ERR]: $tool is not installed." exit 1 fi @@ -53,10 +39,6 @@ cppcheck \ echo "[OK] Static analysis passed" -echo "" -echo "===========>> Generating commit id..." -python3 ./private/genid.py - echo "" echo "===========>> Running program..." if [ -f "$PROJECT_EXEC" ]; then diff --git a/tests/README.md b/tests/README.md index f332245..03bb998 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,7 +1,7 @@ # GoogleTest - GoogleTest helps you write better C++ tests. ## 1. Basic Concepts -- **assertions:** the statememts that check whether a condition is true. The result can be: +- **assertions:** the statements that check whether a condition is true. The result can be: - success - nonfatal failure - fatal failure