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
92 changes: 76 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand All @@ -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
Expand Down
Binary file removed tests/run_tests
Binary file not shown.
22 changes: 0 additions & 22 deletions tests/run_tests.sh

This file was deleted.

16 changes: 16 additions & 0 deletions tests/run_tests.sh.in
Original file line number Diff line number Diff line change
@@ -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
Loading