URI: 
       tests: Use heredoc for diff - sbase - suckless unix tools
  HTML git clone git://git.suckless.org/sbase
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit eedc7522976945476fb4dbf9165d2c6057226c14
   DIR parent b3c479298c7cdba3213ec9ea17a99c64c51e25f8
  HTML Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
       Date:   Thu, 20 Nov 2025 16:47:11 +0100
       
       tests: Use heredoc for diff
       
       This simplifies the logic because it avoids the use of an additional
       temporary file. The cleanup function is added only to EXIT because
       in the way that it is written it works also in the case of signals.
       
       Diffstat:
         M tests/0001-echo.sh                  |      15 ++++++---------
         M tests/0002-printf.sh                |      37 +++++++++++++------------------
         M tests/0003-ed.sh                    |       2 +-
       
       3 files changed, 23 insertions(+), 31 deletions(-)
       ---
   DIR diff --git a/tests/0001-echo.sh b/tests/0001-echo.sh
       @@ -2,22 +2,19 @@
        
        set -e
        
       -tmp1=tmp1.$$
       -tmp2=tmp2.$$
       +tmp=tmp1.$$
        
        cleanup()
        {
                st=$?
       -        rm -f $tmp1 $tmp2
       +        rm -f $tmp
                exit $st
        }
        
       -trap cleanup EXIT HUP INT TERM
       +trap cleanup EXIT
        
       -cat <<'EOF' | tr -d '\n' > $tmp1
       +../echo -n --hello-- --world--! > $tmp
       +
       +tr -d '\n' <<'EOF' | diff -u - $tmp
        --hello-- --world--!
        EOF
       -
       -../echo -n --hello-- --world--! > $tmp2
       -
       -diff -u $tmp1 $tmp2
   DIR diff --git a/tests/0002-printf.sh b/tests/0002-printf.sh
       @@ -2,32 +2,17 @@
        
        set -e
        
       -exp1=tmp1.$$
       -exp2=tmp2.$$
       -res1=tmp3.$$
       -res2=tmp4.$$
       +res1=tmp1.$$
       +res2=tmp2.$$
        
        cleanup()
        {
                st=$?
       -        rm -f $exp1 $exp2 $res1 $res2
       +        rm -f $res1 $res2
                exit $st
        }
        
       -trap cleanup EXIT HUP INT TERM
       -
       -cat <<'EOF' > $exp1
       -123
       -0
       -foo
       -bar
       -+001   +2 +003 -400 
       -Expected failure
       -EOF
       -
       -cat <<'EOF' > $exp2
       -../printf: Missing format specifier.
       -EOF
       +trap cleanup EXIT
        
        (
                ../printf '123\n'
       @@ -40,5 +25,15 @@ EOF
                ../printf '%000' FOO || echo "Expected failure"
        ) > $res1 2> $res2
        
       -diff -u $exp1 $res1
       -diff -u $exp2 $res2
       +diff -u - $res1 <<'EOF'
       +123
       +0
       +foo
       +bar
       ++001   +2 +003 -400 
       +Expected failure
       +EOF
       +  
       +diff -u - $res2 <<'EOF'
       +../printf: Missing format specifier.
       +EOF
   DIR diff --git a/tests/0003-ed.sh b/tests/0003-ed.sh
       @@ -12,7 +12,7 @@ cleanup()
                exit $st
        }
        
       -trap cleanup EXIT HUP INT TERM
       +trap cleanup EXIT
        
        cat <<EOF >$tmp1
        foo