Skip to content

Commit dc0052e

Browse files
committed
feat ci: reenable golden tests for chaotic
Tests: протестировано CI commit_hash:4939ffebe5797fcee1a99a62dc30e90aa258e4df
1 parent 6e81184 commit dc0052e

File tree

5 files changed

+21
-14
lines changed

5 files changed

+21
-14
lines changed

chaotic/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ if(USERVER_BUILD_TESTS)
2727
add_subdirectory(integration_tests)
2828

2929
option(USERVER_CHAOTIC_GOLDEN_TESTS "Whether to run golden tests of chaotic" ON)
30-
#if (USERVER_CHAOTIC_GOLDEN_TESTS)
31-
# add_subdirectory(golden_tests)
32-
#endif()
30+
if (USERVER_CHAOTIC_GOLDEN_TESTS)
31+
add_subdirectory(golden_tests)
32+
endif()
3333
endif()
3434

3535
_userver_directory_install(

chaotic/chaotic/cpp_format.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import subprocess
22

3+
SIMPLE_STYLE = '{BasedOnStyle: Google, ColumnLimit: 120}'
4+
35

46
def format_pp(input_: str, *, binary: str) -> str:
57
if not binary:
68
return input_
7-
output = subprocess.check_output([binary], input=input_, encoding='utf-8')
9+
output = subprocess.check_output([binary, '--style', SIMPLE_STYLE], input=input_, encoding='utf-8')
810
return output + '\n'

chaotic/golden_tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ userver_target_generate_chaotic(
2222
add_test(
2323
NAME chaotic-golden
2424
COMMAND "${USERVER_CHAOTIC_PYTEST_PYTHON_BINARY}"
25-
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/diff-clang-format.py
25+
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/diff-clang-format.py"
2626
--golden-dir "${CMAKE_CURRENT_SOURCE_DIR}/output"
2727
--generated-dir "${CMAKE_CURRENT_BINARY_DIR}/src"
2828
)

chaotic/golden_tests/scripts/diff-clang-format.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
import sys
66
import tempfile
77

8+
SIMPLE_STYLE = '{BasedOnStyle: Google, ColumnLimit: 120}'
9+
810

911
def is_binary_available(binary_name: str) -> bool:
1012
try:
11-
subprocess.checked_call(['which', binary_name], stdout=subprocess.DEVNULL)
13+
subprocess.check_call(['which', binary_name], stdout=subprocess.DEVNULL)
1214
return True
1315
except subprocess.CalledProcessError:
1416
return False
@@ -28,7 +30,7 @@ def parse_args():
2830
def walk_xpp(path: str) -> list[str]:
2931
result = []
3032

31-
extensions = {'.hpp', '.cpp', '.ipp'}
33+
extensions = ('.hpp', '.cpp', '.ipp')
3234
for root, _, files in os.walk(path):
3335
for file in files:
3436
if file.lower().endswith(extensions):
@@ -54,7 +56,7 @@ def main():
5456
shutil.copytree(args.golden_dir, golden_copy)
5557
shutil.copytree(args.generated_dir, generated_copy)
5658

57-
subprocess.check_call(['clang-format', '-i'] + walk_xpp(tmpdir))
59+
subprocess.check_call(['clang-format', '--style', SIMPLE_STYLE, '-i'] + walk_xpp(tmpdir))
5860

5961
result = subprocess.run(['diff', '-uNrpB', golden_copy, generated_copy], capture_output=True, text=True)
6062

cmake/ChaoticGen.cmake

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,14 @@ _userver_prepare_chaotic()
5353

5454
# Generates ${TARGET} cmake target for C++ types, parsers, serializers from JSONSchema file(s).
5555
#
56-
# Options: - OUTPUT_DIR - where to put generated .cpp/.hpp/.ipp files, usually ${CMAKE_CURRENT_BINARY_DIR}/smth -
57-
# RELATIVE_TO - --relative-to option to chaotic-gen - FORMAT - can be ON/OFF, enable to format generated files, defaults
58-
# to USERVER_CHAOTIC_FORMAT - SCHEMAS - JSONSchema source files - ARGS - extra args to chaotic-gen -
59-
# INSTALL_INCLUDES_COMPONENT - component to install generated includes
60-
# LINK_TARGETS - targets to link (used by x-usrv-cpp-type)
56+
# Options:
57+
# - OUTPUT_DIR - where to put generated .cpp/.hpp/.ipp files, usually ${CMAKE_CURRENT_BINARY_DIR}/smth
58+
# - RELATIVE_TO - --relative-to option to chaotic-gen
59+
# - FORMAT - can be ON/OFF, enable to format generated files, defaults to USERVER_CHAOTIC_FORMAT
60+
# - SCHEMAS - JSONSchema source files
61+
# - ARGS - extra args to chaotic-gen
62+
# - INSTALL_INCLUDES_COMPONENT - component to install generated includes
63+
# - LINK_TARGETS - targets to link (used by x-usrv-cpp-type)
6164
function(userver_target_generate_chaotic TARGET)
6265
set(OPTIONS GENERATE_SERIALIZERS PARSE_EXTRA_FORMATS)
6366
set(ONE_VALUE_ARGS OUTPUT_DIR RELATIVE_TO FORMAT INSTALL_INCLUDES_COMPONENT OUTPUT_PREFIX ERASE_PATH_PREFIX)
@@ -149,7 +152,7 @@ function(userver_target_generate_chaotic TARGET)
149152
OUTPUT ${SCHEMAS}
150153
COMMAND ${CMAKE_COMMAND} -E env "USERVER_PYTHON=${USERVER_CHAOTIC_PYTHON_BINARY}" "${CHAOTIC_BIN}"
151154
${CHAOTIC_EXTRA_ARGS} ${CHAOTIC_ARGS} ${PARSE_SCHEMAS}
152-
--clang-format "" # "${CLANG_FORMAT}"
155+
--clang-format "${CLANG_FORMAT}"
153156
DEPENDS ${PARSE_SCHEMAS}
154157
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
155158
VERBATIM ${CODEGEN}

0 commit comments

Comments
 (0)