Skip to content

Commit

Permalink
Merge bitcoin#31542: test: Embed univalue json tests in binary
Browse files Browse the repository at this point in the history
faf7eac test: clang-format -i src/univalue/test/unitester.cpp (MarcoFalke)
fafa9cc test: Embed univalue json tests in binary (MarcoFalke)
fa04485 test: Re-enable univalue test fail18.json (MarcoFalke)
63b6b63 build: Use character literals for generated headers to avoid narrowing (Lőrinc)

Pull request description:

  All other benchmarks and tests have their data embedded, except for the univalue json tests.

  This is not only confusing, but also problematic, when the test binary is moved to a different system for testing, because one has to put the test files in the source dir that was used at compile-time.

  Fix all issues by embedding them. Also, re-enable a disabled test. Also, fix an issue in the GenerateHeaderFromJson.cmake.

  Requested in https://github.com/bitcoin/bitcoin/pull/31434/files#r1876000910

ACKs for top commit:
  l0rinc:
    ACK faf7eac
  fjahr:
    tACK faf7eac
  achow101:
    ACK faf7eac
  TheCharlatan:
    Re-ACK faf7eac
  hebasto:
    Re-ACK faf7eac. The commit, which modifies CMake scripts, has been replaced with the one from bitcoin#31547, and a formatting commit has been added since my recent [review](bitcoin#31542 (review)).

Tree-SHA512: 72ad202125746f32ccf07411ad3efd2771f27a40525c204cba3c9c83b3ca46d05dd18f6fa5985720c6684bdcbb4c4853fc609ced095ddd1a124832318dd8a55d
  • Loading branch information
achow101 committed Jan 3, 2025
2 parents 6aa0e70 + faf7eac commit 4036ee3
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 117 deletions.
2 changes: 1 addition & 1 deletion cmake/script/GenerateHeaderFromJson.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cmake_path(GET JSON_SOURCE_PATH STEM json_source_basename)

file(READ ${JSON_SOURCE_PATH} hex_content HEX)
string(REGEX REPLACE "................" "\\0\n" formatted_bytes "${hex_content}")
string(REGEX REPLACE "[^\n][^\n]" "0x\\0, " formatted_bytes "${formatted_bytes}")
string(REGEX REPLACE "[^\n][^\n]" "'\\\\x\\0'," formatted_bytes "${formatted_bytes}")

set(header_content
"#include <string_view>
Expand Down
2 changes: 1 addition & 1 deletion cmake/script/GenerateHeaderFromRaw.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cmake_path(GET RAW_SOURCE_PATH STEM raw_source_basename)

file(READ ${RAW_SOURCE_PATH} hex_content HEX)
string(REGEX REPLACE "................" "\\0\n" formatted_bytes "${hex_content}")
string(REGEX REPLACE "[^\n][^\n]" "std::byte{0x\\0}, " formatted_bytes "${formatted_bytes}")
string(REGEX REPLACE "[^\n][^\n]" "std::byte{0x\\0}," formatted_bytes "${formatted_bytes}")

set(header_content
"#include <cstddef>
Expand Down
117 changes: 113 additions & 4 deletions src/univalue/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,119 @@ target_include_directories(univalue
target_link_libraries(univalue PRIVATE core_interface)

if(BUILD_TESTS)
add_executable(unitester test/unitester.cpp)
target_compile_definitions(unitester
PRIVATE
JSON_TEST_SRC=\"${CMAKE_CURRENT_SOURCE_DIR}/test\"
include(GenerateHeaders)
generate_header_from_json(test/fail1.json)
generate_header_from_json(test/fail10.json)
generate_header_from_json(test/fail11.json)
generate_header_from_json(test/fail12.json)
generate_header_from_json(test/fail13.json)
generate_header_from_json(test/fail14.json)
generate_header_from_json(test/fail15.json)
generate_header_from_json(test/fail16.json)
generate_header_from_json(test/fail17.json)
generate_header_from_json(test/fail18.json)
generate_header_from_json(test/fail19.json)
generate_header_from_json(test/fail2.json)
generate_header_from_json(test/fail20.json)
generate_header_from_json(test/fail21.json)
generate_header_from_json(test/fail22.json)
generate_header_from_json(test/fail23.json)
generate_header_from_json(test/fail24.json)
generate_header_from_json(test/fail25.json)
generate_header_from_json(test/fail26.json)
generate_header_from_json(test/fail27.json)
generate_header_from_json(test/fail28.json)
generate_header_from_json(test/fail29.json)
generate_header_from_json(test/fail3.json)
generate_header_from_json(test/fail30.json)
generate_header_from_json(test/fail31.json)
generate_header_from_json(test/fail32.json)
generate_header_from_json(test/fail33.json)
generate_header_from_json(test/fail34.json)
generate_header_from_json(test/fail35.json)
generate_header_from_json(test/fail36.json)
generate_header_from_json(test/fail37.json)
generate_header_from_json(test/fail38.json)
generate_header_from_json(test/fail39.json)
generate_header_from_json(test/fail4.json)
generate_header_from_json(test/fail40.json)
generate_header_from_json(test/fail41.json)
generate_header_from_json(test/fail42.json)
generate_header_from_json(test/fail44.json)
generate_header_from_json(test/fail45.json)
generate_header_from_json(test/fail5.json)
generate_header_from_json(test/fail6.json)
generate_header_from_json(test/fail7.json)
generate_header_from_json(test/fail8.json)
generate_header_from_json(test/fail9.json)
generate_header_from_json(test/pass1.json)
generate_header_from_json(test/pass2.json)
generate_header_from_json(test/pass3.json)
generate_header_from_json(test/pass4.json)
generate_header_from_json(test/round1.json)
generate_header_from_json(test/round2.json)
generate_header_from_json(test/round3.json)
generate_header_from_json(test/round4.json)
generate_header_from_json(test/round5.json)
generate_header_from_json(test/round6.json)
generate_header_from_json(test/round7.json)
add_executable(unitester
${CMAKE_CURRENT_BINARY_DIR}/test/fail1.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail10.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail11.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail12.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail13.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail14.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail15.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail16.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail17.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail18.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail19.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail2.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail20.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail21.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail22.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail23.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail24.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail25.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail26.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail27.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail28.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail29.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail3.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail30.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail31.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail32.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail33.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail34.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail35.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail36.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail37.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail38.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail39.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail4.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail40.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail41.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail42.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail44.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail45.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail5.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail6.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail7.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail8.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/fail9.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/pass1.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/pass2.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/pass3.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/pass4.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/round1.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/round2.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/round3.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/round4.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/round5.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/round6.json.h
${CMAKE_CURRENT_BINARY_DIR}/test/round7.json.h
test/unitester.cpp
)
target_link_libraries(unitester
PRIVATE
Expand Down
2 changes: 1 addition & 1 deletion src/univalue/test/fail18.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]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