Skip to content

Commit 2560577

Browse files
committed
CI: Fix state count validation regex
When run under some system locales or Java versions, TLC will output the state count info with comma separators, like "1,000" instead of "1000". Before these changes, the Python regex used to extract & parse these values did not handle these comma separators. Now, it does. This was done by setting the Python locale to en_US.UTF-8 then using the locale.atoi() API. Signed-off-by: Andrew Helwer <ahelwer@pm.me>
1 parent 1408f6c commit 2560577

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

.github/scripts/tla_utils.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import locale
12
from datetime import datetime
23
import json
34
from os.path import join, normpath, pathsep
@@ -223,19 +224,20 @@ def is_state_count_info_correct(model, distinct_states, total_states, state_dept
223224
# State depth not yet deterministic due to TLC bug: https://github.com/tlaplus/tlaplus/issues/883
224225
return none_or_equal(expected_distinct_states, distinct_states) and none_or_equal(expected_total_states, total_states) #and none_or_equal(expected_state_depth, state_depth)
225226

226-
state_count_regex = re.compile(r'(?P<total_states>\d+) states generated, (?P<distinct_states>\d+) distinct states found, 0 states left on queue.')
227-
state_depth_regex = re.compile(r'The depth of the complete state graph search is (?P<state_depth>\d+).')
227+
state_count_regex = re.compile(r'(?P<total_states>[\d,]+) states generated, (?P<distinct_states>[\d,]+) distinct states found, 0 states left on queue.')
228+
state_depth_regex = re.compile(r'The depth of the complete state graph search is (?P<state_depth>[\d,]+).')
228229

229230
def extract_state_count_info(tlc_output):
230231
"""
231232
Parse & extract state count info from TLC output.
232233
"""
234+
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
233235
state_count_findings = state_count_regex.search(tlc_output)
234236
state_depth_findings = state_depth_regex.search(tlc_output)
235237
if state_count_findings is None or state_depth_findings is None:
236238
return None
237-
distinct_states = int(state_count_findings.group('distinct_states'))
238-
total_states = int(state_count_findings.group('total_states'))
239-
state_depth = int(state_depth_findings.group('state_depth'))
239+
distinct_states = locale.atoi(state_count_findings.group('distinct_states'))
240+
total_states = locale.atoi(state_count_findings.group('total_states'))
241+
state_depth = locale.atoi(state_depth_findings.group('state_depth'))
240242
return (distinct_states, total_states, state_depth)
241243

0 commit comments

Comments
 (0)