I don't like fixtures, but this lets us ditch unbundle-modules.py.
--HG--
branch : no_improper_lists
catseye
13 years ago
294 | 294 | * Informally test tail-recursive behavior (does an infinite loop |
295 | 295 | leak memory?) |
296 | 296 | |
297 | * Find another way (one that works on Windows) to do what | |
298 | `unbundle-modules.py` currently does. | |
299 | ||
300 | 297 | * Improve Falderal to let tests take some text as input; use this for the |
301 | 298 | tests for `crude-input`. |
302 | 299 |
0 | #!/usr/bin/env python | |
1 | ||
2 | import os | |
3 | import sys | |
4 | import re | |
5 | ||
6 | module = None | |
7 | major = None | |
8 | minor = None | |
9 | filename = None | |
10 | ||
11 | stuff = {} | |
12 | ||
13 | if __name__ == '__main__': | |
14 | f = open(sys.argv[1], 'r') | |
15 | for line in f: | |
16 | match = re.match(r'^\-*\s*module\s*(\w+)\s*(\d+)\s*\.?\s*(\d+)\s*$', line) | |
17 | if match: | |
18 | module = match.group(1) | |
19 | major = match.group(2) | |
20 | minor = match.group(3) | |
21 | filename = "module/%s_%s_%s.robin" % (module, major, minor) | |
22 | stuff[filename] = [] | |
23 | continue | |
24 | match = re.match(r'^\-*\s*main\s*$', line) | |
25 | if match: | |
26 | filename = "unbundled.robin" | |
27 | stuff[filename] = [] | |
28 | continue | |
29 | stuff[filename].append(line) | |
30 | f.close() | |
31 | ||
32 | for filename in stuff.keys(): | |
33 | f = open(filename, 'w') | |
34 | for line in stuff[filename]: | |
35 | f.write(line) | |
36 | f.close() | |
37 | ||
38 | exitcode = (os.system("bin/robin unbundled.robin") / 256) | |
39 | ||
40 | for filename in stuff.keys(): | |
41 | os.unlink(filename) | |
42 | ||
43 | sys.exit(exitcode) |
2 | 2 | Miscellanous Module Tests |
3 | 3 | ========================= |
4 | 4 | |
5 | -> Functionality "Interpret Bundled Robin Program" is implemented by | |
6 | -> shell command "bin/unbundle_modules.py %(test-file)" | |
7 | ||
8 | -> Tests for functionality "Interpret Bundled Robin Program" | |
5 | -> Tests for functionality "Interpret Robin Program" | |
9 | 6 | |
10 | 7 | This document contains miscellaneous tests for module functionality; |
11 | 8 | tests that require multiple modules be loaded, and so forth. |
13 | 10 | Modules are cached, so that a module referenced by two other modules |
14 | 11 | is not loaded twice. |
15 | 12 | |
16 | | ----- module a 0.1 | |
17 | | (robin (0 1) ((small (0 1) *) (random (0 1) *)) | |
18 | | (pair (pair (literal random-a) random) ())) | |
19 | | ----- module b 0.1 | |
20 | | (robin (0 1) ((small (0 1) *) (random (0 1) *)) | |
21 | | (pair (pair (literal random-b) random) ())) | |
22 | | ----- main | |
23 | | (robin (0 1) ((core (0 1) *) (a (0 1) *) (b (0 1) *)) | |
13 | | (robin (0 1) ((core (0 1) *) (random-a (0 1) *) (random-b (0 1) *)) | |
24 | 14 | | (equal? random-a random-b)) |
25 | 15 | = #t |
26 | 16 | |
27 | 17 | Circular module imports produce an error rather than going into an infinite |
28 | 18 | loop. |
29 | 19 | |
30 | | ----- module a 0.1 | |
31 | | (robin (0 1) ((small (0 1) *) (b (0 1) *)) | |
32 | | (pair (pair (literal literal-a) literal-b) ())) | |
33 | | ----- module b 0.1 | |
34 | | (robin (0 1) ((small (0 1) *) (a (0 1) *)) | |
35 | | (pair (pair (literal literal-b) literal-a) ())) | |
36 | | ----- main | |
37 | | (robin (0 1) ((core (0 1) *) (a (0 1) *)) | |
20 | | (robin (0 1) ((core (0 1) *) (circular-a (0 1) *)) | |
38 | 21 | | (equal? literal-a literal-b)) |
39 | ? robin: circular reference in module a | |
40 | ||
41 | -> Functionality "Interpret Robin Program" is implemented by | |
42 | -> shell command "bin/robin %(test-file)" | |
43 | ||
44 | -> Tests for functionality "Interpret Robin Program" | |
22 | ? robin: circular reference in module circular-a | |
45 | 23 | |
46 | 24 | `and` is short-circuiting. |
47 | 25 |
0 | (robin (0 1) ((small (0 1) *) (circular-b (0 1) *)) | |
1 | (pair (pair (literal literal-a) (pair literal-b ())) ())) |
0 | (robin (0 1) ((small (0 1) *) (circular-a (0 1) *)) | |
1 | (pair (pair (literal literal-b) (pair literal-a ())) ())) |
0 | (robin (0 1) ((small (0 1) *) (random (0 1) *)) | |
1 | (pair (pair (literal random-a) (pair random ())) ())) |
0 | (robin (0 1) ((small (0 1) *) (random (0 1) *)) | |
1 | (pair (pair (literal random-b) (pair random ())) ())) |
24 | 24 | if [ -e bin/robin.exe ]; then |
25 | 25 | falderal test -b \ |
26 | 26 | -c "Interpret Robin Program" \ |
27 | -c "Interpret Bundled Robin Program" \ | |
28 | 27 | -c "Interpret Robin Program without output" \ |
29 | -f 'Interpret Robin Program:shell command "bin\\robin.exe -m module %(test-file)"' \ | |
30 | -f 'Interpret Bundled Robin Program:shell command "c:\\Python27\\python.exe bin\\unbundle_modules.py %(test-file)"' \ | |
28 | -f 'Interpret Robin Program:shell command "bin\\robin.exe -m module -m fixture\\module %(test-file)"' \ | |
31 | 29 | -f 'Interpret Robin Program without output:shell command "bin\\robin.exe -m module -n %(test-file)"' \ |
32 | 30 | ${FILES} |
33 | 31 | rm -f results* |
34 | 32 | else |
35 | 33 | falderal test -b \ |
36 | -f 'Interpret Robin Program:shell command "bin/robin %(test-file)"' \ | |
34 | -c "Interpret Robin Program" \ | |
35 | -f 'Interpret Robin Program:shell command "bin/robin -m module -m fixture/module %(test-file)"' \ | |
37 | 36 | ${FILES} |
38 | 37 | fi |
39 |