Skip to content

Commit

Permalink
build(CMake): support running tests with ctest
Browse files Browse the repository at this point in the history
  • Loading branch information
matoro committed Jul 4, 2024
1 parent c8834c2 commit aad68f7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ else()
BLAKE3_DISABLE_SIMD()
endif()

# cmake test support
if (BLAKE3_BUILD_TESTING)
find_package(Python3 REQUIRED)
get_target_property(BLAKE3_SOURCES blake3 SOURCES)
add_executable(blake3-testing ${BLAKE3_SOURCES} main.c)
set_property(TARGET blake3-testing PROPERTY OUTPUT_NAME blake3)
target_compile_definitions(blake3-testing PRIVATE BLAKE3_TESTING=1)
enable_testing()
add_test(test_vectors "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/test.py" WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
endif()

# cmake install support
install(FILES blake3.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
install(TARGETS blake3 EXPORT blake3-targets)
Expand Down
4 changes: 2 additions & 2 deletions c/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from binascii import hexlify
import json
from os import path
from os import getcwd, path
import subprocess

HERE = path.dirname(__file__)
Expand All @@ -11,7 +11,7 @@


def run_blake3(args, input):
output = subprocess.run([path.join(HERE, "blake3")] + args,
output = subprocess.run([path.join(getcwd(), "blake3")] + args,
input=input,
stdout=subprocess.PIPE,
check=True)
Expand Down

0 comments on commit aad68f7

Please sign in to comment.