#!/usr/bin/env python """ Takes testing files and turns them PHP module tests """ import glob import os def phpescape(s): """ escapes plain text into php-code """ return s.replace("\\", "\\\\").replace("$", "\\$") def readtestdata(filename): """ Read a test file and split into components """ state = None info = { '--TEST--': '', '--INPUT--': '', '--EXPECTED--': '' } for line in open(filename, 'r'): line = line.rstrip() if line in ('--TEST--', '--INPUT--', '--EXPECTED--'): state = line elif state: info[state] += line + '\n' # remove last newline from input info['--INPUT--'] = info['--INPUT--'][0:-1] return (info['--TEST--'], info['--INPUT--'].strip(), info['--EXPECTED--'].strip()) def gentest_tokens(): """ generate token phpt test """ for testname in sorted(glob.glob('../tests/test-tokens-*.txt')): data = readtestdata(os.path.join('../tests', testname)) testname = os.path.basename(testname) phpt = """ --TEST-- {1} --FILE--