Skip to content

Commit 11b5a13

Browse files
committed
Made a good number of changes to tests/workflow
1 parent 5e55828 commit 11b5a13

File tree

9 files changed

+294
-218
lines changed

9 files changed

+294
-218
lines changed

.github/workflows/build.yml

Lines changed: 90 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,7 @@ jobs:
3232
vcpkg-windows-${{ hashFiles('vcpkg.json') }}-
3333
vcpkg-windows-
3434
35-
- name: Prepare build.ps1 from build.default.ps1
36-
shell: pwsh
37-
run: |
38-
Copy-Item build.default.ps1 build.ps1
39-
(Get-Content build.ps1) -replace '^\$VCPKG_PATH\s*=.*', '$VCPKG_PATH = "${{ env.VCPKG_ROOT }}"' | Set-Content build.ps1
40-
41-
- name: Build Project (PowerShell)
42-
shell: pwsh
43-
run: ./build.ps1
44-
45-
- name: Run Game Executable Test
46-
working-directory: build/bin/Debug
47-
run: |
48-
# Keep --test flag for now to avoid audio issues in CI
49-
./meowstro.exe --test
50-
51-
- name: Run cppcheck (static analysis)
35+
- name: Run cppcheck (static analysis - fail fast)
5236
run: |
5337
if (!(Get-Command cppcheck -ErrorAction SilentlyContinue)) {
5438
choco install cppcheck -y
@@ -59,7 +43,28 @@ jobs:
5943
-I "${{ env.VCPKG_ROOT }}/installed/x64-windows/include" `
6044
src
6145
62-
- name: Run clang-tidy (static analysis)
46+
- name: Cache CMake build directory
47+
uses: actions/cache@v4
48+
with:
49+
path: build
50+
key: cmake-windows-${{ hashFiles('**/CMakeLists.txt', 'vcpkg.json') }}-${{ hashFiles('src/**', 'include/**') }}
51+
restore-keys: |
52+
cmake-windows-${{ hashFiles('**/CMakeLists.txt', 'vcpkg.json') }}-
53+
cmake-windows-
54+
55+
- name: Prepare build.ps1 from build.default.ps1
56+
shell: pwsh
57+
run: |
58+
Copy-Item build.default.ps1 build.ps1
59+
(Get-Content build.ps1) -replace '^\$VCPKG_PATH\s*=.*', '$VCPKG_PATH = "${{ env.VCPKG_ROOT }}"' | Set-Content build.ps1
60+
61+
- name: Configure CMake for clang-tidy
62+
shell: pwsh
63+
run: |
64+
# Configure CMake to generate compile_commands.json for clang-tidy
65+
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE="${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Debug
66+
67+
- name: Run clang-tidy (static analysis after CMake configure)
6368
run: |
6469
if (!(Get-Command clang-tidy -ErrorAction SilentlyContinue)) {
6570
choco install llvm -y
@@ -70,10 +75,11 @@ jobs:
7075
Write-Host "No compilation database found, skipping clang-tidy"
7176
}
7277
73-
- name: Run Unit Tests
78+
- name: Build and Test via Script
79+
shell: pwsh
7480
run: |
75-
cd build
76-
ctest --output-on-failure -C Debug
81+
# Run the test script which handles build, test execution, and CTest
82+
./test.ps1
7783
7884
- name: Upload Executable Artifact (main branch only)
7985
if: github.ref == 'refs/heads/main'
@@ -88,6 +94,14 @@ jobs:
8894
- name: Checkout Repository
8995
uses: actions/checkout@v4
9096

97+
- name: Cache APT packages
98+
uses: actions/cache@v4
99+
with:
100+
path: /var/cache/apt/archives
101+
key: apt-${{ runner.os }}-${{ hashFiles('**/CMakeLists.txt') }}
102+
restore-keys: |
103+
apt-${{ runner.os }}-
104+
91105
- name: Install SDL2 system packages and build tools
92106
run: |
93107
sudo apt-get update
@@ -99,120 +113,117 @@ jobs:
99113
libsdl2-image-dev \
100114
libsdl2-mixer-dev \
101115
libsdl2-ttf-dev \
116+
libgtest-dev \
117+
googletest \
102118
cppcheck \
103119
clang-tidy
104120
121+
- name: Run cppcheck (static analysis - fail fast)
122+
run: |
123+
cppcheck --enable=all --inconclusive --std=c++17 --quiet \
124+
-I include \
125+
src
126+
127+
- name: Cache CMake build directory
128+
uses: actions/cache@v4
129+
with:
130+
path: build
131+
key: cmake-linux-${{ hashFiles('**/CMakeLists.txt') }}-${{ hashFiles('src/**', 'include/**') }}
132+
restore-keys: |
133+
cmake-linux-${{ hashFiles('**/CMakeLists.txt') }}-
134+
cmake-linux-
135+
105136
- name: Configure CMake (using system packages, NOT vcpkg)
106137
run: |
107138
# Explicitly avoid vcpkg by not setting CMAKE_TOOLCHAIN_FILE
108139
cmake -B build -S . \
109140
-DCMAKE_BUILD_TYPE=Debug \
110141
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
111142
112-
- name: Build Project
113-
run: cmake --build build --parallel $(nproc)
114-
115-
- name: Run Game Executable Test
116-
run: |
117-
# Keep --test flag for now to avoid audio issues in CI
118-
# Find the executable location (Linux builds to build/bin, not build/bin/Debug)
119-
if [ -f "build/bin/Debug/meowstro" ]; then
120-
build/bin/Debug/meowstro --test
121-
elif [ -f "build/bin/meowstro" ]; then
122-
build/bin/meowstro --test
123-
else
124-
echo "Main executable not found, checking build directory..."
125-
find build -name "meowstro" -type f
126-
exit 1
127-
fi
128-
129-
- name: Run cppcheck (static analysis)
130-
run: |
131-
cppcheck --enable=all --inconclusive --std=c++17 --quiet \
132-
-I include \
133-
src
134-
135-
- name: Run clang-tidy (static analysis)
143+
- name: Run clang-tidy (static analysis after CMake configure)
136144
run: |
137145
if [ -f "build/compile_commands.json" ]; then
138146
find src -name '*.cpp' -exec clang-tidy -p build {} \;
139147
else
140148
echo "No compilation database found, skipping clang-tidy"
141149
fi
142150
143-
- name: Run Unit Tests
151+
- name: Build and Test via Script
144152
run: |
145-
cd build
146-
ctest --output-on-failure
153+
# Make script executable and run it
154+
chmod +x ./test.sh
155+
./test.sh
147156
148157
- name: Upload Executable Artifact (main branch only)
149158
if: github.ref == 'refs/heads/main'
150159
uses: actions/upload-artifact@v4
151160
with:
152161
name: meowstro-linux
153-
path: |
154-
build/bin/
155-
!build/bin/**/*.o
156-
!build/bin/**/*.a
162+
path: build/bin/Debug/
157163

158164
build-macos:
159165
runs-on: macos-latest
160166
steps:
161167
- name: Checkout Repository
162168
uses: actions/checkout@v4
163169

170+
- name: Cache Homebrew packages
171+
uses: actions/cache@v4
172+
with:
173+
path: |
174+
~/Library/Caches/Homebrew
175+
/opt/homebrew/var/homebrew/locks
176+
key: brew-${{ runner.os }}-${{ hashFiles('**/CMakeLists.txt') }}
177+
restore-keys: |
178+
brew-${{ runner.os }}-
179+
164180
- name: Install SDL2 via Homebrew
165181
run: |
166182
brew install \
167183
sdl2 \
168184
sdl2_image \
169185
sdl2_mixer \
170186
sdl2_ttf \
187+
googletest \
171188
cppcheck \
172189
llvm
173190
191+
- name: Run cppcheck (static analysis - fail fast)
192+
run: |
193+
cppcheck --enable=all --inconclusive --std=c++17 --quiet \
194+
-I include \
195+
src
196+
197+
- name: Cache CMake build directory
198+
uses: actions/cache@v4
199+
with:
200+
path: build
201+
key: cmake-macos-${{ hashFiles('**/CMakeLists.txt') }}-${{ hashFiles('src/**', 'include/**') }}
202+
restore-keys: |
203+
cmake-macos-${{ hashFiles('**/CMakeLists.txt') }}-
204+
cmake-macos-
205+
174206
- name: Configure CMake (Homebrew packages)
175207
run: |
176208
HOMEBREW_PREFIX=$(brew --prefix)
177209
cmake -B build -S . \
178210
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
211+
-DCMAKE_BUILD_TYPE=Debug \
179212
-DCMAKE_PREFIX_PATH="$HOMEBREW_PREFIX"
180213
181-
- name: Build Project
182-
run: cmake --build build --parallel $(sysctl -n hw.logicalcpu)
183-
184-
- name: Run Game Executable Test
185-
run: |
186-
# Keep --test flag for now to avoid audio issues in CI
187-
# Find the executable location for macOS
188-
if [ -f "build/bin/Debug/meowstro" ]; then
189-
build/bin/Debug/meowstro --test
190-
elif [ -f "build/bin/meowstro" ]; then
191-
build/bin/meowstro --test
192-
else
193-
echo "Main executable not found, checking build directory..."
194-
find build -name "meowstro" -type f
195-
exit 1
196-
fi
197-
198-
- name: Run cppcheck (static analysis)
199-
run: |
200-
cppcheck --enable=all --inconclusive --std=c++17 --quiet \
201-
-I include \
202-
src
203-
204-
- name: Run clang-tidy (static analysis)
214+
- name: Run clang-tidy (static analysis after CMake configure)
205215
run: |
206216
if [ -f "build/compile_commands.json" ]; then
207217
$(brew --prefix llvm)/bin/clang-tidy -p build $(find src -name '*.cpp')
208218
else
209219
echo "No compilation database found, skipping clang-tidy"
210220
fi
211221
212-
- name: Run Unit Tests
222+
- name: Build and Test via Script
213223
run: |
214-
cd build
215-
ctest --output-on-failure
224+
# Make script executable and run it
225+
chmod +x ./test.sh
226+
./test.sh
216227
217228
- name: Upload Executable Artifact (main branch only)
218229
if: github.ref == 'refs/heads/main'

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ build/
88
build.ps1
99
build.bat
1010
build.sh
11-
test.ps1
12-
test.bat
13-
test.sh
1411
CMakePresets.json
1512
config.json
1613

src/meowstro.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@
2929

3030
int main(int argc, char** argv)
3131
{
32-
// Add tests later, Audio fails to find endpoint in Git Actions
33-
if (argc > 1 && std::string(argv[1]) == "--test")
34-
return EXIT_SUCCESS;
35-
3632
try {
3733
// Initialize SDL subsystems - fail fast on critical errors
3834
if (SDL_Init(SDL_INIT_VIDEO) != EXIT_SUCCESS) {

test.bat

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
@echo off
2+
REM ===== test.bat =====
3+
REM Simple test runner for Meowstro
4+
5+
echo Running Meowstro Tests...
6+
7+
REM Build the project first (including tests)
8+
echo Building project...
9+
cmake --build build --config Debug
10+
11+
if %errorlevel% neq 0 (
12+
echo Build failed! Cannot run tests.
13+
exit /b 1
14+
)
15+
16+
echo.
17+
echo Running tests with detailed output...
18+
19+
REM Find and run the test executable
20+
set "TEST_EXECUTABLE="
21+
if exist ".\build\bin\Debug\meowstro_tests.exe" (
22+
set "TEST_EXECUTABLE=.\build\bin\Debug\meowstro_tests.exe"
23+
) else if exist ".\build\bin\Debug\meowstro_tests" (
24+
set "TEST_EXECUTABLE=.\build\bin\Debug\meowstro_tests"
25+
) else if exist ".\build\bin\meowstro_tests.exe" (
26+
set "TEST_EXECUTABLE=.\build\bin\meowstro_tests.exe"
27+
) else if exist ".\build\bin\meowstro_tests" (
28+
set "TEST_EXECUTABLE=.\build\bin\meowstro_tests"
29+
) else (
30+
echo ❌ Test executable not found!
31+
echo Searched for:
32+
echo - .\build\bin\Debug\meowstro_tests.exe
33+
echo - .\build\bin\Debug\meowstro_tests
34+
echo - .\build\bin\meowstro_tests.exe
35+
echo - .\build\bin\meowstro_tests
36+
exit /b 1
37+
)
38+
39+
echo Running: %TEST_EXECUTABLE%
40+
%TEST_EXECUTABLE%
41+
42+
if %errorlevel% equ 0 (
43+
echo.
44+
echo ✅ All tests passed!
45+
46+
REM Also show CTest summary
47+
echo.
48+
echo CTest Summary:
49+
pushd build
50+
ctest --output-on-failure -C Debug
51+
if %errorlevel% neq 0 (
52+
echo ❌ CTest failed!
53+
popd
54+
exit /b 1
55+
)
56+
popd
57+
) else (
58+
echo.
59+
echo ❌ Some tests failed!
60+
exit /b 1
61+
)
62+
63+
echo.
64+
echo Testing complete!

test.default.bat

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)