#!/usr/bin/env python2
from os import remove
from subprocess import Popen

def main():
    files = open('control_files.txt').readlines()
    for control in files:
	control = control.strip()
	if not control:
	    continue
	text_filename, items_filename, messages_filename = control.split(' ')
	stdout, stderr = open('out.txt', 'w'), open('err.txt', 'w')

	p = Popen("./parser " + text_filename, stdout=stdout, stderr=stderr, shell=True)
	p.wait()
	if open('err.txt').read(1024):
	    print "[FAIL]", text_filename
	    remove('out.txt')
	    return
	else:
	    print "[PASS]", text_filename
	    remove('err.txt')
	    remove('out.txt')


if __name__ == '__main__':
    main()
