diff --git a/CMakeLists.txt b/CMakeLists.txt index 8609193..dd00d66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -152,8 +152,50 @@ include_directories(${GTEST_INCLUDE_DIRS}) # Set runtime output directory set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) -# Create tests directory -file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/tests) +# Create tests directory if it doesn't exist +file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/tests") + +# Ensure the tests directory exists in the source directory +file(MAKE_DIRECTORY "${CMAKE_SOURCE_DIR}/tests") + +# Create the template file in the source directory if it doesn't exist +if(NOT EXISTS "${CMAKE_SOURCE_DIR}/tests/run_tests.sh.in") + file(WRITE "${CMAKE_SOURCE_DIR}/tests/run_tests.sh.in" + "#!/bin/bash\n\n" + "# Test runner script generated by CMake\n" + "# @CMAKE_BINARY_DIR@ will be replaced with actual binary directory\n\n" + "# Set colored output for tests\n" + "export GTEST_COLOR=1\n\n" + "# Run the test executable\n" + "@CMAKE_BINARY_DIR@/run_tests \"$@\"\n\n" + "# Store the exit code\n" + "exit_code=$?\n\n" + "# Exit with the test result\n" + "exit $exit_code\n" + ) +endif() + +# Ensure the tests directory exists in the build directory +file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/tests") + +# Use configure_file with the template from the source directory +configure_file( + "${CMAKE_SOURCE_DIR}/tests/run_tests.sh.in" + "${CMAKE_BINARY_DIR}/tests/run_tests.sh" + @ONLY + PERMISSIONS + OWNER_READ OWNER_WRITE OWNER_EXECUTE + GROUP_READ GROUP_EXECUTE + WORLD_READ WORLD_EXECUTE +) + +# Add fixture to ensure test output directory exists +add_test(NAME create_test_output + COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/tests +) +set_tests_properties(create_test_output PROPERTIES + FIXTURES_SETUP test_output +) # Find all test files using globbing file(GLOB TEST_SOURCES CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/tests/*.cpp") @@ -172,12 +214,38 @@ target_link_libraries(run_tests chunk_benchmark ) -# Generate test runner script -configure_file( - "${CMAKE_SOURCE_DIR}/tests/run_tests.sh.in" - "${CMAKE_BINARY_DIR}/tests/run_tests.sh" - @ONLY - FILE_PERMISSIONS +# Add error checking +if(NOT EXISTS "${CMAKE_BINARY_DIR}/tests") + file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/tests") + if(NOT EXISTS "${CMAKE_BINARY_DIR}/tests") + message(FATAL_ERROR "Failed to create tests directory") + endif() +endif() + +# First ensure the tests directory exists +file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/tests") + +# Generate the run_tests.sh script directly +file(WRITE "${CMAKE_BINARY_DIR}/tests/run_tests.sh" + "#!/bin/bash\n\ +\n\ +# Test runner script generated by CMake\n\ +# Set colored output for tests\n\ +export GTEST_COLOR=1\n\ +\n\ +# Run the test executable\n\ +${CMAKE_BINARY_DIR}/run_tests \"$@\"\n\ +\n\ +# Store the exit code\n\ +exit_code=$?\n\ +\n\ +# Exit with the test result\n\ +exit $exit_code\n" +) + +# Set proper permissions on the script +file(CHMOD "${CMAKE_BINARY_DIR}/tests/run_tests.sh" + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE @@ -196,14 +264,6 @@ set_tests_properties(AllTests PROPERTIES FAIL_REGULAR_EXPRESSION ".*[Ff]ail.*" ) -# Add fixture to ensure test output directory exists -add_test(NAME create_test_output - COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/tests -) -set_tests_properties(create_test_output PROPERTIES - FIXTURES_SETUP test_output -) - # Add the sophisticated chunking library add_library(sophisticated_chunking src/sophisticated_chunking_demo.cpp diff --git a/tests/run_tests b/tests/run_tests deleted file mode 100644 index f3b25ea..0000000 Binary files a/tests/run_tests and /dev/null differ diff --git a/tests/run_tests.sh b/tests/run_tests.sh deleted file mode 100644 index 2e26b0e..0000000 --- a/tests/run_tests.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -# Create directory for test results if it doesn't exist -mkdir -p "${0%/*}" -mkdir -p "${0%/*}/results" - -# Run the tests and generate XML report -cd "${0%/*}" && ./run_tests --gtest_output=xml:test_results.xml --gtest_break_on_failure - -# Check if tests passed -if [ $? -eq 0 ]; then - echo 'All tests passed!' - exit 0 -else - echo 'Some tests failed!' - if [ -f test_results.xml ]; then - cat test_results.xml - else - echo Error:test_results.xmlnotfound - fi - exit 1 -fi diff --git a/tests/run_tests.sh.in b/tests/run_tests.sh.in new file mode 100644 index 0000000..d5f4de1 --- /dev/null +++ b/tests/run_tests.sh.in @@ -0,0 +1,16 @@ +#!/bin/bash + +# Test runner script generated by CMake +# @CMAKE_BINARY_DIR@ will be replaced with actual binary directory + +# Set colored output for tests +export GTEST_COLOR=1 + +# Run the test executable +@CMAKE_BINARY_DIR@/run_tests + +# Store the exit code +exit_code=$? + +# Exit with the test result +exit $exit_code