Files
cobol-java-v3/test-data/s19_final_bridge_test.py
T

55 lines
2.1 KiB
Python

"""S19: Final bridge test — extract_structure with new procedure parser"""
import sys, os, re, time
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from _paths import BENCH_ROOT as ROOT
COPYBOOKS = os.path.join(ROOT, "common", "copybooks")
from cobol_testgen import extract_structure, generate_data
from cobol_testgen.read import preprocess, resolve_copybooks
from cobol_testgen.flatfile import analyze_fd_layout, write_all_files
def find_main(d):
cbls = [f for f in os.listdir(d) if f.endswith('.cbl')]
ws = [f for f in cbls if re.match(r'main-\d{2}-', f, re.IGNORECASE)]
if ws: return max(ws, key=lambda f: os.path.getsize(os.path.join(d, f)))
return max(cbls, key=lambda f: os.path.getsize(os.path.join(d, f))) if cbls else None
fmt = "{:<28} {:>4} {:>7} {:>5} {:>5} {}"
print(fmt.format("Program", "Br", "Time", "Recs", "Flats", "Parser"))
print("-"*78)
with_br = 0; gen_ok = 0; old_cnt = 0; new_cnt = 0; total_t = 0
for d in sorted(os.listdir(ROOT)):
dp = os.path.join(ROOT, d)
if not os.path.isdir(dp) or d in ('common','docs','cross-cutting'): continue
fn = find_main(dp)
if not fn: continue
t0 = time.time()
try:
src = open(os.path.join(dp, fn), encoding='utf-8').read()
st = extract_structure(src)
branches = st.get('total_branches', 0)
t = (time.time()-t0)*1000
total_t += t
# Also generate data + flat files
pp = resolve_copybooks(src, dp, extra_search_paths=[COPYBOOKS])
pp = preprocess(pp)
recs = generate_data(pp, st)
layouts = analyze_fd_layout(pp)
flats = write_all_files(recs, pp, dp) if layouts else []
parser = st.get("parser", "old")
if branches > 0: with_br += 1
gen_ok += 1
if parser == "new": new_cnt += 1
else: old_cnt += 1
print(fmt.format(d, branches, f"{t:.0f}ms", len(recs), len(flats), parser))
except Exception as e:
print(fmt.format(d, "ERR", f"{(time.time()-t0)*1000:.0f}ms", "", "", str(e)[:40]))
print(f"\nWith branches: {with_br}/{gen_ok}")
print(f"Parser: new={new_cnt} old={old_cnt}")
print(f"Total time: {total_t/1000:.1f}s")