#!/usr/bin/env python

import sys, re

testname=sys.argv[1]
execout=sys.argv[2]

# piece together a .good file
basehelp='basehelp.txt'
fh = open(basehelp, 'r')
myLines = fh.readlines()
fh.close()

partgoodfile=testname + '.partgood'
fh = open(partgoodfile, 'r')
myLines += fh.readlines()
fh.close()

goodfile=testname + '.good'
fh = open(goodfile, 'w')
for line in myLines:
    # ignore blank lines
    if not line.strip(): continue
    # replace all white space with a single space
    fh.write(re.sub("\s+", " ", line)+'\n')
fh.close()

del myLines

# We could avoid the following if we could send arguments to diff in sub_test
# replace all white space in the output with a single space
fh = open(execout, 'r')
myLines = fh.readlines()
fh.close()

inBuiltIns = False
fh = open(execout, 'w')
for line in myLines:
    # ignore blank lines
    if not line.strip(): continue
    if inBuiltIns:
        if line.strip().find(' config vars:') != -1:
            inBuiltIns = False
        else:
            # Remove "(configured to XXX)" from output
            line = line.split('(configured to')[0]
    if line.strip().find('Built-in config vars:') != -1:
        inBuiltIns = True
    # replace all white space with a single space
    fh.write(re.sub("\s+", " ", line)+'\n')
fh.close()
