Fix: strip TEST_BEGIN..TEST_END blocks from Javelin .cc files entirely

This commit is contained in:
afiqzudinhadi 2026-06-22 23:26:43 +08:00
parent 3470bfb18e
commit f70037b728

View file

@ -12,33 +12,22 @@ if(CONFIG_ZMK_JAVELIN_STENO)
COMMAND sed -i "s/constexpr StenoUserDictionaryData(const uint8_t/StenoUserDictionaryData(const uint8_t/" COMMAND sed -i "s/constexpr StenoUserDictionaryData(const uint8_t/StenoUserDictionaryData(const uint8_t/"
"${JAVELIN_SRC_DIR}/dictionary/user_dictionary.h" "${JAVELIN_SRC_DIR}/dictionary/user_dictionary.h"
) )
# Replace unit_test.h #else block to wrap test bodies in # Strip all test bodies from Javelin .cc files.
# if constexpr(false) — prevents compilation of test code that # TEST_BEGIN...TEST_END blocks contain code referencing
# references RUN_TESTS-only APIs like Pattern::HasEndAnchor # RUN_TESTS-only APIs. Remove them entirely.
execute_process( execute_process(
COMMAND python3 -c " COMMAND python3 -c "
import re import glob, re, os
f = '${JAVELIN_SRC_DIR}/unit_test.h' src = '${JAVELIN_SRC_DIR}'
t = open(f).read() pattern = re.compile(r'(?:^|\\n)(TEST_BEGIN\\(.*?TEST_END)', re.DOTALL)
old = '''#define TEST_BEGIN__(text, file, line) \\\\ count = 0
namespace UnitTest##line { \\\\ for f in glob.glob(os.path.join(src, '**/*.cc'), recursive=True):
static void Test() { t = open(f).read()
t2 = pattern.sub('', t)
#define TEST_END \\\\ if t2 != t:
} \\\\ open(f, 'w').write(t2)
}''' count += 1
new = '''#define TEST_BEGIN__(text, file, line) \\\\ print(f'Stripped test blocks from {count} files')
namespace UnitTest##line { \\\\
static void Test() { if constexpr(false) {
#define TEST_END \\\\
} } \\\\
}'''
if old in t:
open(f,'w').write(t.replace(old, new))
print('unit_test.h patched')
else:
print('unit_test.h: pattern not found')
" "
) )
message(STATUS "Javelin steno: source patches applied") message(STATUS "Javelin steno: source patches applied")