Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 import os
00009 import string
00010 import sys
00011
00012
00013 def test_file(filename):
00014 """Runs stage with the given filename and validates the output."""
00015
00016 file = open(filename)
00017 a = read_lists(file)
00018 del file
00019
00020 file = os.popen('../../src/stage %s' % filename, 'r')
00021 b = read_lists(file)
00022 del file
00023
00024 print '%s : errors ' % filename,
00025 if compare_lists(a[2], b[2]) != 0:
00026 print ': \033[41mfail\033[0m'
00027 print_lists(a[2], b[2])
00028 return 1
00029 else:
00030 print ': pass'
00031
00032 print '%s : sections' % filename,
00033 if compare_lists(a[0], b[0]) != 0:
00034 print ': \033[41mfail\033[0m'
00035 print_lists(a[0], b[0])
00036 else:
00037 print ': pass'
00038
00039 print '%s : items ' % filename,
00040 if compare_lists(a[1], b[1]) != 0:
00041 print ': \033[41mfail\033[0m'
00042 print_lists(a[1], b[1])
00043 else:
00044 print ': pass'
00045
00046 return 0
00047
00048
00049 def read_lists(file):
00050 """Read and return the various lists from a file object."""
00051
00052 list = None
00053 sections = []
00054 items = []
00055 errors = []
00056
00057 while 1:
00058
00059 line = file.readline()
00060 if not line:
00061 break
00062 bits = string.split(line)
00063 if not bits:
00064 continue
00065 if bits[0] == '##':
00066 if bits[1] == 'begin':
00067 if bits[2] == 'sections':
00068 list = sections
00069 elif bits[2] == 'items':
00070 list = items
00071 elif bits[1] == 'end':
00072 list = None
00073 elif bits[1] == 'stage' and bits[2] == 'error':
00074 errors.append(string.join(bits[4:]))
00075 elif list != None:
00076 list.append(string.join(bits[1:]))
00077 elif bits[0] == 'stage' and bits[1] == 'error':
00078 errors.append(string.join(bits[3:]))
00079
00080 return (sections, items, errors)
00081
00082
00083 def compare_lists(la, lb):
00084 """Compare two lists."""
00085
00086 if len(la) != len(lb):
00087 return 1
00088 for i in range(0, len(la)):
00089 sa = la[i]
00090 sb = lb[i]
00091 if sa != sb:
00092 return 1
00093 return 0
00094
00095
00096 def print_lists(la, lb):
00097 """Print two lists."""
00098
00099 for i in range(0, max(len(la), len(lb))):
00100 if i < len(la):
00101 sa = la[i]
00102 else:
00103 sa = ''
00104 if i < len(lb):
00105 sb = lb[i]
00106 else:
00107 sb = ''
00108 if sa == sb:
00109 print sa
00110 print sb
00111 else:
00112 print '\033[42m' + sa + '\33[K\033[0m'
00113 print '\033[41m' + sb + '\33[K\033[0m'
00114 return
00115
00116
00117
00118
00119 def main(argv):
00120 """Run the tests."""
00121
00122 for test in argv[1:]:
00123 test_file(test)
00124
00125 return
00126
00127
00128
00129
00130 if __name__ == '__main__':
00131
00132 main(sys.argv)