]> git.draconx.ca Git - dxcommon.git/commitdiff
at-compat: Add diff workaround for DOS/Windows hosts.
authorNick Bowler <nbowler@draconx.ca>
Fri, 26 Jan 2024 06:01:01 +0000 (01:01 -0500)
committerNick Bowler <nbowler@draconx.ca>
Sat, 27 Jan 2024 03:52:10 +0000 (22:52 -0500)
Kind of ugly, but we need to hook at_diff in order to deal with the
fact that programs under test might generate DOS line endings but the
shell and utilities do not.

atlocal.in
snippet/at-compat.at

index da16608153a33786b6c2acef84d91eab84643ca2..865ca656f835d9f6ca28fd90a945109c03a1d1bb 100644 (file)
@@ -3,3 +3,4 @@
 : "${CC=@CC@}"
 : "${EXEEXT=@EXEEXT@}"
 : "${TEST_SHELL=@SHELL@}"
+: "${host_os=@host_os@}"
index 6eb6d97042a6dcd5f4d5bbbeda055c206fc4550a..2457d22aaa5f8ac990d4c244bb079a2c3407f76c 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright © 2023 Nick Bowler
+# Copyright © 2023-2024 Nick Bowler
 #
 # Autotest monkey patches to fix some issues.  This should be included before
 # expanding AT_INIT.
@@ -7,29 +7,57 @@
 # This is free software: you are free to do what the fuck you want to.
 # There is NO WARRANTY, to the extent permitted by law.
 
+m4_define([DX_PATCH_MACRO], [m4_ifdef([$1],
+  [m4_define([$1], m4_bpatsubst(m4_dquote(m4_defn([$1])), [$2], [$3]))])])
+
 # In a shell function, redirections on : are not correctly handled by some
 # shells, including Solaris 10 /bin/sh.  Work around the problem using 'eval'.
 # See the following Autoconf patch description for further details:
 #
 #   https://lists.gnu.org/archive/html/autoconf-patches/2021-03/msg00000.html
-m4_define([AT_INIT],
-  m4_bpatsubst(m4_dquote(m4_defn([AT_INIT])),
-    [^\( *\)\(: >"\$at_stdout".*$\)], [\1eval '\2']))
+DX_PATCH_MACRO([AT_INIT],
+  [^\( *\)\(: >"\$at_stdout".*$\)],
+  [\1eval '\2'])
 
 # Parsing of command-line options with arguments is busted in the two-argument
 # form if the option name contains a hyphen.  Apply a fix for this bug.  See
 # the following Autoconf patch description for further details:
 #
 #   https://lists.gnu.org/archive/html/autoconf-patches/2020-02/msg00000.html
-m4_define([_AT_ARG_OPTION],
-  m4_bpatsubst(m4_dquote(m4_defn([_AT_ARG_OPTION])),
-    [at_prev=--AT_first_option_tr], [at_prev=--AT_first_option]))
+DX_PATCH_MACRO([_AT_ARG_OPTION],
+  [at_prev=--AT_first_option_tr],
+  [at_prev=--AT_first_option])
 
 # The computation of the elapsed time can crash the testsuite on DJGPP because
 # in this environment date +%s can return a string that starts with a 0, which
 # bash interprets as octal digits in arithmetic expansions.  With a working
 # GNU-like date +%s the output should never start with a 0 so just reject
 # anything that does.
-m4_define([AT_INIT],
-  m4_bpatsubst(m4_dquote(m4_defn([AT_INIT])),
-    [\[0-9]\*,\[0-9]\*], [[1-9][0-9]*,[1-9][0-9]*]))
+DX_PATCH_MACRO([AT_INIT],
+  [\[0-9]\*,\[0-9]\*],
+  [[1-9][0-9]*,[1-9][0-9]*])
+
+# When testing DOS/Windows applications we cannot assume that the line endings
+# actually output by the programs under test will match the output of the shell.
+#
+# For example, the MSYS bash shell and most utilities generate UNIX-style line
+# endings while programs output DOS-style.  A similar situation occurs when
+# running the test suite on a POSIX host while the tested applications are run
+# using something like wine.
+#
+# So on DOS-like hosts, if a trailing CR is seen by 'sed' from the test output,
+# remove it.  The "left" file, which is the expected output, is left unchanged.
+#
+# For this to work, the package must arrange for host_os to be defined in the
+# test suite (e.g., via atlocal).
+DX_PATCH_MACRO([AT_INIT],
+  [at_diff=.*
+fi], [\&
+
+at_fn_diff_dosnl () {
+  sed 's/\r$//' "$[2]" >"$[2].nl" &&
+    $at_diff_ "$[1]" "$[2].nl" && rm -f "$[2].nl"
+}
+
+AS_CASE([$host_os],
+  [mingw*|msdos*], [at_diff_=$at_diff; at_diff=at_fn_diff_dosnl])])