|
1 | | -#! /usr/bin/env python3 |
| 1 | +#!/usr/bin/env python3 |
2 | 2 |
|
3 | 3 | import os, sys |
4 | 4 | from glob import glob |
5 | 5 | from re import sub |
6 | 6 |
|
7 | 7 | def escape(s): |
8 | | - lookup = { |
9 | | - '\0': '\\0', |
10 | | - '\t': '\\t', |
11 | | - '\n': '\\n\"\n\"', |
12 | | - '\r': '\\r', |
13 | | - '\\': '\\\\', |
14 | | - '\"': '\\\"', |
15 | | - } |
16 | | - return "\"\"\n\"{}\"".format(''.join([lookup[x] if x in lookup else x for x in s])) |
| 8 | + s = s.decode() |
| 9 | + lookup = { |
| 10 | + '\0': '\\0', |
| 11 | + '\t': '\\t', |
| 12 | + '\n': '\\n\"\n\"', |
| 13 | + '\r': '\\r', |
| 14 | + '\\': '\\\\', |
| 15 | + '\"': '\\\"', |
| 16 | + } |
| 17 | + return "\"\"\n\"{}\"".format(''.join([lookup[x] if x in lookup else x for x in s])) |
17 | 18 |
|
18 | 19 | def chew_filename(t): |
19 | | - return { 'func': "test_{}_fn".format(sub(r'/|\.|-', '_', t)), 'desc': t.split('/')[1] } |
| 20 | + return { 'func': "test_{}_fn".format(sub(r'/|\.|-', '_', t)), 'desc': t.split('/')[1] } |
20 | 21 |
|
21 | | -def script_to_map(t): |
22 | | - r = { 'name': chew_filename(t)['func'] } |
23 | | - with open(t) as f: r['script'] = escape(''.join(f.readlines())) |
24 | | - return r |
| 22 | +def script_to_map(test_file): |
| 23 | + r = {"name": chew_filename(test_file)["func"]} |
| 24 | + with open(test_file, "rb") as f: |
| 25 | + r["script"] = escape(f.read()) |
| 26 | + with open(test_file + ".exp", "rb") as f: |
| 27 | + r["output"] = escape(f.read()) |
| 28 | + return r |
25 | 29 |
|
26 | 30 | test_function = ( |
27 | 31 | "void {name}(void* data) {{\n" |
28 | | - " const char * pystr = {script};\n" |
29 | | - " do_str(pystr);\n" |
| 32 | + " static const char pystr[] = {script};\n" |
| 33 | + " static const char exp[] = {output};\n" |
| 34 | + " upytest_set_expected_output(exp, sizeof(exp) - 1);\n" |
| 35 | + " upytest_execute_test(pystr);\n" |
30 | 36 | "}}" |
31 | 37 | ) |
32 | 38 |
|
@@ -57,10 +63,10 @@ def script_to_map(t): |
57 | 63 | output = [] |
58 | 64 |
|
59 | 65 | for group in test_dirs: |
60 | | - tests = [test for test in glob('{}/*.py'.format(group)) if test not in exclude_tests] |
61 | | - output.extend([test_function.format(**script_to_map(test)) for test in tests]) |
62 | | - testcase_members = [testcase_member.format(**chew_filename(test)) for test in tests] |
63 | | - output.append(testcase_struct.format(name=group, body='\n'.join(testcase_members))) |
| 66 | + tests = [test for test in glob('{}/*.py'.format(group)) if test not in exclude_tests] |
| 67 | + output.extend([test_function.format(**script_to_map(test)) for test in tests]) |
| 68 | + testcase_members = [testcase_member.format(**chew_filename(test)) for test in tests] |
| 69 | + output.append(testcase_struct.format(name=group, body='\n'.join(testcase_members))) |
64 | 70 |
|
65 | 71 | testgroup_members = [testgroup_member.format(name=group) for group in test_dirs] |
66 | 72 |
|
|
0 commit comments