kward / shunit2

shUnit2 is a xUnit based unit test framework for Bourne based shell scripts.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tput error inside Docker

mjsteinbaugh opened this issue · 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!

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

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

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 ?

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

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 <williamdes@wdes.fr>
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_}"