shunit2 icon indicating copy to clipboard operation
shunit2 copied to clipboard

tput error inside Docker

Open mjsteinbaugh opened this issue 4 years ago • 5 comments

Hi, I'm seeing this error pop up inside Docker images using shunit2 for unit tests:

tput: No value for $TERM and no -T specified
/usr/local/bin/shunit2: line 840: [: : integer expression expected

It seems like this issue has popped up for CI tests previously, as reported in #86 and #88. This post also seems to be relevant.

I'm trying to set ARG TERM=xterm-256color inside my Dockerfile to see if this fixes the issue and will report back.

Any advice or ideas on how to handle this issue? Thanks!

mjsteinbaugh avatar Jun 21 '20 21:06 mjsteinbaugh

Can you try with the latest version from HEAD, and report back whether this error still appears?

kward avatar Oct 23 '21 14:10 kward

@kward Sure I'll try to test this out and get back to you

mjsteinbaugh avatar Oct 23 '21 14:10 mjsteinbaugh

Hi @kward ! I have this error on my Debian package: https://salsa.debian.org/debian/shunit2/-/jobs/3587857#L672

It's because tput is missing. It prevents the new version to enter debian as it breaks most of the projects using shunit2. See: https://tracker.debian.org/pkg/shunit2

I am going to craft a patch for this, can you also have a look ?

williamdes avatar Nov 28 '22 14:11 williamdes

Edit: tput exists but it says tput: unknown terminal "unknown"

williamdes avatar Nov 28 '22 14:11 williamdes

See: https://opensource.apple.com/source/ncurses/ncurses-7/ncurses/progs/tput.c.auto.html

I did some debug

echo "colors 1: $(${SHUNIT_CMD_TPUT} colors)"
echo "colors 2: $(${SHUNIT_CMD_TPUT} colors 2>/dev/null)"
  if command [ $? -eq 0 ]; then
    echo "c: $?"
  else
    echo "cc: 16"
  fi

${SHUNIT_CMD_TPUT} colors 2>/dev/null
echo "c: $?"

${SHUNIT_CMD_TPUT} colors
echo "c: $?"
tput: No value for $TERM and no -T specified
colors 1: 
colors 2: 
c: 0
c: 2
tput: No value for $TERM and no -T specified
c: 2

The fix:

From: William Desportes <[email protected]>
Date: Mon, 28 Nov 2022 15:42:19 +0100
Subject: Fix error with tput when $TERM is not set

Origin: vendor
Forwarded: https://github.com/kward/shunit2/issues/134
---
 shunit2 | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/shunit2 b/shunit2
index 6239683..b9b4603 100755
--- a/shunit2
+++ b/shunit2
@@ -1027,6 +1027,12 @@ _shunit_configureColor() {
 
 # colors returns the number of supported colors for the TERM.
 _shunit_colors() {
+  # Avoid: tput: No value for $TERM and no -T specified
+  if command [ -z "${TERM:-}" ]; then
+    echo 16
+    return
+  fi
+
   _shunit_tput_=`${SHUNIT_CMD_TPUT} colors 2>/dev/null`
   if command [ $? -eq 0 ]; then
     echo "${_shunit_tput_}"

williamdes avatar Nov 28 '22 18:11 williamdes