[hackers] [sbase] tests: Be deterministic about stderr || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Thu, 22 Jan 2026 11:11:58 +0100 (CET)

commit 02db7b173a56839fbb69a0d861c731fb987df4df
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.net>
AuthorDate: Thu Jan 22 11:10:19 2026 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.net>
CommitDate: Thu Jan 22 11:10:19 2026 +0100

    tests: Be deterministic about stderr
    
    Different libcsuse different criteria about buffering stderr
    and it created problems in tests merging stdout and stderr.
    To avoid the problem just redirect stderr to a different file
    and merge them later using cat in a subshell.

diff --git a/tests/0035-dc.sh b/tests/0035-dc.sh
index 646d019..214e5b7 100755
--- a/tests/0035-dc.sh
+++ b/tests/0035-dc.sh
_AT_@ -1,24 +1,22 @@
 #!/bin/sh
 
-tmp=$$.tmp
+tmp1=$$.tmp1
+tmp2=$$.tmp2
 
-trap 'rm -f $tmp' EXIT
+trap 'rm -f $tmp1 $tmp2' EXIT
 trap 'exit $?' HUP INT TERM
 
 # Test negative number sqrt - should produce error message and push 0
 # Test negative numbers: integers, fractions, odd and even fraction digits
-$EXEC ../dc <<EOF >$tmp 2>&1
+($EXEC ../dc <<EOF 2>$tmp2
 [test 1:]pc _1vp
 [test 2:]pc _4vp
 [test 3:]pc _.5vp
 [test 4:]pc _.25vp
 EOF
+cat $tmp2) > $tmp1
 
-diff -u - $tmp <<'EOF'
-../dc: square root of negative number
-../dc: square root of negative number
-../dc: square root of negative number
-../dc: square root of negative number
+diff -u - $tmp1 <<'EOF'
 test 1:
 0
 test 2:
_AT_@ -27,4 +25,8 @@ test 3:
 0
 test 4:
 0
+../dc: square root of negative number
+../dc: square root of negative number
+../dc: square root of negative number
+../dc: square root of negative number
 EOF
diff --git a/tests/0039-dc.sh b/tests/0039-dc.sh
index 12a0d6a..dea59dd 100755
--- a/tests/0039-dc.sh
+++ b/tests/0039-dc.sh
_AT_@ -1,12 +1,13 @@
 #!/bin/sh
 
-tmp=$$.tmp
+tmp1=$$.tmp1
+tmp2=$$.tmp2
 
-trap 'rm -f $tmp' EXIT
+trap 'rm -f $tmp1 $tmp2' EXIT
 trap 'exit $?' HUP INT TERM
 
 # Test s, l, S, L register commands
-$EXEC ../dc <<'EOF' >$tmp 2>&1
+($EXEC ../dc <<'EOF' 2>$tmp2
 [test 1:]pc 5 sa la p c
 [test 2:]pc lz p c
 [test 3:]pc 1 sb 2 lb p c
_AT_@ -35,12 +36,9 @@ $EXEC ../dc <<'EOF' >$tmp 2>&1
 [test 26:]pc sC
 [test 27:]pc SD
 EOF
+cat $tmp2) > $tmp1
 
-diff -u - $tmp <<'EOF'
-../dc: stack register 'A' (101) is empty
-../dc: stack register 'B' (102) is empty
-../dc: stack empty
-../dc: stack empty
+diff -u - $tmp1 <<'EOF'
 test 1:
 5
 test 2:
_AT_@ -98,4 +96,8 @@ test 24:
 test 25:
 test 26:
 test 27:
+../dc: stack register 'A' (101) is empty
+../dc: stack register 'B' (102) is empty
+../dc: stack empty
+../dc: stack empty
 EOF
diff --git a/tests/0040-dc.sh b/tests/0040-dc.sh
index c92c5c8..702ece4 100755
--- a/tests/0040-dc.sh
+++ b/tests/0040-dc.sh
_AT_@ -1,15 +1,16 @@
 #!/bin/sh
 
-tmp=$$.tmp
+tmp1=$$.tmp1
+tmp2=$$.tmp2
 
-trap 'rm -f $tmp' EXIT
+trap 'rm -f $tmp1 $tmp2' EXIT
 trap 'exit $?' HUP INT TERM
 
 # Test x, >, !>, <, !<, =, != commands
 # Note: dc pops values and compares: first_popped OP second_popped
 # So "3 5 >a" pops 5 then 3, checks 5 > 3 (true)
 # And "5 3 >a" pops 3 then 5, checks 3 > 5 (false)
-$EXEC ../dc <<'EOF' >$tmp 2>&1
+($EXEC ../dc <<'EOF' 2>$tmp2
 [test 1:]pc [42p]x c
 [test 2:]pc 5 x p c
 [test 3:]pc []x c
_AT_@ -52,11 +53,9 @@ $EXEC ../dc <<'EOF' >$tmp 2>&1
 [test 40:]pc [[NO]p]sa 5 >a
 [test 41:]pc [[NO]p]sa >a
 EOF
+cat $tmp2) > $tmp1
 
-diff -u - $tmp <<'EOF'
-../dc: stack empty
-../dc: stack empty
-../dc: stack empty
+diff -u - $tmp1 <<'EOF'
 test 1:
 42
 test 2:
_AT_@ -132,4 +131,7 @@ test 38:
 test 39:
 test 40:
 test 41:
+../dc: stack empty
+../dc: stack empty
+../dc: stack empty
 EOF
diff --git a/tests/0041-dc.sh b/tests/0041-dc.sh
index 8b5c0fb..9562182 100755
--- a/tests/0041-dc.sh
+++ b/tests/0041-dc.sh
_AT_@ -1,15 +1,12 @@
 #!/bin/sh
 
-tmp=$$.tmp
+tmp1=$$.tmp1
+tmp2=$$.tmp2
 
-trap 'rm -f $tmp' EXIT
+trap 'rm -f $tmp1 $tmp2' EXIT
 trap 'exit $?' HUP INT TERM
 
-cat <<'EOF' > $tmp
-../dc: stack empty
-../dc: Q command argument exceeded string execution depth
-../dc: Q command requires a number >= 0
-../dc: Q command argument exceeded string execution depth
+cat <<'EOF' > $tmp1
 test 1:
 test 2:
 test 3:
_AT_@ -66,9 +63,14 @@ test 19:
 before-q
 test 20:
 equal
+../dc: stack empty
+../dc: Q command argument exceeded string execution depth
+../dc: Q command requires a number >= 0
+../dc: Q command argument exceeded string execution depth
 EOF
 
-($EXEC ../dc <<'EOF'
+(exec 2>$tmp2
+$EXEC ../dc <<'EOF'
 [test 1:]pc Q
 [test 2:]pc 1Q
 [test 3:]pc _1Q
_AT_@ -98,4 +100,5 @@ EOF
 $EXEC ../dc <<'EOF'
 [test 20:]pc [[equal]p q]sa 5 5 =a [not-printed]p
 EOF
-) 2>&1 | diff -u - $tmp
+cat $tmp2
+) | diff -u - $tmp1
diff --git a/tests/0042-dc.sh b/tests/0042-dc.sh
index cf9e835..d20a8f3 100755
--- a/tests/0042-dc.sh
+++ b/tests/0042-dc.sh
_AT_@ -1,12 +1,13 @@
 #!/bin/sh
 
-tmp=$$.tmp
+tmp1=$$.tmp1
+tmp2=$$.tmp2
 
-trap 'rm -f $tmp' EXIT
+trap 'rm -f $tmp1 $tmp2' EXIT
 trap 'exit $?' HUP INT TERM
 
 # Test : and ; array commands
-$EXEC ../dc <<'EOF' >$tmp 2>&1
+($EXEC ../dc <<'EOF' 2>$tmp2
 [test 1:]pc 42 0:a 0;a p c
 [test 2:]pc 10 0:b 20 1:b 30 2:b 0;b p 1;b p 2;b p c
 [test 3:]pc 100 5:c 5;c p c
_AT_@ -32,10 +33,9 @@ $EXEC ../dc <<'EOF' >$tmp 2>&1
 [test 23:]pc 10 0:v 20 1:v 1 Sv 2 Sv Lv p Lv p 0;v p 1;v p c
 [test 24:]pc 100 5:w 1 Sw 200 5:w 2 Sw 300 5:w 5;w p Lw p 5;w p Lw p 5;w p c
 EOF
+cat $tmp2) > $tmp1
 
-diff -u - $tmp <<'EOF'
-../dc: array index must fit in a positive integer
-../dc: array index must fit in a positive integer
+diff -u - $tmp1 <<'EOF'
 test 1:
 42
 test 2:
_AT_@ -104,4 +104,6 @@ test 24:
 200
 1
 100
+../dc: array index must fit in a positive integer
+../dc: array index must fit in a positive integer
 EOF
Received on Thu Jan 22 2026 - 11:11:58 CET

This archive was generated by hypermail 2.3.0 : Thu Jan 22 2026 - 11:24:34 CET