Skip to content

Commit 2d8469e

Browse files
authored
Merge pull request #6 from developer239/feat/test
basic e2e test framework
2 parents 39779b6 + c765b0f commit 2d8469e

File tree

18 files changed

+1300
-64
lines changed

18 files changed

+1300
-64
lines changed
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,27 @@ name: Build
22

33
on:
44
push:
5-
branches:
6-
- master
5+
branches: [ master ]
76
paths:
87
- 'src/**'
8+
- 'tests/**'
9+
- '.github/**'
10+
- 'CMakeLists.txt'
911
pull_request:
10-
branches:
11-
- master
12+
branches: [ master ]
1213
paths:
1314
- 'src/**'
15+
- 'tests/**'
16+
- '.github/**'
17+
- 'CMakeLists.txt'
1418

1519
jobs:
1620
build:
17-
runs-on: macos-12
21+
runs-on: macos-latest
1822
steps:
19-
- name: Checkout repository
20-
uses: actions/checkout@v2
23+
- uses: actions/checkout@v3
2124
with:
22-
submodules: 'recursive'
25+
submodules: recursive
2326

2427
- name: Install dependencies
2528
run: |

.github/workflows/test-macos.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: MacOS Tests (mouse)
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
paths:
7+
- 'src/**'
8+
- 'tests/**'
9+
- '.github/**'
10+
- 'CMakeLists.txt'
11+
pull_request:
12+
branches: [ master ]
13+
paths:
14+
- 'src/**'
15+
- 'tests/**'
16+
- '.github/**'
17+
- 'CMakeLists.txt'
18+
19+
jobs:
20+
test-macos:
21+
runs-on: macos-latest
22+
steps:
23+
- uses: actions/checkout@v3
24+
with:
25+
submodules: recursive
26+
27+
- name: Install dependencies
28+
run: brew install cmake sdl2
29+
30+
- name: Configure
31+
run: cmake -B build -DBUILD_ROBOT_TESTS=ON
32+
33+
- name: Build
34+
run: cmake --build build
35+
36+
- name: Test
37+
run: |
38+
# macOS can run GUI apps in headless mode
39+
build/bin/RobotCPPSDLTest --gtest_filter=-*InteractiveMode --ci-mode true

.github/workflows/test-windows.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Windows Tests (mouse)
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
paths:
7+
- 'src/**'
8+
- 'tests/**'
9+
- '.github/**'
10+
- 'CMakeLists.txt'
11+
pull_request:
12+
branches: [ master ]
13+
paths:
14+
- 'src/**'
15+
- 'tests/**'
16+
- '.github/**'
17+
- 'CMakeLists.txt'
18+
19+
jobs:
20+
test-windows:
21+
runs-on: windows-latest
22+
steps:
23+
- uses: actions/checkout@v3
24+
with:
25+
submodules: recursive
26+
27+
- name: Install vcpkg and SDL2
28+
run: |
29+
# Clone vcpkg
30+
git clone https://github.com/Microsoft/vcpkg.git
31+
cd vcpkg
32+
33+
# Bootstrap vcpkg
34+
.\bootstrap-vcpkg.bat
35+
36+
# Install SDL2
37+
.\vcpkg install sdl2:x64-windows
38+
39+
# Integrate with Visual Studio
40+
.\vcpkg integrate install
41+
42+
cd ..
43+
44+
- name: Configure with vcpkg
45+
run: |
46+
cmake -B build -DCMAKE_TOOLCHAIN_FILE="$PWD/vcpkg/scripts/buildsystems/vcpkg.cmake" -DBUILD_ROBOT_TESTS=ON
47+
48+
- name: Build
49+
run: cmake --build build --config Release
50+
51+
- name: Test
52+
run: |
53+
# Check and display directory structure
54+
Write-Host "Checking directory structure..."
55+
56+
# Check vcpkg directories
57+
Write-Host "Vcpkg directories:"
58+
Get-ChildItem -Path "vcpkg\installed\x64-windows\bin" -ErrorAction SilentlyContinue
59+
60+
# Check build output directories
61+
Write-Host "Build output directories:"
62+
Get-ChildItem -Path "build\bin" -ErrorAction SilentlyContinue
63+
Get-ChildItem -Path "build\bin\Release" -ErrorAction SilentlyContinue
64+
65+
# Find SDL2.dll
66+
Write-Host "Finding SDL2.dll..."
67+
Get-ChildItem -Path "vcpkg" -Recurse -Filter "SDL2.dll" -ErrorAction SilentlyContinue |
68+
ForEach-Object { Write-Host $_.FullName }
69+
70+
# Create Release directory if it doesn't exist
71+
if (-not (Test-Path "build\bin\Release")) {
72+
Write-Host "Creating missing directory: build\bin\Release"
73+
New-Item -Path "build\bin\Release" -ItemType Directory -Force
74+
}
75+
76+
# Try to find the executable
77+
Write-Host "Finding test executable..."
78+
Get-ChildItem -Path "build" -Recurse -Filter "*.exe" -ErrorAction SilentlyContinue |
79+
ForEach-Object { Write-Host $_.FullName }
80+
81+
# Try to run the executable wherever it is
82+
$executable = Get-ChildItem -Path "build" -Recurse -Filter "RobotCPPSDLTest.exe" -ErrorAction SilentlyContinue |
83+
Select-Object -First 1
84+
85+
if ($executable) {
86+
Write-Host "Found executable at: $($executable.FullName)"
87+
88+
# Try to find and copy SDL2.dll
89+
$sdl2Dll = Get-ChildItem -Path "vcpkg" -Recurse -Filter "SDL2.dll" -ErrorAction SilentlyContinue |
90+
Select-Object -First 1
91+
92+
if ($sdl2Dll) {
93+
Write-Host "Found SDL2.dll at: $($sdl2Dll.FullName)"
94+
Copy-Item -Path $sdl2Dll.FullName -Destination $executable.DirectoryName -Force
95+
}
96+
97+
# Run the executable
98+
Write-Host "Running: $($executable.FullName) --gtest_filter=-*InteractiveMode --ci-mode true"
99+
& $executable.FullName --gtest_filter=-*InteractiveMode --ci-mode true
100+
} else {
101+
Write-Host "Executable not found!"
102+
exit 1
103+
}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@
66
# Build files
77
/cmake-build-debug
88
/example/cmake-build-debug
9+
10+
11+
/build

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
[submodule "externals/lodepng"]
22
path = externals/lodepng
33
url = https://github.com/lvandeve/lodepng
4+
[submodule "cmake/sdl2"]
5+
path = cmake/sdl2
6+
url = https://github.com/opeik/cmake-modern-findsdl2
7+
[submodule "externals/googletest"]
8+
path = externals/googletest
9+
url = https://github.com/google/googletest

CMakeLists.txt

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,36 @@ cmake_minimum_required(VERSION 3.21)
33
project(RobotCPP)
44

55
set(CMAKE_CXX_STANDARD 23)
6+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7+
set(CMAKE_CXX_EXTENSIONS OFF)
8+
9+
# Library name
610
set(LIB_NAME RobotCPP)
711

12+
# Option to build tests (OFF by default)
13+
option(BUILD_ROBOT_TESTS "Build the RobotCPP tests" OFF)
14+
15+
# Only find dependencies and add GoogleTest if tests are enabled
16+
if(BUILD_ROBOT_TESTS)
17+
# Add GoogleTest
18+
add_subdirectory(externals/googletest)
19+
enable_testing()
20+
21+
# Find SDL2 for tests
22+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/sdl2/")
23+
find_package(SDL2 REQUIRED)
24+
endif()
25+
26+
# Compiler-specific options
27+
if(MSVC)
28+
# MSVC flags
29+
add_compile_options(/W4 /MP)
30+
else()
31+
# GCC/Clang flags
32+
add_compile_options(-Wall -Wextra -Wpedantic)
33+
endif()
34+
35+
# Common source files
836
set(COMMON_SOURCES
937
src/ActionRecorder.h
1038
src/types.h
@@ -17,19 +45,32 @@ set(COMMON_SOURCES
1745
src/Screen.cpp
1846
src/Screen.h)
1947

48+
# External dependencies
2049
set(SOURCES_LODEPNG
2150
externals/lodepng/lodepng.cpp
2251
externals/lodepng/lodepng.h)
2352

24-
if (APPLE)
53+
# Platform-specific components
54+
if(APPLE)
2555
list(APPEND PLATFORM_SOURCES src/EventHookMacOS.h)
2656
find_library(CARBON_LIBRARY Carbon)
2757
mark_as_advanced(CARBON_LIBRARY)
2858
list(APPEND PLATFORM_LIBRARIES ${CARBON_LIBRARY})
29-
elseif (WIN32)
59+
elseif(WIN32)
3060
list(APPEND PLATFORM_SOURCES src/EventHookWindows.h)
31-
endif ()
61+
endif()
3262

63+
# Define the main library
3364
add_library(${LIB_NAME} STATIC ${COMMON_SOURCES} ${PLATFORM_SOURCES} ${SOURCES_LODEPNG})
3465
target_include_directories(${LIB_NAME} PUBLIC src PRIVATE externals/lodepng)
3566
target_link_libraries(${LIB_NAME} ${PLATFORM_LIBRARIES})
67+
68+
# Set output directory for all targets
69+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
70+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/bin)
71+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/bin)
72+
73+
# Add the tests directory only if tests are enabled
74+
if(BUILD_ROBOT_TESTS)
75+
add_subdirectory(tests)
76+
endif()

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Robot CPP
22

3-
![master](https://github.com/developer239/robot-cpp/actions/workflows/ci.yml/badge.svg)
4-
![Windows](https://img.shields.io/badge/Windows-0078D6?style=for-the-badge&logo=windows&logoColor=white)
5-
![macOS](https://img.shields.io/badge/mac%20os-000000?style=for-the-badge&logo=macos&logoColor=F0F0F0)
3+
![Build](https://github.com/developer239/robot-cpp/actions/workflows/build.yml/badge.svg)
4+
[![MacOS Tests](https://github.com/developer239/robot-cpp/actions/workflows/test-macos.yml/badge.svg)](https://github.com/developer239/robot-cpp/actions/workflows/test-macos.yml)
5+
[![Windows Tests](https://github.com/developer239/robot-cpp/actions/workflows/test-windows.yml/badge.svg)](https://github.com/developer239/robot-cpp/actions/workflows/test-windows.yml)
66

77
This library is inspired by older unmaintained libraries like [octalmage/robotjs](https://github.com/octalmage/robotjs)
88
and [Robot/robot-js](https://github.com/Robot/robot-js). The goal is to provide cross-platform controls for various

cmake/sdl2

Submodule sdl2 added at 77f77c6

example/CMakeLists.txt

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

example/main.cpp

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

0 commit comments

Comments
 (0)