Files
anvil/templates/basic/test/run_tests.bat
Eric Ratliff aa1e9d5043 Add mock Arduino for x86_64 host-side testing
Complete Arduino API mock (mock_arduino.h/cpp) enabling application
code to compile and run on PC without hardware. Includes MockSerial,
String class, GPIO/analog/timing/interrupt mocks with state tracking
and test control API.

- Arduino.h, Wire.h, SPI.h shims intercept includes in test builds
- System test template (test_system.cpp) using SimHal
- CMakeLists.txt builds mock_arduino as static lib, links both suites
- Root test.sh/test.bat with --unit/--system/--clean/--verbose flags
- test.bat auto-detects MSVC via vswhere + vcvarsall.bat
- Doctor reports nuanced compiler status (on PATH vs installed)
- Refresh pulls mock infrastructure into existing projects
- 15 tests passing: 7 unit (MockHal) + 8 system (SimHal)
2026-02-20 08:21:11 -06:00

72 lines
1.9 KiB
Batchfile

@echo off
setlocal enabledelayedexpansion
set "SCRIPT_DIR=%~dp0"
:: %~dp0 always ends with \ which breaks cmake quoting ("path\" escapes the quote)
set "SCRIPT_DIR=%SCRIPT_DIR:~0,-1%"
set "BUILD_DIR=%SCRIPT_DIR%\build"
:: -- Compiler detection (with vswhere fallback for MSVC) --------------------
set "HAS_COMPILER=0"
where g++ >nul 2>&1 && set "HAS_COMPILER=1"
where clang++ >nul 2>&1 && set "HAS_COMPILER=1"
where cl >nul 2>&1 && set "HAS_COMPILER=1"
if "%HAS_COMPILER%"=="1" goto :compiler_ok
set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
if not exist "%VSWHERE%" goto :compiler_ok
for /f "usebackq tokens=*" %%i in (`"%VSWHERE%" -latest -property installationPath`) do (
set "VS_PATH=%%i"
)
if not defined VS_PATH goto :compiler_ok
set "VCVARS=!VS_PATH!\VC\Auxiliary\Build\vcvarsall.bat"
if not exist "!VCVARS!" goto :compiler_ok
echo Setting up MSVC environment...
call "!VCVARS!" x64 >nul 2>&1
:compiler_ok
:: -- Build and test ---------------------------------------------------------
if "%1"=="--clean" (
if exist "%BUILD_DIR%" (
echo Cleaning build directory...
rmdir /s /q "%BUILD_DIR%"
)
)
if not exist "%BUILD_DIR%\CMakeCache.txt" (
echo Configuring test build. First run will fetch Google Test...
cmake -S "%SCRIPT_DIR%" -B "%BUILD_DIR%" -DCMAKE_BUILD_TYPE=Debug
if errorlevel 1 (
echo FAIL: cmake configure failed.
echo cmake and a C++ compiler are required for host-side tests.
echo Run 'anvil doctor' to see install instructions.
exit /b 1
)
)
echo Building tests...
cmake --build "%BUILD_DIR%" --parallel
if errorlevel 1 (
echo FAIL: build failed
exit /b 1
)
echo.
echo Running tests...
echo.
ctest --test-dir "%BUILD_DIR%" --output-on-failure
if errorlevel 1 (
echo.
echo FAIL: Some tests failed.
exit /b 1
)
echo.
echo PASS: All tests passed.