#!/usr/bin/env python3

from glob import glob
import subprocess
import os.path
import sys
import tempfile

CPP="@CMAKE_CURRENT_BINARY_DIR@/macro"

count=0
ret=0

for src in glob(os.path.join ("@CMAKE_CURRENT_SOURCE_DIR@", "test/cpp/good/*.inc")):
    basename, extension = os.path.splitext(src)
    res = basename + ".res"

    cpp_out = subprocess.check_output([CPP, src])
    cpp_out = cpp_out.decode()
    cpp_out = cpp_out.replace("\r", "")
    with open(res, "r") as f: res_out = f.read()

    head = "ok"
    if cpp_out != res_out:
        head = "not ok"
        ret = 1


    print(f"{head} - {src}")
    count = count + 1

print(f"1..{count}")
sys.exit(ret)