Permalink
Browse files

revamp test system, but still need to correct the .out files

  • Loading branch information...
1 parent a221c6d commit cddc1edd047358aa8d3749ba020573e264350a20 @andrewrk committed Dec 5, 2010
Showing with 291 additions and 29 deletions.
  1. +1 −1 .gitignore
  2. +116 −28 test.py
  3. 0 tests/control_flow/{complex.p.expected → complex.p.errors}
  4. +9 −0 tests/control_flow/complex.p.out
  5. 0 tests/control_flow/{constant_expressions.p.expected → constant_expressions.p.errors}
  6. 0 tests/control_flow/{global_redundancy_elimination.p.expected → constant_expressions.p.out}
  7. 0 tests/control_flow/{if.p.expected → delete_blocks.p.errors}
  8. 0 tests/control_flow/{inline_condition.p.expected → delete_blocks.p.out}
  9. 0 tests/control_flow/{lol_graph.p.expected → global_redundancy_elimination.p.errors}
  10. 0 tests/control_flow/{maths.p.expected → global_redundancy_elimination.p.out}
  11. 0 tests/control_flow/{real.p.expected → if.p.errors}
  12. 0 tests/control_flow/{simple.p.expected → if.p.out}
  13. 0 tests/control_flow/{value_numbering.p.expected → inline_condition.p.errors}
  14. 0 tests/control_flow/{value_numbering2.p.expected → inline_condition.p.out}
  15. 0 tests/control_flow/{value_numbering_extended.p.expected → lol_graph.p.errors}
  16. 0 tests/control_flow/{value_numbering_loops.p.expected → lol_graph.p.out}
  17. 0 tests/control_flow/{while.p.expected → maths.p.errors}
  18. 0 tests/{custom/arg_casting.p.expected → control_flow/maths.p.out}
  19. 0 tests/{custom/deep.p.expected → control_flow/real.p.errors}
  20. 0 tests/{custom/equivalence_parameter.p.expected → control_flow/real.p.out}
  21. 0 tests/{custom/forward_references.p.expected → control_flow/simple.p.errors}
  22. 0 tests/{custom/operators.p.expected → control_flow/simple.p.out}
  23. 0 tests/{formal/test_array_assignment_valid.p.expected → control_flow/sneaky_assignment.p.errors}
  24. 0 tests/{formal/test_array_bounds_valid.p.expected → control_flow/sneaky_assignment.p.out}
  25. 0 tests/{formal/test_array_dim2.p.expected → control_flow/value_numbering.p.errors}
  26. 0 tests/{formal/test_array_dim4.p.expected → control_flow/value_numbering.p.out}
  27. 0 tests/{formal/test_array_multi_bounds_valid.p.expected → control_flow/value_numbering2.p.errors}
  28. 0 tests/{formal/test_attribute_designator_complex.p.expected → control_flow/value_numbering2.p.out}
  29. 0 ...rmal/test_attribute_designator_multi.p.expected → control_flow/value_numbering_extended.p.errors}
  30. 0 ...formal/test_attribute_designator_simple.p.expected → control_flow/value_numbering_extended.p.out}
  31. 0 ...s/{formal/test_boolean_assignment_valid.p.expected → control_flow/value_numbering_loops.p.errors}
  32. 0 ...rmal/test_class_assignment_base_type_valid.p.expected → control_flow/value_numbering_loops.p.out}
  33. 0 tests/{formal/test_class_equivalence_valid.p.expected → control_flow/while.p.errors}
  34. 0 tests/{formal/test_class_preuse_assignment_valid.p.expected → control_flow/while.p.out}
  35. +48 −0 tests/control_flow_formal/Value_num.p
  36. 0 tests/{formal/test_class_preuse_function_valid.p.expected → control_flow_formal/Value_num.p.errors}
  37. 0 tests/{formal/test_class_preuse_valid.p.expected → control_flow_formal/Value_num.p.out}
  38. +73 −0 tests/control_flow_formal/test.p
  39. 0 tests/{formal/test_expression_complex.p.expected → control_flow_formal/test.p.errors}
  40. 0 tests/{formal/test_expression_complex2.p.expected → control_flow_formal/test.p.out}
  41. +44 −0 tests/control_flow_formal/test_gre.p
  42. 0 tests/{formal/test_expression_simple.p.expected → control_flow_formal/test_gre.p.errors}
  43. 0 tests/{formal/test_function_call_arg_array.p.expected → control_flow_formal/test_gre.p.out}
  44. 0 .../{formal/test_function_call_arg_object.p.expected → control_flow_formal/{Value_num.p.errors,test}
  45. 0 tests/{formal/test_function_call_base.p.expected → custom/arg_casting.p.errors}
  46. 0 tests/{formal/test_function_call_class_byref.p.expected → custom/arg_casting.p.out}
  47. 0 tests/custom/{broken_syntax.p.expected → broken_syntax.p.errors}
  48. 0 tests/{formal/test_function_call_class_noargs.p.expected → custom/broken_syntax.p.out}
  49. 0 tests/custom/{crash_compatible.p.expected → crash_compatible.p.errors}
  50. 0 tests/{formal/test_function_call_multi.p.expected → custom/crash_compatible.p.out}
  51. 0 tests/custom/{crash_recursive_struct.p.expected → crash_recursive_struct.p.errors}
  52. 0 tests/{formal/test_function_call_object.p.expected → custom/crash_recursive_struct.p.out}
  53. 0 tests/{formal/test_function_call_object_extend.p.expected → custom/deep.p.errors}
  54. 0 tests/{formal/test_function_list.p.expected → custom/deep.p.out}
  55. 0 tests/custom/{deep_broken.p.expected → deep_broken.p.errors}
  56. 0 tests/{formal/test_function_local_variable_declared.p.expected → custom/deep_broken.p.out}
  57. 0 ...t_function_local_variable_declared_base_class.p.expected → custom/equivalence_parameter.p.errors}
  58. 0 tests/{formal/test_function_local_variable_list.p.expected → custom/equivalence_parameter.p.out}
  59. 0 tests/custom/{equivalence_parameter_invalid.p.expected → equivalence_parameter_invalid.p.errors}
  60. 0 tests/{formal/test_function_return_valid.p.expected → custom/equivalence_parameter_invalid.p.out}
  61. 0 tests/custom/{extend_loop.p.expected → extend_loop.p.errors}
  62. 0 tests/{formal/test_if_then_else.p.expected → custom/extend_loop.p.out}
  63. 0 tests/{formal/test_indexed_variable_complex.p.expected → custom/forward_references.p.errors}
  64. 0 tests/{formal/test_many_nots.p.expected → custom/forward_references.p.out}
  65. 0 tests/custom/{forward_references_broken.p.expected → forward_references_broken.p.errors}
  66. 0 tests/{formal/test_many_signs.p.expected → custom/forward_references_broken.p.out}
  67. 0 tests/custom/{main_construcor_too_many_args.p.expected → main_construcor_too_many_args.p.errors}
  68. 0 ...s/{formal/test_method_designator_complex.p.expected → custom/main_construcor_too_many_args.p.out}
  69. 0 tests/custom/{method_duplication.p.expected → method_duplication.p.errors}
  70. 0 tests/{formal/test_method_designator_complex_this.p.expected → custom/method_duplication.p.out}
  71. 0 tests/custom/{min_syntax.p.expected → min_syntax.p.errors}
  72. 0 tests/{formal/test_object_instantiation.p.expected → custom/min_syntax.p.out}
  73. 0 tests/{formal/test_this_global_variable_valid.p.expected → custom/operators.p.errors}
  74. 0 tests/{formal/test_this_variable_disambiguation.p.expected → custom/operators.p.out}
  75. 0 tests/custom/{same_name_different_class.p.expected → same_name_different_class.p.errors}
  76. 0 ...mal/test_this_variable_disambiguation_extend.p.expected → custom/same_name_different_class.p.out}
  77. 0 tests/custom/{too_many_args.p.expected → too_many_args.p.errors}
  78. 0 tests/{formal/test_valid_class_definition.p.expected → custom/too_many_args.p.out}
  79. 0 tests/custom/{wrong_arg_type.p.expected → wrong_arg_type.p.errors}
  80. 0 tests/{formal/test_variable_declared_global.p.expected → custom/wrong_arg_type.p.out}
  81. 0 tests/formal/{test_array_assignment_invalid.p.expected → test_array_assignment_invalid.p.errors}
  82. 0 tests/formal/{test_variable_declared_global_extend.p.expected → test_array_assignment_invalid.p.out}
  83. 0 tests/formal/{test_while_do.p.expected → test_array_assignment_valid.p.errors}
  84. 0 tests/formal/test_array_assignment_valid.p.out
  85. 0 ...ormal/{test_array_bounds_declare_invalid.p.expected → test_array_bounds_declare_invalid.p.errors}
  86. 0 tests/formal/test_array_bounds_declare_invalid.p.out
  87. 0 tests/formal/{test_array_bounds_invalid.p.expected → test_array_bounds_invalid.p.errors}
  88. 0 tests/formal/test_array_bounds_invalid.p.out
  89. 0 tests/formal/test_array_bounds_valid.p.errors
  90. 0 tests/formal/test_array_bounds_valid.p.out
  91. 0 tests/formal/test_array_dim2.p.errors
  92. 0 tests/formal/test_array_dim2.p.out
  93. 0 tests/formal/test_array_dim4.p.errors
  94. 0 tests/formal/test_array_dim4.p.out
  95. 0 tests/formal/{test_array_index_boolean.p.expected → test_array_index_boolean.p.errors}
  96. 0 tests/formal/test_array_index_boolean.p.out
  97. 0 ...ormal/{test_array_index_boolean_variable.p.expected → test_array_index_boolean_variable.p.errors}
  98. 0 tests/formal/test_array_index_boolean_variable.p.out
  99. 0 tests/formal/{test_array_index_class.p.expected → test_array_index_class.p.errors}
  100. 0 tests/formal/test_array_index_class.p.out
  101. 0 tests/formal/{test_array_multi_bounds_invalid.p.expected → test_array_multi_bounds_invalid.p.errors}
  102. 0 tests/formal/test_array_multi_bounds_invalid.p.out
  103. 0 tests/formal/test_array_multi_bounds_valid.p.errors
  104. 0 tests/formal/test_array_multi_bounds_valid.p.out
  105. 0 tests/formal/test_attribute_designator_complex.p.errors
  106. 0 tests/formal/test_attribute_designator_complex.p.out
  107. 0 tests/formal/test_attribute_designator_multi.p.errors
  108. 0 tests/formal/test_attribute_designator_multi.p.out
  109. 0 ...{test_attribute_designator_multi_this.p.expected → test_attribute_designator_multi_this.p.errors}
  110. 0 tests/formal/test_attribute_designator_multi_this.p.out
  111. 0 tests/formal/test_attribute_designator_simple.p.errors
  112. 0 tests/formal/test_attribute_designator_simple.p.out
  113. 0 tests/formal/{test_boolean_assignment_invalid.p.expected → test_boolean_assignment_invalid.p.errors}
  114. 0 tests/formal/test_boolean_assignment_invalid.p.out
  115. 0 tests/formal/test_boolean_assignment_valid.p.errors
  116. 0 tests/formal/test_boolean_assignment_valid.p.out
  117. 0 ...class_assignment_base_type_invalid.p.expected → test_class_assignment_base_type_invalid.p.errors}
  118. 0 tests/formal/test_class_assignment_base_type_invalid.p.out
  119. 0 tests/formal/test_class_assignment_base_type_valid.p.errors
  120. 0 tests/formal/test_class_assignment_base_type_valid.p.out
  121. 0 ...{test_class_equivalence_invalid_order.p.expected → test_class_equivalence_invalid_order.p.errors}
  122. 0 tests/formal/test_class_equivalence_invalid_order.p.out
  123. 0 ...{test_class_equivalence_invalid_types.p.expected → test_class_equivalence_invalid_types.p.errors}
  124. 0 tests/formal/test_class_equivalence_invalid_types.p.out
  125. 0 tests/formal/test_class_equivalence_valid.p.errors
  126. 0 tests/formal/test_class_equivalence_valid.p.out
  127. 0 tests/formal/test_class_preuse_assignment_valid.p.errors
  128. 0 tests/formal/test_class_preuse_assignment_valid.p.out
  129. 0 tests/formal/test_class_preuse_function_valid.p.errors
  130. 0 tests/formal/test_class_preuse_function_valid.p.out
  131. 0 tests/formal/{test_class_preuse_invalid.p.expected → test_class_preuse_invalid.p.errors}
  132. 0 tests/formal/test_class_preuse_invalid.p.out
  133. 0 tests/formal/test_class_preuse_valid.p.errors
  134. 0 tests/formal/test_class_preuse_valid.p.out
  135. 0 tests/formal/{test_datatype_defined.p.expected → test_datatype_defined.p.errors}
  136. 0 tests/formal/test_datatype_defined.p.out
  137. 0 tests/formal/{test_datatype_not_defined.p.expected → test_datatype_not_defined.p.errors}
  138. 0 tests/formal/test_datatype_not_defined.p.out
  139. 0 tests/formal/test_expression_complex.p.errors
  140. 0 tests/formal/test_expression_complex.p.out
  141. 0 tests/formal/test_expression_complex2.p.errors
  142. 0 tests/formal/test_expression_complex2.p.out
  143. 0 tests/formal/test_expression_simple.p.errors
  144. 0 tests/formal/test_expression_simple.p.out
  145. 0 tests/formal/{test_function_args_few.p.expected → test_function_args_few.p.errors}
  146. 0 tests/formal/test_function_args_few.p.out
  147. 0 tests/formal/test_function_call_arg_array.p.errors
  148. 0 tests/formal/test_function_call_arg_array.p.out
  149. 0 tests/formal/test_function_call_arg_object.p.errors
  150. 0 tests/formal/test_function_call_arg_object.p.out
  151. 0 tests/formal/test_function_call_base.p.errors
  152. 0 tests/formal/test_function_call_base.p.out
  153. 0 tests/formal/{test_function_call_class.p.expected → test_function_call_class.p.errors}
  154. 0 tests/formal/test_function_call_class.p.out
  155. 0 tests/formal/test_function_call_class_byref.p.errors
  156. 0 tests/formal/test_function_call_class_byref.p.out
  157. 0 tests/formal/test_function_call_class_noargs.p.errors
  158. 0 tests/formal/test_function_call_class_noargs.p.out
  159. 0 tests/formal/test_function_call_multi.p.errors
  160. 0 tests/formal/test_function_call_multi.p.out
  161. 0 tests/formal/test_function_call_object.p.errors
  162. 0 tests/formal/test_function_call_object.p.out
  163. 0 tests/formal/test_function_call_object_extend.p.errors
  164. 0 tests/formal/test_function_call_object_extend.p.out
  165. 0 ...ormal/{test_function_call_object_missing.p.expected → test_function_call_object_missing.p.errors}
  166. 0 tests/formal/test_function_call_object_missing.p.out
  167. 0 tests/formal/{test_function_declared.p.expected → test_function_declared.p.errors}
  168. 0 tests/formal/test_function_declared.p.out
  169. 0 tests/formal/test_function_list.p.errors
  170. 0 tests/formal/test_function_list.p.out
  171. 0 tests/formal/test_function_local_variable_declared.p.errors
  172. 0 tests/formal/test_function_local_variable_declared.p.out
  173. 0 tests/formal/test_function_local_variable_declared_base_class.p.errors
  174. 0 tests/formal/test_function_local_variable_declared_base_class.p.out
  175. 0 tests/formal/test_function_local_variable_list.p.errors
  176. 0 tests/formal/test_function_local_variable_list.p.out
  177. 0 ...tion_local_variable_not_declared.p.expected → test_function_local_variable_not_declared.p.errors}
  178. 0 tests/formal/test_function_local_variable_not_declared.p.out
  179. 0 ...ed_other_function.p.expected → test_function_local_variable_not_declared_other_function.p.errors}
  180. 0 tests/formal/test_function_local_variable_not_declared_other_function.p.out
  181. 0 tests/formal/{test_function_not_declared.p.expected → test_function_not_declared.p.errors}
  182. 0 tests/formal/test_function_not_declared.p.out
  183. 0 ...mal/{test_function_not_declared_complex.p.expected → test_function_not_declared_complex.p.errors}
  184. 0 tests/formal/test_function_not_declared_complex.p.out
  185. 0 tests/formal/{test_function_return_invalid.p.expected → test_function_return_invalid.p.errors}
  186. 0 tests/formal/test_function_return_invalid.p.out
  187. 0 ...{test_function_return_invalid_complex.p.expected → test_function_return_invalid_complex.p.errors}
  188. 0 tests/formal/test_function_return_invalid_complex.p.out
  189. 0 tests/formal/test_function_return_valid.p.errors
  190. 0 tests/formal/test_function_return_valid.p.out
  191. 0 tests/formal/{test_function_variable_same.p.expected → test_function_variable_same.p.errors}
  192. 0 tests/formal/test_function_variable_same.p.out
  193. 0 tests/formal/test_if_then_else.p.errors
  194. 0 tests/formal/test_if_then_else.p.out
  195. 0 tests/formal/test_indexed_variable_complex.p.errors
  196. 0 tests/formal/test_indexed_variable_complex.p.out
  197. 0 tests/formal/{test_indexed_variable_not_array.p.expected → test_indexed_variable_not_array.p.errors}
  198. 0 tests/formal/test_indexed_variable_not_array.p.out
  199. 0 ...s_definition_undeclared_vars.p.expected → test_invalid_class_definition_undeclared_vars.p.errors}
  200. 0 tests/formal/test_invalid_class_definition_undeclared_vars.p.out
  201. 0 ...lid_class_definition_underscores.p.expected → test_invalid_class_definition_underscores.p.errors}
  202. 0 tests/formal/test_invalid_class_definition_underscores.p.out
  203. 0 tests/formal/test_many_nots.p.errors
  204. 0 tests/formal/test_many_nots.p.out
  205. 0 tests/formal/test_many_signs.p.errors
  206. 0 tests/formal/test_many_signs.p.out
  207. 0 tests/formal/test_method_designator_complex.p.errors
  208. 0 tests/formal/test_method_designator_complex.p.out
  209. 0 tests/formal/test_method_designator_complex_this.p.errors
  210. 0 tests/formal/test_method_designator_complex_this.p.out
  211. 0 tests/formal/{test_missing_base_class.p.expected → test_missing_base_class.p.errors}
  212. 0 tests/formal/test_missing_base_class.p.out
  213. 0 tests/formal/{test_missing_program_class.p.expected → test_missing_program_class.p.errors}
  214. 0 tests/formal/test_missing_program_class.p.out
  215. 0 tests/formal/test_object_instantiation.p.errors
  216. 0 tests/formal/test_object_instantiation.p.out
  217. 0 ...ormal/{test_this_global_variable_invalid.p.expected → test_this_global_variable_invalid.p.errors}
  218. 0 tests/formal/test_this_global_variable_invalid.p.out
  219. 0 tests/formal/test_this_global_variable_valid.p.errors
  220. 0 tests/formal/test_this_global_variable_valid.p.out
  221. 0 tests/formal/test_this_variable_disambiguation.p.errors
  222. 0 tests/formal/test_this_variable_disambiguation.p.out
  223. 0 tests/formal/test_this_variable_disambiguation_extend.p.errors
  224. 0 tests/formal/test_this_variable_disambiguation_extend.p.out
  225. 0 tests/formal/{test_this_variable_not_declared.p.expected → test_this_variable_not_declared.p.errors}
  226. 0 tests/formal/test_this_variable_not_declared.p.out
  227. 0 .../formal/{test_type_mismatch_array_integer.p.expected → test_type_mismatch_array_integer.p.errors}
  228. 0 tests/formal/test_type_mismatch_array_integer.p.out
  229. 0 tests/formal/{test_type_mismatch_integer.p.expected → test_type_mismatch_integer.p.errors}
  230. 0 tests/formal/test_type_mismatch_integer.p.out
  231. 0 tests/formal/test_valid_class_definition.p.errors
  232. 0 tests/formal/test_valid_class_definition.p.out
  233. 0 tests/formal/{test_variable_declared.p.expected → test_variable_declared.p.errors}
  234. 0 tests/formal/test_variable_declared.p.out
  235. 0 ...ormal/{test_variable_declared_base_class.p.expected → test_variable_declared_base_class.p.errors}
  236. 0 tests/formal/test_variable_declared_base_class.p.out
  237. 0 tests/formal/test_variable_declared_global.p.errors
  238. 0 tests/formal/test_variable_declared_global.p.out
  239. 0 tests/formal/test_variable_declared_global_extend.p.errors
  240. 0 tests/formal/test_variable_declared_global_extend.p.out
  241. 0 tests/formal/{test_variable_invalid_name_tf.p.expected → test_variable_invalid_name_tf.p.errors}
  242. 0 tests/formal/test_variable_invalid_name_tf.p.out
  243. 0 tests/formal/{test_variable_not_declared.p.expected → test_variable_not_declared.p.errors}
  244. 0 tests/formal/test_variable_not_declared.p.out
  245. 0 ...mal/{test_variable_not_declared_complex.p.expected → test_variable_not_declared_complex.p.errors}
  246. 0 tests/formal/test_variable_not_declared_complex.p.out
  247. 0 tests/formal/test_while_do.p.errors
  248. 0 tests/formal/test_while_do.p.out
  249. 0 tests/generation/functions.p.errors
  250. 0 tests/generation/functions.p.out
  251. 0 tests/generation/simple.p.errors
  252. 0 tests/generation/simple.p.out
  253. 0 tests/generation/test_array_local.p.errors
  254. 0 tests/generation/test_array_local.p.out
  255. 0 tests/generation/test_function_call_multi.p.errors
  256. 0 tests/generation/test_function_call_multi.p.out
View
@@ -1,4 +1,4 @@
.git
output
opc
-cse440p1.creator.user
+cse440p1.creator.user*
View
144 test.py
@@ -3,6 +3,41 @@
import os, sys
import subprocess
import optparse
+import tempfile
+
+def which(executable, path=None):
+ """Try to find 'executable' in the directories listed in 'path' (a
+ string listing directories separated by 'os.pathsep'; defaults to
+ os.environ['PATH']). Returns the complete filename or None if not
+ found
+ """
+ if path is None:
+ path = os.environ['PATH']
+ paths = path.split(os.pathsep)
+ extlist = ['']
+ if os.name == 'os2':
+ (base, ext) = os.path.splitext(executable)
+ # executable files on OS/2 can have an arbitrary extension, but
+ # .exe is automatically appended if no dot is present in the name
+ if not ext:
+ executable = executable + ".exe"
+ elif sys.platform == 'win32':
+ pathext = os.environ['PATHEXT'].lower().split(os.pathsep)
+ (base, ext) = os.path.splitext(executable)
+ if ext.lower() not in pathext:
+ extlist = pathext
+ for ext in extlist:
+ execname = executable + ext
+ if os.path.isfile(execname):
+ return execname
+ else:
+ for p in paths:
+ f = os.path.join(p, execname)
+ if os.path.isfile(f):
+ return f
+ else:
+ return None
+
def superwalk(folder):
for dirpath, _dirnames, filenames in os.walk(folder):
@@ -12,6 +47,25 @@ def superwalk(folder):
def absolute(relative_path):
return os.path.abspath(os.path.join(os.path.dirname(__file__), relative_path))
+def execute_spim_code(asm_code):
+ "execute asm_code and return stdout"
+ exe = which('spim')
+
+ # save asm_code to a file
+ handle = tempfile.NamedTemporaryFile(suffix=".asm", delete=False)
+ handle.write(asm_code)
+ handle.close()
+ spim = subprocess.Popen([exe, '-file', handle.name], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ stdout, stderr = spim.communicate()
+ try:
+ os.remove(handle.name)
+ except:
+ pass
+
+ # chop off the 5 useless lines
+ clean_out = "\n".join(stdout.split('\n')[5:])
+
+ return clean_out
def main():
parser = optparse.OptionParser()
@@ -27,26 +81,33 @@ def main():
for f in superwalk("tests/"):
if f.find("/_") != -1:
continue
- if f.endswith('.p.expected'):
- test_name = f[:-len('.p.expected')]
- ext = '.p.expected'
+ if f.endswith('.p.errors'):
+ test_name = f[:-len('.p.errors')]
+ ext = '.p.errors'
elif f.endswith('.p'):
test_name = f[:-len('.p')]
ext = '.p'
+ elif f.endswith('.p.out'):
+ test_name = f[:-len('.p.out')]
+ ext = '.p.out'
else:
continue
if not tests.has_key(test_name):
tests[test_name] = {}
- if ext == '.p.expected':
+ if ext == '.p.errors':
+ compiler_output = open(absolute(f), 'r').read()
+ tests[test_name]['errors'] = compiler_output.replace('Errors detected. Exiting.\n', '')
+ elif ext == '.p.out':
expected_output = open(absolute(f), 'r').read()
- tests[test_name]['expected'] = expected_output.replace('Errors detected. Exiting.\n', '')
- else:
+ tests[test_name]['out'] = expected_output
+ else: # ext == '.p'
tests[test_name]['source'] = open(absolute(f), 'r').read()
fails = []
compiler_exe = absolute('opc')
+ interpret_command = execute_spim_code
passed = 0
test_list = sorted(tests.iteritems())
if options.backwards:
@@ -55,59 +116,86 @@ def main():
if not test.has_key('source'):
print("%s missing source" % test_name)
continue
- if not test.has_key('expected'):
- print("%s missing expected value" % test_name)
+ if not test.has_key('errors'):
+ print("%s missing .errors file for expected compiler output" % test_name)
+ continue
+ if not test.has_key('out'):
+ print("%s missing .out file for what the program should output" % test_name)
continue
+ # try compiling the test file
compiler = subprocess.Popen([compiler_exe], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = compiler.communicate(test['source'])
if compiler.returncode not in [0, 1]:
sys.stdout.write('E')
fails.append({
- 'expected': test['expected'],
+ 'errors': test['errors'],
'output': stderr,
'stdout': stdout,
'name': test_name,
'crash': True,
})
- if stderr == test['expected']:
- sys.stdout.write('.')
- passed += 1
- else:
+ if options.failfast:
+ break
+ elif stderr != test['errors']:
sys.stdout.write('F')
fails.append({
- 'expected': test['expected'],
+ 'errors': test['errors'],
'output': stderr,
'stdout': stdout,
'name': test_name,
'crash': False,
})
if options.failfast:
break
- sys.stdout.flush()
-
+ else:
+ # compiler output correct, now test the generated code output
+ asm_output = interpret_command(stdout)
+ if asm_output != test['out']:
+ sys.stdout.write('W')
+ fails.append({
+ 'expected_runout': test['out'],
+ 'runout': asm_output,
+ 'name': test_name,
+ 'crash': False,
+ })
+ if options.failfast:
+ break
+ else:
+ sys.stdout.write('.')
+ passed += 1
+ sys.stdout.flush()
if len(fails) > 0:
if not options.quiet:
print("\n=========================================")
for fail in fails:
- print("""Test name: %(name)s
----- Output: ----
-%(output)s
----- Expected output: ----
-%(expected)s
+ print("Test name: %(name)s" % fail)
+ if 'expected_runout' in fail:
+ print("""\
+---- Program Output: ----
+%(runout)s\
+---- Expected Program Output: ----
+%(expected_runout)s\
+--------""" % fail)
+ else:
+ print("""\
+---- Compiler Output: ----
+%(output)s\
+---- Expected Compiler output: ----
+%(errors)s\
--------""" % fail)
- if fail['crash']:
- print("The program crashed.")
- if fail['stdout'].strip() != '':
- print("---- stdout ----")
- print(fail['stdout'])
- print("----------------")
+ if fail['crash']:
+ print("The program crashed.")
+ if fail['stdout'].strip() != '':
+ print("---- Compiler stdout ----")
+ print(fail['stdout'])
+ print("----------------")
print("=========================================")
print("\n%i tests passed, %i tests failed." % (passed, len(fails)))
else:
- print("\nAll %i tests passed." % len(tests))
+ print("\nAll %i tests passed." % passed)
if __name__ == "__main__":
main()
@@ -0,0 +1,9 @@
+1
+2
+3
+4
+5
+6
+7
+8
+9
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,48 @@
+program testIfThenElseNested;
+
+class testIfThenElseNested
+
+BEGIN
+FUNCTION testIfThenElseNested;
+
+ VAR aa, bb, cc, dd, ee, ff, xx, yy, zz, c1, c2, c3, c4, c5, c6, ww: integer;
+
+BEGIN
+ aa := 3;
+ cc := 23;
+ dd := ee + ff;
+
+ IF aa = 0 THEN
+ bb := 1
+ ELSE
+ BEGIN
+ bb := 0;
+ xx := aa + aa + cc + cc;
+ zz := cc+cc;
+ ww := aa+aa;
+ IF cc = 7 THEN
+
+
+ aa := aa
+ ELSE
+ BEGIN
+ bb := 5;
+ bb := aa + aa + cc
+ END;
+ yy := aa + cc;
+ cc := 4
+ END;
+ zz := ee + ff;
+ cc := ee + ee;
+ c1 := ee + 0;
+ c2 := ee - 0;
+ c3 := ee * 1;
+ c4 := ee * 0;
+ c5 := ee / 1;
+ c6 := 2 * ee
+
+END
+
+END
+.
+
@@ -0,0 +1,73 @@
+program FirstClass;
+
+class FirstClass
+
+BEGIN
+
+ FUNCTION FirstClass;
+
+ VAR a1, b1, c1, d1, aa, ff, gg, kk, ll, mm, cc, bb, a4, a2, a3 : integer;
+x1, x2, x3, x4, x5, x6, x7, x8, x9, x0, th: boolean;
+ BEGIN
+ aa := bb+cc;
+ ff := aa;
+ gg := ff;
+ kk := bb+cc;
+ ll := 1+bb;
+ aa := 1;
+ mm := aa+bb;
+ th := a1 <= b1 * (a1 * (a1 * a2) * (a2 * a3 * a4));
+ a1 := 1 - 2 + 5 * 10;
+ a2 := 4 - 2;
+ b1 := a1;
+ x1 := true;
+ x2 := false;
+ x3 := NOT x1;
+ x4 := NOT x3;
+ x5 := 1 > 2;
+ x6 := 2 > 1;
+ x7 := a2 < a1;
+ x8 := a2 > a1;
+ x9 := x7 AND x8;
+ x0 := x7 OR x8;
+ c1 := a1 + b1 + a2 + a1;
+ WHILE c1 <= (a1 + 5) DO
+ BEGIN
+ a1 := 1;
+ b1 := 2;
+ c1 := 3
+ END;
+ a1 := 69;
+ b1 := 1;
+ c1 := a1 + b1 + c1 + a1;
+ c1 := a1 * (b1 + c1 + a1);
+ c1 := 2;
+ IF c1 <= 5 * b1 THEN
+ BEGIN
+ c1 := a1 + b1;
+ IF c1 <=0 THEN
+ BEGIN
+ c1 := 1;
+ c1 := a1;
+ c1 := 1
+ END
+ ELSE
+ BEGIN
+ c1 := b1;
+ c1 := 0;
+ c1 := 0
+ END;
+ c1 := 1;
+ c1 := 1
+ END
+ ELSE
+ BEGIN
+ c1 := a1 + b1;
+ c1 := 0;
+ c1 := 0
+ END;
+ c1 := 1;
+ c1 := 1
+ END
+END
+.
Oops, something went wrong.

0 comments on commit cddc1ed

Please sign in to comment.