diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ea735ca..56d8b9f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,6 +24,7 @@ on: jobs: build: + timeout-minutes: 5 strategy: matrix: os: [ubuntu-latest, windows-latest, macos-latest] @@ -31,28 +32,12 @@ jobs: 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 @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index d9e244e..f395fa6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -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 ) diff --git a/cmake/run_test.cmake b/cmake/run_test.cmake index 92a9c3b..2ba5a42 100644 --- a/cmake/run_test.cmake +++ b/cmake/run_test.cmake @@ -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 @@ -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()