# two test executable
add_library(asebavmdummycallbacks STATIC
	asebavmdummycallbacks.cpp
)

# If the asebavm is built as a shared lib, it must not be a dependency of
# asebavmdummycallbacks because if it is, it will not be able to resolve refs
# using asebavmdummycallbacks. On the other hand, if asabavm is not built as a
# shared lib, it must be a dependency so that it can be used to resolve refs 
# in asebavmdummycallbacks.
if (BUILD_SHARED_LIBS)
	target_link_libraries(asebavmdummycallbacks ${ASEBA_CORE_LIBRARIES})
else (BUILD_SHARED_LIBS)
	target_link_libraries(asebavmdummycallbacks asebavm ${ASEBA_CORE_LIBRARIES})
endif (BUILD_SHARED_LIBS)

add_executable(asebatest
	asebatest.cpp
)
target_link_libraries(asebatest asebacompiler asebavm asebavmdummycallbacks ${ASEBA_CORE_LIBRARIES})

# the following tests should succeed
add_test(basic-arithmetic ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/basic-arithmetic.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/basic-arithmetic.txt)
add_test(basic-arithmetic-vector ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/basic-arithmetic-vector.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/basic-arithmetic-vector.txt)
add_test(advanced-arithmetic ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/advanced-arithmetic.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/advanced-arithmetic.txt)
add_test(advanced-arithmetic-vector ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/advanced-arithmetic-vector.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/advanced-arithmetic-vector.txt)
add_test(binary-op ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/binary-op.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/binary-op.txt)
add_test(shift-op ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/shift-op.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/shift-op.txt)
add_test(compound-assignment ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/compound-assignments.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/compound-assignments.txt)
add_test(compound-assignment-vector ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/compound-assignments-vector.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/compound-assignments-vector.txt)
add_test(binary-assignment ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/binary-assignments.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/binary-assignments.txt)
add_test(shift-assignment ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/shift-assignments.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/shift-assignments.txt)
add_test(shift-assignment-vector ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/shift-assignments-vector.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/shift-assignments-vector.txt)
add_test(multiple-logic-op ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/multiple-logic-op.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/multiple-logic-op.txt)
add_test(unicode ${EXECUTABLE_OUTPUT_PATH}/asebatest -d -s ${CMAKE_CURRENT_SOURCE_DIR}/data/unicode.txt)
add_test(optimisation-binary-not ${EXECUTABLE_OUTPUT_PATH}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/optimisation-binary-not.txt)
add_test(optimisation-bit-to-bit ${EXECUTABLE_OUTPUT_PATH}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/optimisation-bit-to-bit.txt)
add_test(optimisation-neutral-element ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/optimisation-neutral-element.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/optimisation-neutral-element.txt)
add_test(optimisation-absorbing-element ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/optimisation-absorbing-element.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/optimisation-absorbing-element.txt)
add_test(optimisation-demorgan ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/optimisation-demorgan.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/optimisation-demorgan.txt)
add_test(for-loop ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/for-loop.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/for-loop.txt)
add_test(for-loop-vector ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/for-loop-vector.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/for-loop-vector.txt)
add_test(for-loop-single-inc ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/for-loop-single-inc.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/for-loop-single-inc.txt)
add_test(for-loop-single-dec ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/for-loop-single-dec.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/for-loop-single-dec.txt)
add_test(while-loop ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/while-loop.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/while-loop.txt)
add_test(while-loop-vector ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/while-loop-vector.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/while-loop-vector.txt)
add_test(when-conditional ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/when-conditional.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/when-conditional.txt)
add_test(comments ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/comments.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/comments.txt)
add_test(subroutine ${EXECUTABLE_OUTPUT_PATH}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/subroutine.txt)
add_test(array-post-increment ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/array-post-increment.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/array-post-increment.txt)
add_test(array-constant-access ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/array-constant-access.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/array-constant-access.txt)
add_test(vardef ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/vardef.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/vardef.txt)
add_test(vardef-compat ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/vardef-compat.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/vardef-compat.txt)
add_test(vardef-constant-size ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/vardef-constant-size.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/vardef-constant-size.txt)
add_test(general-tuple ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/general-tuple.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/general-tuple.txt)
add_test(assignments ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/assignments.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/assignments.txt)
add_test(events ${EXECUTABLE_OUTPUT_PATH}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/events.txt)
add_test(general-tuple-events ${EXECUTABLE_OUTPUT_PATH}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/general-tuple-events.txt)
add_test(native-function ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/native-function.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/native-function.txt)
add_test(native-function-indirect ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/native-function-indirect.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/native-function-indirect.txt)
add_test(general-tuple-native-function ${EXECUTABLE_OUTPUT_PATH}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/general-tuple-native-function.txt)
add_test(var-def-compat-issue135 ${EXECUTABLE_OUTPUT_PATH}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/var-def-compat-issue135.txt)
add_test(array-indirect-access-issue134 ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/array-indirect-access-issue134.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/array-indirect-access-issue134.txt)
add_test(constdef ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/constdef.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/constdef.txt)
add_test(literal-overflow-check1 ${EXECUTABLE_OUTPUT_PATH}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/literal-overflow-check-ok1.txt)
add_test(literal-overflow-check2 ${EXECUTABLE_OUTPUT_PATH}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/literal-overflow-check-ok2.txt)
add_test(literal-hex1 ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/literal-hex1.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/literal-hex1.txt)
add_test(literal-hex2 ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/literal-hex2.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/literal-hex2.txt)
add_test(literal-bin1 ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/literal-bin1.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/literal-bin1.txt)
add_test(literal-bin2 ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/literal-bin2.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/literal-bin2.txt)
add_test(array-overwrite1 ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/array-overwrite.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/array-overwrite.txt)
add_test(negation-optimisation ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/negation-optimisation.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/negation-optimisation.txt)
add_test(division-optimisation ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/division-optimisation.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/division-optimisation.txt)
add_test(if-not-optimisation ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/if-not-optimisation.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/if-not-optimisation.txt)
add_test(callsub-before-sub-decl ${EXECUTABLE_OUTPUT_PATH}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/callsub-before-sub-decl.txt)
add_test(return-in-if ${EXECUTABLE_OUTPUT_PATH}/asebatest --event --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/return-in-if.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/return-in-if.txt)
add_test(sort-basic ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/sort-basic.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/sort-basic.txt)
add_test(sort-duplicates ${EXECUTABLE_OUTPUT_PATH}/asebatest --memcmp ${CMAKE_CURRENT_SOURCE_DIR}/data/sort-duplicates.dump ${CMAKE_CURRENT_SOURCE_DIR}/data/sort-duplicates.txt)

# the following tests should fail
add_test(division-by-zero-dyn ${EXECUTABLE_OUTPUT_PATH}/asebatest --exec_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/division-by-zero-dyn.txt)
add_test(division-by-zero-static ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/division-by-zero-static.txt)
add_test(chained-conditional ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/chained-conditional.txt)
add_test(implicit-conditional ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/implicit-conditional.txt)
add_test(array-access-out-of-bounds-dyn-over ${EXECUTABLE_OUTPUT_PATH}/asebatest --exec_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/array-access-out-of-bounds-dyn-over.txt)
add_test(array-access-out-of-bounds-dyn-under ${EXECUTABLE_OUTPUT_PATH}/asebatest --exec_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/array-access-out-of-bounds-dyn-under.txt)
add_test(array-access-out-of-bounds-static-over ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/array-access-out-of-bounds-static-over.txt)
add_test(array-access-out-of-bounds-static-under ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/array-access-out-of-bounds-static-under.txt)
add_test(vector-access-out-of-bounds-static-over ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/vector-access-out-of-bounds-static-over.txt)
add_test(vector-access-out-of-bounds-static-under ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/vector-access-out-of-bounds-static-under.txt)
add_test(vector-access-two-expr ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/vector-access-two-expr.txt)
add_test(assigning-bool ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/assigning-bool.txt)
add_test(inconsistent-input1 ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/inconsistent-input1.txt)
add_test(inconsistent-input2 ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/inconsistent-input2.txt)
add_test(inconsistent-input3 ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/inconsistent-input3.txt)
add_test(inconsistent-input4 ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/inconsistent-input4.txt)
add_test(assignments-fail1 ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/assignments-fail1.txt)
add_test(assignments-fail2 ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/assignments-fail2.txt)
add_test(assignments-fail3 ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/assignments-fail3.txt)
add_test(assignments-fail4 ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/assignments-fail4.txt)
add_test(vardef-fail1 ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/vardef-fail1.txt)
add_test(vardef-fail2 ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/vardef-fail2.txt)
add_test(vardef-fail3 ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/vardef-fail3.txt)
add_test(vardef-compat-fail1 ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/vardef-compat-fail1.txt)
add_test(vardef-not-constant-size ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/vardef-not-constant-size.txt)
add_test(out-of-memory1 ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/out-of-memory1.txt)
add_test(out-of-memory2 ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/out-of-memory2.txt)
add_test(out-of-memory-temp1 ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/out-of-memory-temp1.txt)
add_test(out-of-memory-temp2 ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/out-of-memory-temp2.txt)
add_test(if-condition-vector ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/if-condition-vector.txt)
add_test(for-loop-condition-vector ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/for-loop-condition-vector.txt)
add_test(for-loop-bounds ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/for-loop-bounds.txt)
add_test(constant-namespace-collision ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/constant-namespace-collision.txt)
add_test(array-constant-access-fail ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/array-constant-access-fail.txt)
add_test(constdef-collision-1 ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/constdef-collision-1.txt)
add_test(constdef-collision-2 ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/constdef-collision-2.txt)
add_test(constdef-overriding ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/constdef-overriding.txt)
add_test(constdef-collision-var ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/constdef-collision-var.txt)
add_test(literal-overflow-fail1 ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/literal-overflow-check-fail1.txt)
add_test(literal-overflow-fail2 ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/literal-overflow-check-fail2.txt)
add_test(literal-hex-overflow-fail1 ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/literal-hex-overflow1.txt)
add_test(literal-hex-overflow-fail2 ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/literal-hex-overflow2.txt)
add_test(literal-bin-overflow-fail1 ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/literal-bin-overflow1.txt)
add_test(literal-bin-overflow-fail2 ${EXECUTABLE_OUTPUT_PATH}/asebatest --comp_fail ${CMAKE_CURRENT_SOURCE_DIR}/data/literal-bin-overflow2.txt)

# check whether we have Python interpreter to run tests that require scripts
find_package(PythonInterp)
if (PYTHONINTERP_FOUND)
	# stress test the compiler, by simulating user's input
	# compiler should not crash. Exiting with an exception is OK
	# The script should always succeed (otherwise the compiler caught a signal)
	add_test(simulate-basic-arithmetic ${CMAKE_CURRENT_SOURCE_DIR}/simulateuser.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/basic-arithmetic.txt)
	add_test(simulate-advanced-arithmetic ${CMAKE_CURRENT_SOURCE_DIR}/simulateuser.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/advanced-arithmetic.txt)
	add_test(simulate-binary-op ${CMAKE_CURRENT_SOURCE_DIR}/simulateuser.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/binary-op.txt)
	add_test(simulate-shift-op ${CMAKE_CURRENT_SOURCE_DIR}/simulateuser.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/shift-op.txt)
	add_test(simulate-compound-assignment ${CMAKE_CURRENT_SOURCE_DIR}/simulateuser.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/compound-assignments.txt)
	add_test(simulate-binary-assignment ${CMAKE_CURRENT_SOURCE_DIR}/simulateuser.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/binary-assignments.txt)
	add_test(simulate-shift-assignment ${CMAKE_CURRENT_SOURCE_DIR}/simulateuser.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/shift-assignments.txt)
	add_test(simulate-multiple-logic-op ${CMAKE_CURRENT_SOURCE_DIR}/simulateuser.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/multiple-logic-op.txt)
	add_test(simulate-unicode ${CMAKE_CURRENT_SOURCE_DIR}/simulateuser.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/unicode.txt)
	add_test(simulate-optimisation-binary-not ${CMAKE_CURRENT_SOURCE_DIR}/simulateuser.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/optimisation-binary-not.txt)
	add_test(simulate-optimisation-bit-to-bit ${CMAKE_CURRENT_SOURCE_DIR}/simulateuser.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/optimisation-bit-to-bit.txt)
	add_test(simulate-for-loop ${CMAKE_CURRENT_SOURCE_DIR}/simulateuser.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/for-loop.txt)
	add_test(simulate-while-loop ${CMAKE_CURRENT_SOURCE_DIR}/simulateuser.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/while-loop.txt)
	add_test(simulate-when-conditional ${CMAKE_CURRENT_SOURCE_DIR}/simulateuser.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/when-conditional.txt)
	add_test(simulate-comments ${CMAKE_CURRENT_SOURCE_DIR}/simulateuser.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/comments.txt)
	add_test(simulate-subroutine ${CMAKE_CURRENT_SOURCE_DIR}/simulateuser.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/subroutine.txt)

	add_test(simulate-division-by-zero-dyn ${CMAKE_CURRENT_SOURCE_DIR}/simulateuser.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/division-by-zero-dyn.txt)
	add_test(simulate-division-by-zero-static ${CMAKE_CURRENT_SOURCE_DIR}/simulateuser.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/division-by-zero-static.txt)
	add_test(simulate-chained-conditional ${CMAKE_CURRENT_SOURCE_DIR}/simulateuser.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/chained-conditional.txt)
	add_test(simulate-implicit-conditional ${CMAKE_CURRENT_SOURCE_DIR}/simulateuser.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/implicit-conditional.txt)
	add_test(simulate-array-access-out-of-bounds-dyn-over ${CMAKE_CURRENT_SOURCE_DIR}/simulateuser.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/array-access-out-of-bounds-dyn-over.txt)
	add_test(simulate-array-access-out-of-bounds-dyn-under ${CMAKE_CURRENT_SOURCE_DIR}/simulateuser.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/array-access-out-of-bounds-dyn-under.txt)
	add_test(simulate-array-access-out-of-bounds-static-over ${CMAKE_CURRENT_SOURCE_DIR}/simulateuser.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/array-access-out-of-bounds-static-over.txt)
	add_test(simulate-array-access-out-of-bounds-static-under ${CMAKE_CURRENT_SOURCE_DIR}/simulateuser.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/array-access-out-of-bounds-static-under.txt)
	add_test(simulate-assigning-bool ${CMAKE_CURRENT_SOURCE_DIR}/simulateuser.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/assigning-bool.txt)
	add_test(simulate-inconsistent-input1 ${CMAKE_CURRENT_SOURCE_DIR}/simulateuser.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/inconsistent-input1.txt)
	add_test(simulate-inconsistent-input2 ${CMAKE_CURRENT_SOURCE_DIR}/simulateuser.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/inconsistent-input2.txt)
	add_test(simulate-inconsistent-input3 ${CMAKE_CURRENT_SOURCE_DIR}/simulateuser.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/inconsistent-input3.txt)
	add_test(simulate-inconsistent-input4 ${CMAKE_CURRENT_SOURCE_DIR}/simulateuser.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/inconsistent-input4.txt)

	# use zzuf to fuzzy the input script deterministically
	# compiler should not crash
	find_program(zzuf_FOUND zzuf)
	if (zzuf_FOUND)
		message(STATUS "zzuf executable found: " ${zzuf_FOUND})
		# set the number of test loops for the fuzzy test
		set(fuzzy_loop "500")
		# add tests
		add_test(fuzzy-basic-arithmetic ${CMAKE_CURRENT_SOURCE_DIR}/fuzzyinput.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/basic-arithmetic.txt ${fuzzy_loop})
		add_test(fuzzy-advanced-arithmetic ${CMAKE_CURRENT_SOURCE_DIR}/fuzzyinput.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/advanced-arithmetic.txt ${fuzzy_loop})
		add_test(fuzzy-binary-op ${CMAKE_CURRENT_SOURCE_DIR}/fuzzyinput.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/binary-op.txt ${fuzzy_loop})
		add_test(fuzzy-shift-op ${CMAKE_CURRENT_SOURCE_DIR}/fuzzyinput.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/shift-op.txt ${fuzzy_loop})
		add_test(fuzzy-compound-assignment ${CMAKE_CURRENT_SOURCE_DIR}/fuzzyinput.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/compound-assignments.txt ${fuzzy_loop})
		add_test(fuzzy-binary-assignment ${CMAKE_CURRENT_SOURCE_DIR}/fuzzyinput.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/binary-assignments.txt ${fuzzy_loop})
		add_test(fuzzy-shift-assignment ${CMAKE_CURRENT_SOURCE_DIR}/fuzzyinput.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/shift-assignments.txt ${fuzzy_loop})
		add_test(fuzzy-multiple-logic-op ${CMAKE_CURRENT_SOURCE_DIR}/fuzzyinput.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/multiple-logic-op.txt ${fuzzy_loop})
		add_test(fuzzy-unicode ${CMAKE_CURRENT_SOURCE_DIR}/fuzzyinput.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/unicode.txt ${fuzzy_loop})
		add_test(fuzzy-optimisation-binary-not ${CMAKE_CURRENT_SOURCE_DIR}/fuzzyinput.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/optimisation-binary-not.txt ${fuzzy_loop})
		add_test(fuzzy-for-loop ${CMAKE_CURRENT_SOURCE_DIR}/fuzzyinput.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/for-loop.txt ${fuzzy_loop})
		add_test(fuzzy-while-loop ${CMAKE_CURRENT_SOURCE_DIR}/fuzzyinput.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/while-loop.txt ${fuzzy_loop})
		add_test(fuzzy-when-conditional ${CMAKE_CURRENT_SOURCE_DIR}/fuzzyinput.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/when-conditional.txt ${fuzzy_loop})
		add_test(fuzzy-comments ${CMAKE_CURRENT_SOURCE_DIR}/fuzzyinput.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/comments.txt ${fuzzy_loop})
		add_test(fuzzy-subroutine ${CMAKE_CURRENT_SOURCE_DIR}/fuzzyinput.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/subroutine.txt ${fuzzy_loop})
	else (zzuf_FOUND)
		message(WARNING "zzuf executable not found! Disabling fuzzy tests")
	endif (zzuf_FOUND)

	# use valgrind to test memory leaks inside the compiler
	if (valgrind_FOUND)
		# test all the .txt files inside the data directory
		add_test(valgrind-compiler-all ${CMAKE_CURRENT_SOURCE_DIR}/valgrind.py ${CMAKE_CURRENT_BINARY_DIR}/asebatest ${CMAKE_CURRENT_SOURCE_DIR}/data/)
	endif (valgrind_FOUND)
else (PYTHONINTERP_FOUND)
	message(WARNING "Python interpreter not found! Disabling advanced compiler tests")
endif (PYTHONINTERP_FOUND)
