1
0
forked from Mirror/wren

Run examples as tests. Would have prevented #266

This commit is contained in:
Kyle Marek-Spartz
2015-05-20 10:10:40 -05:00
parent a114f34a2a
commit fc7612c843
2 changed files with 11 additions and 4 deletions

View File

@ -90,8 +90,8 @@ class ReservedWords is SyntaxExample {
} }
// `foreign`, `static` // `foreign`, `static`
foreign static bar // foreign static bar
foreign baz(string) // foreign baz(string)
// (Remove lines above to make this file compile) // (Remove lines above to make this file compile)
} }

View File

@ -65,7 +65,7 @@ def print_line(line=None):
sys.stdout.flush() sys.stdout.flush()
def run_test(path): def run_test(path, example=False):
global passed global passed
global failed global failed
global skipped global skipped
@ -216,7 +216,9 @@ def run_test(path):
for line in out_lines: for line in out_lines:
if sys.version_info < (3, 0): if sys.version_info < (3, 0):
line = line.encode('utf-8') line = line.encode('utf-8')
if expect_index >= len(expect_output): if example:
pass
elif expect_index >= len(expect_output):
fails.append('Got output "{0}" when none was expected.'.format(line)) fails.append('Got output "{0}" when none was expected.'.format(line))
elif expect_output[expect_index][0] != line: elif expect_output[expect_index][0] != line:
fails.append('Expected output "{0}" on line {1} and got "{2}".'. fails.append('Expected output "{0}" on line {1} and got "{2}".'.
@ -242,10 +244,15 @@ def run_test(path):
print(' ' + color.PINK + fail + color.DEFAULT) print(' ' + color.PINK + fail + color.DEFAULT)
print('') print('')
def run_example(path):
return run_test(path, example=True)
for dir in ['core', 'io', 'language', 'limit', 'meta']: for dir in ['core', 'io', 'language', 'limit', 'meta']:
walk(join(WREN_DIR, 'test', dir), run_test) walk(join(WREN_DIR, 'test', dir), run_test)
walk(join(WREN_DIR, 'example'), run_example)
walk(join(WREN_DIR, 'example', 'import-module'), run_example)
print_line() print_line()
if failed == 0: if failed == 0:
print('All ' + color.GREEN + str(passed) + color.DEFAULT + ' tests passed.') print('All ' + color.GREEN + str(passed) + color.DEFAULT + ' tests passed.')