#!/bin/bash

export TESTLOG="tests.run.out"
cat /dev/null > ${TESTLOG}

export HERE="`pwd`"
export BASEDIR="../.."
export TESTINCDIR="${BASEDIR}/qss-qasm/tests/include"
export TESTSRCDIR="${BASEDIR}/qss-qasm/tests/src"
export QASMPARSER="${HERE}/QasmParser"

export RED='\033[0;31m'
export GREEN='\033[0;32m'
export NC='\033[0m'

ulimit -Ss unlimited

for file in \
  adder_8.qasm \
  barrier.qasm \
  cphase.qasm \
  newlineifelse.qasm \
  nospace-ifelse.qasm \
  qft1.qasm \
  qft2.qasm \
  qft4.qasm \
  tof_10.qasm \
  tof_3.qasm \
  tof_4.qasm \
  tof_5.qasm \
  qft1.qasm \
  qft2.qasm \
  teleportation-1.qasm \
  teleportation-2.qasm \
  teleportation-3.qasm \
  test-qubit.qasm \
  test-const.qasm \
  hadamard.qasm \
  angle-theta.qasm \
  test-angle.qasm \
  test-angle-cast.qasm \
  test-big-int.qasm \
  test-bitset-cast.qasm \
  test-bool.qasm \
  test-bool-2.qasm \
  test-bool-3.qasm \
  test-gate-1.qasm \
  test-gate-2.qasm \
  test-gate-3.qasm \
  test-gate-4.qasm \
  test-gate-switch.qasm \
  test-bit-1.qasm \
  test-bit-2.qasm \
  test-bit-3.qasm \
  test-bit-4.qasm \
  test-bit-5.qasm \
  test-bit-6.qasm \
  test-bit-7.qasm \
  test-const.qasm \
  test-qubit.qasm \
  test-euler.qasm \
  test-pi.qasm \
  test-tau.qasm \
  test-ifelse-1.qasm \
  test-ifelse-2.qasm \
  test-ifelse-3.qasm \
  test-ifelse-4.qasm \
  test-ifelse-5.qasm \
  test-ifelse-6.qasm \
  test-ifelse-7.qasm \
  test-ifelse-8.qasm \
  test-ifelse-9.qasm \
  test-ifelse-10.qasm \
  test-ifelse-11.qasm \
  test-ifelse-12.qasm \
  test-ifelse-13.qasm \
  test-shift-1.qasm \
  test-shift-2.qasm \
  test-shift-3.qasm \
  test-for-1.qasm \
  test-for-2.qasm \
  test-for-3.qasm \
  test-for-4.qasm \
  test-for-5.qasm \
  test-for-6.qasm \
  test-for-7.qasm \
  test-induction-var-1.qasm \
  test-induction-var-2.qasm \
  test-induction-var-3.qasm \
  test-while-1.qasm \
  test-while-2.qasm \
  test-while-3.qasm \
  test-assign.qasm \
  test-cast-bool.qasm \
  test-no-openqasm-line-1.qasm \
  test-no-openqasm-line-2.qasm \
  test-no-openqasm-line-3.qasm \
  test-c-comment.qasm \
  test-consecutive-gates-1.qasm \
  test-consecutive-gates-2.qasm \
  test-add-assign.qasm \
  test-sub.qasm \
  test-eq.qasm \
  test-operators.qasm \
  test-operators-2.qasm \
  test-mpdecimal.qasm \
  test-unary-ops.qasm \
  test-func-1.qasm \
  test-func-2.qasm \
  test-func-3.qasm \
  test-func-4.qasm \
  test-func-5.qasm \
  test-func-6.qasm \
  test-func-7.qasm \
  test-func-8.qasm \
  test-func-9.qasm \
  test-func-10.qasm \
  test-xor-1.qasm \
  test-cx.qasm \
  test-cos.qasm \
  test-phase.qasm \
  test-hadamard.qasm \
  test-scalars.qasm \
  test-add-assign.qasm \
  test-nested-if.qasm \
  test-nested-redeclarations.qasm \
  test-return.qasm \
  test-return-2.qasm \
  test-return-3.qasm \
  test-return-xor.qasm \
  test-kernel-1.qasm \
  test-kernel-2.qasm \
  test-kernel-3.qasm \
  test-kernel-4.qasm \
  test-defcal.qasm \
  test-defcal-reset.qasm \
  test-defcal-measure.qasm \
  test-defcal-binop.qasm \
  test-defcal-conversion.qasm \
  test-defcal-unop.qasm \
  test-measure.qasm \
  test-measure-2.qasm \
  test-void-measure.qasm \
  test-opaque.qasm \
  test-let-1.qasm \
  test-let-2.qasm \
  test-let-3.qasm \
  test-let-4.qasm \
  test-let-5.qasm \
  test-let-6.qasm \
  test-fixed-scalars.qasm \
  test-ctrl.qasm \
  test-creg.qasm \
  test-qreg-v2.qasm \
  test-qreg-v3.qasm \
  iqpe-1.qasm \
  iqpe-2-3.qasm \
  iqpe-4.qasm \
  iqpe-5.qasm \
  iqpe-6.qasm \
  iqpe-7.qasm \
  iqpe-8.qasm \
  iqpe-9.qasm \
  iqpe-10.qasm \
  test-box-1.qasm \
  test-box-2.qasm \
  test-box-3.qasm \
  test-box-4.qasm \
  test-opaque.qasm \
  test-delay.qasm \
  test-delay-2.qasm \
  test-func-call-1.qasm \
  test-func-call-2.qasm \
  test-func-call-3.qasm \
  test-func-call-4.qasm \
  test-func-call-5.qasm \
  test-func-call-6.qasm \
  test-func-call-7.qasm \
  test-func-call-8.qasm \
  test-func-call-9.qasm \
  test-func-call-10.qasm \
  test-sign-1.qasm \
  test-sign-2.qasm \
  bell_v0.qasm \
  bell_v1.qasm \
  reset_v0.qasm \
  reset_v1.qasm \
  qss-teleport.qasm \
  test-array-1.qasm \
  test-array-2.qasm \
  test-array-3.qasm \
  test-array-4.qasm \
  test-array-5.qasm \
  test-array-6.qasm \
  test-array-7.qasm \
  test-array-8.qasm \
  test-array-9.qasm \
  test-array-10.qasm \
  test-array-11.qasm \
  test-array-12.qasm \
  test-array-13.qasm \
  test-array-14.qasm \
  test-array-15.qasm \
  test-array-16.qasm \
  test-extern-1.qasm \
  test-extern-2.qasm \
  test-extern-3.qasm \
  test-extern-4.qasm \
  test-duration-1.qasm \
  test-duration-2.qasm \
  test-complex-1.qasm \
  test-complex-2.qasm \
  test-complex-3.qasm \
  test-complex-4.qasm \
  test-complex-5.qasm \
  test-complex-6.qasm \
  test-complex-7.qasm \
  test-complex-8.qasm \
  test-complex-9.qasm \
  test-complex-10.qasm \
  test-complex-11.qasm \
  test-complex-12.qasm \
  test-ugate-1.qasm \
  test-ugate-2.qasm \
  test-ugate-3.qasm \
  test-inverse-trig-1.qasm \
  test-inverse-trig-2.qasm \
  test-function-gate-1.qasm \
  test-function-param-names.qasm \
  test-negative-expression.qasm \
  test-negative-angle.qasm \
  test-nested-loop.qasm \
  test-unary-pi.qasm \
  test-unicode.qasm \
  test-chinese-simplified-utf8.qasm \
  test-chinese-traditional-utf8.qasm \
  test-german-utf8.qasm \
  test-hiragana-utf8.qasm \
  test-katakana-utf8.qasm \
  test-korean-utf8.qasm \
  test-russian-utf8.qasm \
  test-swedish-utf8.qasm \
  test-umlaut-utf8.qasm \
  test-underscore-1-utf8.qasm \
  test-underscore-2-utf8.qasm \
  test-underscore-3-utf8.qasm \
  test-popcount.qasm \
  test-popcount-2.qasm \
  test-rotl.qasm \
  test-rotr.qasm \
  test-bitset-bitops.qasm \
  test-control-chain-1.qasm \
  test-gate-control-1.qasm \
  test-gate-control-2.qasm \
  test-gate-gphase.qasm \
  test-gate-noangle.qasm \
  test-gate-qubit.qasm \
  test-input.qasm \
  test-output.qasm \
  test-neg-trig.qasm \
  test-subscript-1.qasm \
  test-frame-1.qasm \
  test-frame-2.qasm \
  test-frame-3.qasm \
  test-cal-1.qasm \
  test-cal-2.qasm \
  test-cal-complex.qasm \
  test-dot-1.qasm \
  test-dot-2.qasm \
  test-logical-bang.qasm \
  test-waveform-1.qasm \
  test-waveform-2.qasm \
  test-waveform-3.qasm \
  test-waveform-4.qasm \
  test-waveform-5.qasm \
  test-pow-1.qasm \
  test-pow-2.qasm \
  test-pow-3.qasm \
  test-pow-int.qasm \
  test-play-1.qasm \
  test-play-2.qasm \
  test-builtins-1.qasm \
  test-const-scalars.qasm \
  test-pragma-1.qasm \
  test-pragma-2.qasm \
  test-pragma-3.qasm \
  test-run-defcal-1.qasm \
  test-run-defcal-2.qasm \
  test-identifier-overloading.qasm \
  test-cast-bool.qasm \
  test-c-comment.qasm \
  test-defcal-conversion.qasm \
  test-function-param-names.qasm \
  test-gate-gphase.qasm \
  test-gate-noangle.qasm \
  test-gate-qubit.qasm \
  test-idref-scope.qasm \
  test-nested-if.qasm \
  test-nested-redeclarations.qasm \
  test-return-2.qasm \
  test-return-3.qasm \
  test-return-xor.qasm \
  test-ugate-3.qasm \
  test-void-measure.qasm \
  test-rz-1.qasm \
  test-rz-2.qasm \
  test-u-1.qasm \
  test-consecutive-gates-1.qasm \
  test-consecutive-gates-2.qasm \
  test-switch-1.qasm \
  test-switch-2.qasm \
  test-switch-3.qasm \
  test-switch-4.qasm \
  test-do-while-1.qasm \
  test-do-while-2.qasm \
  test-do-while-3.qasm \
  test-do-while-4.qasm \
  test-do-while-5.qasm \
  test-gate-switch.qasm \
  test-bitset-cast.qasm \
  test-bool-cast.qasm \
  test-angle-cast.qasm \
  test-bitset-int-cast.qasm \
  test-bit-gate-1.qasm \
  test-bit-gate-2.qasm \
  test-bit-gate-3.qasm \
  test-bit-gate-4.qasm \
  test-bit-gate-5.qasm \
  test-unicode-epislon-gate.qasm \
  test-annotation-1.qasm \
  test-annotation-2.qasm \
  test-nested-while-loop-1.qasm \
  test-nested-for-loop-1.qasm
do
  printf "Testing ${file} ... "
  echo "${file}.out" >> ${TESTLOG} 2>&1
  ${QASMPARSER} -I${TESTINCDIR} "${TESTSRCDIR}/${file}" > "${file}.out" 2>&1

  if [ $? -ne 0 ] ; then
    printf "${RED}FAILED!${NC}\n"
  else
    printf "${GREEN}OK.${NC}\n"
  fi
done
