]> git.draconx.ca Git - dxcommon.git/blob - snippet/at-compat.at
DX_C_ALIGNAS: Work around bash-5 parsing bug.
[dxcommon.git] / snippet / at-compat.at
1 # Copyright © 2023-2024 Nick Bowler
2 #
3 # Autotest monkey patches to fix some issues.  This should be included before
4 # expanding AT_INIT.
5 #
6 # License WTFPL2: Do What The Fuck You Want To Public License, version 2.
7 # This is free software: you are free to do what the fuck you want to.
8 # There is NO WARRANTY, to the extent permitted by law.
9
10 m4_define([DX_PATCH_MACRO], [m4_ifdef([$1],
11   [m4_define([$1], m4_bpatsubst(m4_dquote(m4_defn([$1])), [$2], [$3]))])])
12
13 # In a shell function, redirections on : are not correctly handled by some
14 # shells, including Solaris 10 /bin/sh.  Work around the problem using 'eval'.
15 # See the following Autoconf patch description for further details:
16 #
17 #   https://lists.gnu.org/archive/html/autoconf-patches/2021-03/msg00000.html
18 DX_PATCH_MACRO([AT_INIT],
19   [^\( *\)\(: >"\$at_stdout".*$\)],
20   [\1eval '\2'])
21
22 # Parsing of command-line options with arguments is busted in the two-argument
23 # form if the option name contains a hyphen.  Apply a fix for this bug.  See
24 # the following Autoconf patch description for further details:
25 #
26 #   https://lists.gnu.org/archive/html/autoconf-patches/2020-02/msg00000.html
27 DX_PATCH_MACRO([_AT_ARG_OPTION],
28   [at_prev=--AT_first_option_tr],
29   [at_prev=--AT_first_option])
30
31 # The computation of the elapsed time can crash the testsuite on DJGPP because
32 # in this environment date +%s can return a string that starts with a 0, which
33 # bash interprets as octal digits in arithmetic expansions.  With a working
34 # GNU-like date +%s the output should never start with a 0 so just reject
35 # anything that does.
36 DX_PATCH_MACRO([AT_INIT],
37   [\[0-9]\*,\[0-9]\*],
38   [[1-9][0-9]*,[1-9][0-9]*])
39
40 # When testing DOS/Windows applications we cannot assume that the line endings
41 # actually output by the programs under test will match the output of the shell.
42 #
43 # For example, the MSYS bash shell and most utilities generate UNIX-style line
44 # endings while programs output DOS-style.  A similar situation occurs when
45 # running the test suite on a POSIX host while the tested applications are run
46 # using something like wine.
47 #
48 # So on DOS-like hosts, if a trailing CR is seen by 'sed' from the test output,
49 # remove it.  The "left" file, which is the expected output, is left unchanged.
50 #
51 # For this to work, the package must arrange for host_os to be defined in the
52 # test suite (e.g., via atlocal).
53 DX_PATCH_MACRO([AT_INIT],
54   [at_diff=.*
55 fi], [\&
56
57 at_fn_diff_dosnl () {
58   sed 's/\r$//' "$[2]" >"$[2].nl" &&
59     $at_diff_ "$[1]" "$[2].nl" && rm -f "$[2].nl"
60 }
61
62 AS_CASE([$host_os],
63   [mingw*|msdos*], [at_diff_=$at_diff; at_diff=at_fn_diff_dosnl])])