]])
AT_CLEANUP
+
+m4_divert_push([PREPARE_TESTS])dnl
+test_fix_gnulib () {
+ $PERL -e 'my $x = 42; exit $x;'; test $? = 42 || exit 77
+ $PERL -f "$srcdir/scripts/fix-gnulib.pl" "$@"
+}
+test_gnulib_mk () {
+ echo; sed -n -f - "$srcdir/tests/data/gnulib.mk" <<EOF
+/^## begin gnulib module $1/,/^## end gnulib module $1/p
+EOF
+}
+m4_divert_pop([PREPARE_TESTS])
+
+AT_SETUP([fix-gnulib.pl SED_HEADER variables])
+
+test_gnulib_mk gen-header >test.mk.in
+AT_CHECK([grep SED_HEADER test.mk.in >expout || exit 99])
+AT_CHECK([test_fix_gnulib -i test.mk.in -o test.mk || exit
+grep SED_HEADER test.mk], [0], [expout])
+
+AT_CLEANUP
+
+AT_SETUP([fix-gnulib.pl %reldir% substitution])
+
+test_gnulib_mk sys_types >test.mk.in
+AT_CHECK([grep '%reldir%' test.mk.in >/dev/null || exit 99])
+
+sed -n -f - test.mk.in >expout <<'EOF'
+${G;p;b}
+/^## begin gnulib/,/^## end gnulib/!b
+/^#/{p;b}
+s|(srcdir)|(top_srcdir)|
+s|%reldir%|lib|
+s|BUILT_SOURCES|gnulib_core_headers|
+s|sys[[/_]]|lib/&|g
+/^MOSTLYCLEANFILES/{h;b}
+p
+EOF
+
+AT_CHECK([test_fix_gnulib -i test.mk.in -o test.mk || exit
+sed -n -e '/^## begin gnulib/,/^## end gnulib/p' \
+ -e '/CLEANFILES/p' test.mk],
+[0], [expout])
+
+AT_CLEANUP