From: Nick Bowler Date: Fri, 26 Jan 2024 06:01:01 +0000 (-0500) Subject: at-compat: Add diff workaround for DOS/Windows hosts. X-Git-Url: https://git.draconx.ca/gitweb/dxcommon.git/commitdiff_plain/9748f358ba2d6c9c732d5e12006255d45226328e at-compat: Add diff workaround for DOS/Windows hosts. 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. --- diff --git a/atlocal.in b/atlocal.in index da16608..865ca65 100644 --- a/atlocal.in +++ b/atlocal.in @@ -3,3 +3,4 @@ : "${CC=@CC@}" : "${EXEEXT=@EXEEXT@}" : "${TEST_SHELL=@SHELL@}" +: "${host_os=@host_os@}" diff --git a/snippet/at-compat.at b/snippet/at-compat.at index 6eb6d97..2457d22 100644 --- a/snippet/at-compat.at +++ b/snippet/at-compat.at @@ -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/ $//' "$[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])])