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
670 B
Python
Raw Normal View History

2020-01-27 22:30:01 +01:00
#!/usr/bin/env python3
2019-01-25 11:39:31 +01:00
import sys
with open(sys.argv[1],'r') as f:
raw_data = f.read()
2020-01-27 22:30:01 +01:00
print("set -x")
2019-01-25 11:39:31 +01:00
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)
2020-01-27 22:30:01 +01:00
print("".join(output).replace("@test ",
2019-01-25 11:39:31 +01:00
"""[[ -z $BATS_TEST_NUMBER ]] && BATS_TEST_NUMBER=0 || ((++BATS_TEST_NUMBER)) ;
2020-01-27 22:30:01 +01:00
export BATS_TEST_DESCRIPTION=""").replace("skip","return"))
2019-01-25 11:39:31 +01:00