Fix: strip TEST_BEGIN..TEST_END blocks from Javelin .cc files entirely
This commit is contained in:
parent
3470bfb18e
commit
f70037b728
1 changed files with 14 additions and 25 deletions
|
|
@ -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}'
|
||||||
|
pattern = re.compile(r'(?:^|\\n)(TEST_BEGIN\\(.*?TEST_END)', re.DOTALL)
|
||||||
|
count = 0
|
||||||
|
for f in glob.glob(os.path.join(src, '**/*.cc'), recursive=True):
|
||||||
t = open(f).read()
|
t = open(f).read()
|
||||||
old = '''#define TEST_BEGIN__(text, file, line) \\\\
|
t2 = pattern.sub('', t)
|
||||||
namespace UnitTest##line { \\\\
|
if t2 != t:
|
||||||
static void Test() {
|
open(f, 'w').write(t2)
|
||||||
|
count += 1
|
||||||
#define TEST_END \\\\
|
print(f'Stripped test blocks from {count} files')
|
||||||
} \\\\
|
|
||||||
}'''
|
|
||||||
new = '''#define TEST_BEGIN__(text, file, line) \\\\
|
|
||||||
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")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue