Commit 63918e6d authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel 🕺

Add n-ary version of `two_normalisers` to testsuite lib

This is more readable than nesting `two_normalisers()`-invocations
parent aa2ceba3
......@@ -506,8 +506,29 @@ def _normalise_errmsg_fun( name, opts, f ):
opts.extra_errmsg_normaliser = f
def two_normalisers(f, g):
"""
See also `join_normalisers` for a n-ary version of `two_normalisers`
"""
return lambda x, f=f, g=g: f(g(x))
def join_normalisers(*a):
"""
Compose functions, e.g.
join_normalisers(f1,f2,f3)
is the same as
lambda x: f1(f2(f3(x)))
"""
assert all(callable(f) for f in a)
fn = lambda x:x # identity function
for f in a:
fn = lambda x,f=f,fn=fn: fn(f(x))
return fn
# ----
# Function for composing two opt-fns together
......@@ -1004,8 +1025,10 @@ def do_compile( name, way, should_fail, top_mod, extra_mods, extra_hc_opts, over
(platform_specific, expected_stderr_file) = platform_wordsize_qualify(namebase, 'stderr')
actual_stderr_file = qualify(name, 'comp.stderr')
if not compare_outputs('stderr', \
two_normalisers(two_normalisers(getTestOpts().extra_errmsg_normaliser, normalise_errmsg), normalise_whitespace), \
if not compare_outputs('stderr',
join_normalisers(getTestOpts().extra_errmsg_normaliser,
normalise_errmsg,
normalise_whitespace),
expected_stderr_file, actual_stderr_file):
return failBecause('stderr mismatch')
......
......@@ -8,6 +8,9 @@ def normaliseArrayPackage(str):
def normaliseBytestringPackage(str):
return re.sub('bytestring-[0-9]+(\.[0-9]+)*', 'bytestring-<VERSION>', str)
def normaliseIntegerPackage(str):
return re.sub('integer-(gmp|simple)-[0-9.]+', 'integer-<IMPL>-<VERSION>', str)
def normaliseArrayPackageKey(str):
return re.sub('array_[A-Za-z0-9]+', 'array_<HASH>', str)
......@@ -38,10 +41,11 @@ make_args = 'VANILLA=' + vanilla + ' PROF=' + prof + ' DYN=' + dyn
test('safePkg01',
[clean_cmd('$MAKE -s --no-print-directory cleanPackageDatabase.safePkg01'),
normalise_errmsg_fun(ignoreLdOutput),
normalise_fun(two_normalisers(two_normalisers(normaliseArrayPackage,
normaliseArrayPackageKey),
normaliseBytestringPackage))],
run_command,
normalise_fun(join_normalisers(
normaliseArrayPackage,
normaliseArrayPackageKey,
normaliseBytestringPackage))],
run_command,
['$MAKE -s --no-print-directory safePkg01 ' + make_args])
# Fail since we enable package trust
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment