forked from emojicode/emojicode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
executable file
·159 lines (138 loc) · 4.11 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
from subprocess import *
import glob
import os
import dist
import sys
import re
compilation_tests = [
"hello",
"intTest",
"if",
"vars",
"namespace",
"enum",
"enumMethod",
"enumTypeMethod",
"unwrap",
"assignmentByCall",
"repeatWhile",
"conditionalProduce",
"stringConcat",
"babyBottleInitializer",
"classInheritance",
"classOverride",
"classSuper",
"classSubInstanceVar",
"extension",
"piglatin",
"class",
"assignmentByCallInstanceVariable",
"valueType",
"valueTypeSelf",
"valueTypeMutate",
"isNothingness",
"downcastClass",
"castAny",
"castGenericValueType",
"protocolClass",
"protocolSubclass",
"protocolValueType",
"protocolValueTypeRemote",
"protocolEnum",
"protocolGenericLayerClass",
"protocolGenericLayerValueType",
"protocolMulti",
"assignmentByCallProtocol",
"commonType",
"typeAlias",
"generics",
"genericsValueType",
"genericProtocol",
"genericProtocolValueType",
"variableInitAndScoping",
"valueTypeRemoteAdditional",
"closureBasic",
"closureCapture",
"closureCaptureThis",
"closureCaptureValueType",
"captureMethod",
"captureTypeMethod",
"errorIsError",
"errorPerfect",
"errorAvocado",
"errorInitializer",
# "gcStressTest1",
# "gcStressTest2",
# "gcStressTest3",
# "gcStressTest4",
"valueTypeCopySelf",
"valueTypeBoxCopySelf",
"includer",
# "threads",
]
library_tests = [
"stringTest", "primitives", "mathTest", "dataTest", "systemTest",
"listTest", "enumerator", "rangeTest", "dictionaryTest",
# "jsonTest", "fileTest"
]
reject_tests = glob.glob(os.path.join(dist.source, "tests", "reject",
"*.emojic"))
failed_tests = []
emojicode = os.path.abspath("emojicode")
emojicodec = os.path.abspath("emojicodec")
os.environ["EMOJICODE_PACKAGES_PATH"] = os.path.join(dist.path, "packages")
def fail_test(name):
global failed_tests
print("🛑 {0} failed".format(name))
failed_tests.append(name)
def test_paths(name, kind):
return (os.path.join(dist.source, "tests", kind, name + ".emojic"),
os.path.join(dist.source, "tests", kind, name + ".emojib"))
def library_test(name):
source_path, binary_path = test_paths(name, 's')
run([emojicodec, source_path], check=True)
completed = run([emojicode, binary_path], stdout=PIPE)
if completed.returncode != 0:
fail_test(name)
print(completed.stdout.decode('utf-8'))
def compilation_test(name):
source_path, binary_path = test_paths(name, 'compilation')
run([emojicodec, source_path], check=True)
completed = run([emojicode, binary_path], stdout=PIPE)
exp_path = os.path.join(dist.source, "tests", "compilation", name + ".txt")
output = completed.stdout.decode('utf-8')
if output != open(exp_path, "r", encoding='utf-8').read():
print(output)
fail_test(name)
def reject_test(filename):
completed = run([emojicodec, filename], stderr=PIPE)
output = completed.stderr.decode('utf-8')
if completed.returncode == 0 or len(re.findall(r"(^|\n)🚨", output)) != 1:
print(output)
fail_test(filename)
def prettyprint_test(name):
source_path = test_paths(name, 'compilation')[0]
run([emojicodec, '-f', source_path], check=True)
try:
compilation_test(name)
except CalledProcessError:
pass
os.rename(source_path + '_original', source_path)
for test in compilation_tests:
compilation_test(test)
for test in compilation_tests:
prettyprint_test(test)
included = os.path.join(dist.source, "tests", "compilation", "included.emojic")
os.rename(included + '_original', included)
# for test in reject_tests:
# reject_test(test)
os.chdir(os.path.join(dist.source, "tests", "s"))
for test in library_tests:
library_test(test)
if len(failed_tests) == 0:
print("✅ ✅ All tests passed.")
sys.exit(0)
else:
print("🛑 🛑 {0} tests failed: {1}".format(len(failed_tests),
", ".join(failed_tests)))
sys.exit(1)