libabigail/tests/update-test-output.py
Dodji Seketeli bfb7ccb372 tests/update-test-output.py: Adapt to some broken test output
Sometimes, the output of runtestreaddwarf or runtestannotate are
broken due the fact that they execute test units in parallel and each
unit might emit output that watch on each other toes.

This fixes tests/update-test-output.py to take that into account.

As this is a helper tool used to update updates, it won't have any
impact on libabigail's output.

	* tests/update-test-output.py (process): Don't expect the start
	pattern of the main diff hunk to begin at the end of a line
	because that can be broken for runtestreaddwarf and co.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2023-04-25 15:50:25 +02:00

74 lines
2.0 KiB
Python
Executable File

#!/bin/python
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# This program generates the copy commands you should use to update
# the reference data for tests <build-dir>/tests/runtest* that emit an
# output that is compared against a reference output.
#
# It takes in argument the diff result emitted by
# <build-dir>/tests/runtest*, and emits on standard output a series of
# 'cp <src> <dest>' commands to execute to update reference data of
# the test.
import fileinput
import re
import sys
import getopt
def display_usage():
sys.stderr.write("usage: prog-name [options] <file-name|-->\n");
sys.stderr.write(" options:\n");
sys.stderr.write(" -h display this help\n");
sys.stderr.write(" argument:\n");
sys.stderr.write(" <file-name> the file to read from\n");
sys.stderr.write(" if no argument, then reads from stdin\n");
sys.exit(2)
def main():
input_file = None
try:
opts, args = getopt.getopt(sys.argv[1:], "hi", ["help"])
except getopt.GetoptError as err:
print(str(err))
display_usage()
for opt, arg in opts:
if opt in ("-h", "--help"):
display_usage()
else:
# unknown option.
display_usage()
if input_file == None and len(args) and args[0] != None:
input_file = open(args[0], 'r')
elif input_file == None:
input_file = sys.stdin
if input_file != None:
process(input_file)
else:
display_usage()
def process(input_file):
source = None
dest = None
for line in input_file:
m = re.match(r'(.*?)--- (.*?)\t', line)
if m:
dest = m.group(2)
else:
m = re.match(r'(.*?)\+\+\+ (.*?)\t', line)
if m:
source = m.group(2)
if source != None and dest != None:
sys.stdout.write("cp " + source + " " + dest + "\n");
source = None
dest = None
if __name__ == "__main__":
main()