feat: add input validation and stack trace filtering for Timer.sleep

Add type and range checks to Timer.sleep() in both C source and Wren
implementation, aborting with descriptive errors for non-numeric or
negative arguments. Introduce six new test files covering sleep with
fibers, float durations, main fiber, zero milliseconds, negative
values, and non-numeric input. Fix stack trace parsing in test runner
to skip builtin library frames by iterating through error lines until
a main-line match is found.
This commit is contained in:
Bob Nystrom
2015-08-08 14:17:30 +00:00
parent 810da1f0fc
commit 664a166d6c
10 changed files with 95 additions and 5 deletions
+10 -4
View File
@@ -19,7 +19,7 @@ EXPECT_ERROR_PATTERN = re.compile(r'// expect error(?! line)')
EXPECT_ERROR_LINE_PATTERN = re.compile(r'// expect error line (\d+)')
EXPECT_RUNTIME_ERROR_PATTERN = re.compile(r'// expect runtime error: (.+)')
ERROR_PATTERN = re.compile(r'\[.* line (\d+)\] Error')
STACK_TRACE_PATTERN = re.compile(r'\[.* line (\d+)\] in')
STACK_TRACE_PATTERN = re.compile(r'\[main line (\d+)\] in')
STDIN_PATTERN = re.compile(r'// stdin: (.*)')
SKIP_PATTERN = re.compile(r'// skip: (.*)')
NONTEST_PATTERN = re.compile(r'// nontest')
@@ -159,11 +159,17 @@ class Test:
self.runtime_error_message)
self.fail(error_lines[0])
# Make sure the stack trace has the right line.
match = STACK_TRACE_PATTERN.search(error_lines[1])
# Make sure the stack trace has the right line. Skip over any lines that
# come from builtin libraries.
stack_lines = error_lines[1:]
for stack_line in stack_lines:
match = STACK_TRACE_PATTERN.search(stack_line)
if match: break
if not match:
self.fail('Expected stack trace and got:')
self.fail(error_lines[1])
for stack_line in stack_lines:
self.fail(stack_line)
else:
stack_line = int(match.group(1))
if stack_line != self.runtime_error_line: