commit 02db7b173a56839fbb69a0d861c731fb987df4df
parent c5bfe949dca7001f5e1d456b0c6aebef8fbe07c8
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date: Thu, 22 Jan 2026 11:10:19 +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.
Diffstat:
5 files changed, 49 insertions(+), 38 deletions(-)
diff --git a/tests/0035-dc.sh b/tests/0035-dc.sh
@@ -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:
@@ -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
@@ -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
@@ -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:
@@ -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
@@ -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
@@ -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:
@@ -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
@@ -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:
@@ -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
@@ -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
@@ -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
@@ -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:
@@ -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