9
1
mirror of https://github.com/QuantumPackage/qp2.git synced 2024-11-09 15:03:37 +01:00
qp2/tests/bats_to_sh.py

34 lines
668 B
Python
Raw Normal View History

2019-01-25 11:39:31 +01:00
#!/usr/bin/env python2
import sys
with open(sys.argv[1],'r') as f:
raw_data = f.read()
print "set -x"
output = []
inside = False
level = 0
for i in raw_data:
new_i = i
if i == "@":
inside = True
elif i == "{" and inside and level == 0:
new_i = "\nfunction _run_test() {\n setup\n"
elif i == "}" and inside and level == 1:
inside = False
new_i = "}\n_run_test || exit 1"
if i == "{":
level += 1
elif i == "}":
level -= 1
output.append(new_i)
print "".join(output).replace("@test ",
"""[[ -z $BATS_TEST_NUMBER ]] && BATS_TEST_NUMBER=0 || ((++BATS_TEST_NUMBER)) ;
export BATS_TEST_DESCRIPTION=""").replace("skip","return")