Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,20 @@ on:

jobs:
build:
timeout-minutes: 5
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
fail-fast: false

runs-on: ${{ matrix.os }}

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Configure CMake
run: cmake -B build -DCMAKE_BUILD_TYPE=Release

- name: Build
run: cmake --build build --config Release

- name: Run tests
working-directory: build
run: ctest -C Release --output-on-failure

lint:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Check file sizes
if: runner.os == 'Linux'
run: |
MAX_LINES=1500
FAILED=0
Expand All @@ -70,8 +55,19 @@ jobs:
echo "All source files are within the $MAX_LINES line limit."

- name: Check formatting with clang-format
if: runner.os == 'Linux'
continue-on-error: true
run: |
sudo apt-get install -y clang-format-17 > /dev/null 2>&1
echo "Checking formatting of source files..."
find src/ include/ -name "*.cpp" -o -name "*.h" | xargs clang-format-17 --dry-run --Werror 2>&1 || echo "::warning::Code formatting issues found. Run clang-format to fix."

- name: Configure CMake
run: cmake -B build -DCMAKE_BUILD_TYPE=Release

- name: Build
run: cmake --build build --config Release

- name: Run tests
working-directory: build
run: ctest -C Release --output-on-failure
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ if( WIN32 )
"${CMAKE_CURRENT_SOURCE_DIR}/3p" )
target_link_libraries(${PROJECT_NAME} PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/3p/doublets_ffi.dll.lib" )
# Increase stack size to 8MB on Windows (default 1MB causes stack overflow
# with deeply recursive export_json on large inputs like text2.json)
if( MSVC )
target_link_options(${TARGET_NAME} PRIVATE /STACK:8388608)
else()
target_link_options(${TARGET_NAME} PRIVATE -Wl,--stack,8388608)
endif()
endif()

# Add tests: for each test JSON file, run avm and compare output with expected
Expand Down Expand Up @@ -78,6 +85,11 @@ target_compile_definitions( avm_unit_test PRIVATE AVM_NO_MAIN )
if( WIN32 )
target_link_libraries( avm_unit_test PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/3p/doublets_ffi.dll.lib" )
if( MSVC )
target_link_options(avm_unit_test PRIVATE /STACK:8388608)
else()
target_link_options(avm_unit_test PRIVATE -Wl,--stack,8388608)
endif()
endif()

add_test( NAME unit_tests COMMAND avm_unit_test )
Expand Down
10 changes: 10 additions & 0 deletions cmake/run_test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

get_filename_component(TEST_NAME "${TEST_FILE}" NAME)

# Remove stale output from previous tests to avoid false positives
set(RES_FILE "${TEST_DIR}/res.json")
if(EXISTS "${RES_FILE}")
file(REMOVE "${RES_FILE}")
endif()

# Run avm on the test file from the test directory
# Note: avm may return non-zero due to static destructor cleanup issues,
# so we check the output file content instead of relying on exit code
Expand All @@ -31,6 +37,10 @@ file(READ "${TEST_FILE}" EXPECTED_CONTENT)
string(STRIP "${ACTUAL_CONTENT}" ACTUAL_CONTENT)
string(STRIP "${EXPECTED_CONTENT}" EXPECTED_CONTENT)

# Normalize line endings (CRLF -> LF) for cross-platform compatibility
string(REPLACE "\r\n" "\n" ACTUAL_CONTENT "${ACTUAL_CONTENT}")
string(REPLACE "\r\n" "\n" EXPECTED_CONTENT "${EXPECTED_CONTENT}")

if(NOT "${ACTUAL_CONTENT}" STREQUAL "${EXPECTED_CONTENT}")
message(FATAL_ERROR "Test ${TEST_NAME} FAILED:\nExpected: ${EXPECTED_CONTENT}\nActual: ${ACTUAL_CONTENT}")
endif()
Expand Down
Loading