diff --git a/scripts/gendiff.py b/scripts/gendiff.py index 037f8d94..f5e1ac40 100755 --- a/scripts/gendiff.py +++ b/scripts/gendiff.py @@ -10,7 +10,7 @@ performed on all files, but no diff is created. The source files are assumed to be terminal output captured by the `script` command. -The original source files are backed up with the .orig extension. +The cleaned source files are saved with the .clean extension. """ import sys,re @@ -19,35 +19,44 @@ from difflib import unified_diff fns = sys.argv[1:] translate = { - '\r': '[CR]\n', +# '\r': '[CR]\n', + '\r': '', '\b': '[BS]', +# chr(4): '', # Ctrl-D, EOT } def cleanup_file(fn): + with open(fn) as fp: data = fp.read() + def gen_text(): for line in data.splitlines(): - line = re.sub('\r\n','\n',line) # DOS CRLF to Unix LF +# line = re.sub('\r\n','\n',line) # DOS CRLF to Unix LF line = line.translate({ord(a):b for a,b in translate.items()}) line = re.sub(r'\s+$','',line) # trailing whitespace yield line + ret = list(gen_text()) - with open(fn+'.orig','w') as fp: - fp.write(data) - with open(fn,'w') as fp: + + sys.stderr.write(f'Saving cleaned file to {fn}.clean\n') + + with open(f'{fn}.clean','w') as fp: fp.write('\n'.join(ret)) + return ret +if len(fns) != 2: + sys.stderr.write(f'{len(fns)} input files. Not generating diff.\n') + cleaned_texts = [cleanup_file(fn) for fn in fns] if len(fns) == 2: """ chunk headers have trailing newlines, hence the rstrip() """ + sys.stderr.write('Generating diff\n') print( f'diff a/{fns[0]} b/{fns[1]}\n' + '\n'.join(a.rstrip() for a in unified_diff(*cleaned_texts,fromfile=f'a/{fns[0]}',tofile=f'b/{fns[1]}')) ) -else: - print(f'{len(fns)} input files. Not generating diff.') diff --git a/test/include/pexpect.py b/test/include/pexpect.py index 9f114da2..52a0904b 100755 --- a/test/include/pexpect.py +++ b/test/include/pexpect.py @@ -81,7 +81,8 @@ class MMGenPexpect(object): self.expect('Comment: ',add_comment+'\n') def ok(self): - self.p.sendeof() + if not opt.pexpect_spawn: + self.p.sendeof() self.p.read() ret = self.p.wait() if ret != self.req_exit_val and not opt.coverage: