From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 0F8mE7r6k2DtcwAAgWs5BA (envelope-from ) for ; Thu, 06 May 2021 16:18:34 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id mNjfDrr6k2DYZAAAB5/wlQ (envelope-from ) for ; Thu, 06 May 2021 14:18:34 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [144.217.243.247]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 8838E2578D for ; Thu, 6 May 2021 16:18:33 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id B396B2716D; Thu, 6 May 2021 10:18:27 -0400 (EDT) X-Greylist: delayed 344 seconds by postgrey-1.36 at nmbug; Thu, 06 May 2021 10:18:24 EDT Received: from meesny.iki.fi (meesny.iki.fi [195.140.195.201]) by mail.notmuchmail.org (Postfix) with ESMTPS id 78A7727167 for ; Thu, 6 May 2021 10:18:24 -0400 (EDT) Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: too) by meesny.iki.fi (Postfix) with ESMTPSA id ACDEF20D0B; Thu, 6 May 2021 17:12:35 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1620310355; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=05kB54Z1sN6DquvosJHBPlT4wVuAu1AyWNP2EKmwTSY=; b=uJXyYAtgm0eNVUDeZEkAwfhLLHYvH6+egSDu2xYvDfBNBJHTI2Jn+SiIb5IoNjsWNVdOYl G6TNP4zVNTPdYqyY3sYiQcLEdRgcgLU1vL58xWP0hap3vhsrt0ngkESNQgWuHYstX/54R0 FK1Xd+w32aG91eDtDYsXuospNB5rUZ8= From: Tomi Ollila To: notmuch@notmuchmail.org Subject: [PATCH] test: say_color() in one write(2) Date: Thu, 6 May 2021 17:12:32 +0300 Message-Id: <20210506141232.24182-1-tomi.ollila@iki.fi> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=too smtp.mailfrom=tomi.ollila@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1620310355; a=rsa-sha256; cv=none; b=mifA2i+VKQwUpFoXm7s8lOHBHCzIrGn/Tig3qmy1rBaQg2gz9f5CK53bmT4sCDh4y2GqYB 9W5EuHwe9rOGHJ76ZF7KPMUQvTIx5EK+CqnTkuESC0uRrQeylXUsKYnAzOBvkPtQ9OxCm/ FOqL8oIRbn4+LeBrlLnhybLLwEaIZL0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1620310355; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=05kB54Z1sN6DquvosJHBPlT4wVuAu1AyWNP2EKmwTSY=; b=qu0JVaLC6CvaoEknAh4VgQ+gna5WY0cVvqC+0hhbrMa7AdhId4m9JNnj3p2FrxAInLrhFH 9uASJjpLEZsiNtPa+PzcJtwE6+ke7f9KRNsQ5XowZsgnmyQmmCN7LqLFXC08OJ7HPWkvF8 4QCUu9Q+EHzp3BvD3khaPo6lTfr5ZN0= Message-ID-Hash: CL5N7B2SP2OBNBAGZPKKKQQGESIPR3PF X-Message-ID-Hash: CL5N7B2SP2OBNBAGZPKKKQQGESIPR3PF X-MailFrom: tomi.ollila@iki.fi X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: tomi.ollila@iki.fi X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1620310713; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=AABvilm+jzy7KO8JHwVz4NkndgY3pTW1Bv+l7S7ES9I=; b=q4mtHqiMe2WD5TQm7CKOcx9z7JkLWDbo8HfbQM5hnySuv6/CV4WpduGVoVOupqLaYeBdWq fdvJ5PLaOrkbkk+8cuSjoLFHRM0QQhLejlzsFhJwIj/3cixqXib7oowzGMjuVgGgsQxo0h /pNzfnUxg8tYtd2geViiMhJZb9NXSmFbkMxU9j95DHTlauyonUUAA9TqYEcrrPLAgX20vu jmsyh//rqCRry9m61FgVc4aKhNmqUCZnYDMDI040opT9A8gyEnVKX10YW5mHDnR5pHpd/L F2bvoL7DP0z1zVPPVQxH5BkvsoPeAw4lsA0Xb8ivTbHYy7XSIsB9KnALvzrGgQ== ARC-Seal: i=2; s=key1; d=yhetil.org; t=1620310713; a=rsa-sha256; cv=fail; b=UqHHwUYvO7mic1F16f9qDsKyKZkP7Hi4+MS6ziWFHTsU6SEd4cT3C0FxvnuaZwRdzkhq3R EfVv5wfCs8Hgx2+i9kqChAsg7zMw31iNryjz60jTK4RBidpTzFMxPcKebSJJzWWCru/bT8 bI7+QLtIQlUU22EvMaApLsCfeBWGOFfUdMpM+k6BmvLKmtqYKBSHa/+G474R3N9j/hSOTL 154tzPE9hcRNsLEGwi+wJf6O1slktW+07QrKNWP+WH27+9vcW0oAe6YMWQqDDT61TiMf1t 7cxAskrY5TB5D9BvN149I2QOSvUuk5nh/LsuL19i5XCjWsnei/LeiLBTrT0NJQ== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=iki.fi header.s=meesny header.b=uJXyYAtg; arc=reject ("signature check failed: fail, {[1] = sig:iki.fi:reject}"); dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: 3.62 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=iki.fi header.s=meesny header.b=uJXyYAtg; arc=reject ("signature check failed: fail, {[1] = sig:iki.fi:reject}"); dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 8838E2578D X-Spam-Score: 3.62 X-Migadu-Scanner: scn0.migadu.com X-TUID: rKw6Koj074H4 say_color() used to call (builtin) printf (and tput(1) to stdout) several times, which caused attempts to write messages with color to have partial content (e.g. escape sequences) often intermixed with other tests when parallel tests were run. Now, with all output collected, then written out using one printf, all strings with color print out correctly ((at least short) write(2)'s appear to write out "atomically"). While at it, used only one tput(1) execution to determine whether color output works, and made bold/colors/sgr0 to tput(1) their values once per test. --- test/test-lib.sh | 61 +++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/test/test-lib.sh b/test/test-lib.sh index d46bb4c3..d7c96a93 100644 --- a/test/test-lib.sh +++ b/test/test-lib.sh @@ -201,56 +201,53 @@ do done if test -n "$debug"; then - print_subtest () { - printf " %-4s" "[$((test_count - 1))]" - } + fmt_subtest () { + printf -v $1 " %-4s" "[$((test_count - 1))]" + } else - print_subtest () { - true - } + fmt_subtest () { + printf -v $1 '' + } fi test -n "$COLORS_WITHOUT_TTY" || [ -t 1 ] || color= -if [ -n "$color" ] && [ "$ORIGINAL_TERM" != 'dumb' ] && ( - TERM=$ORIGINAL_TERM && - export TERM && - tput bold - tput setaf - tput sgr0 - ) >/dev/null 2>&1 +if [ -n "$color" ] && [ "$ORIGINAL_TERM" != 'dumb' ] && + tput -T "$ORIGINAL_TERM" -S <<<$'bold\nsetaf\nsgr0\n' >/dev/null 2>&1 then color=t else color= fi -if test -n "$color"; then +if test -n "$color" +then + # _tput run in subshell (``) only + _tput () { exec tput -T "$ORIGINAL_TERM" "$@"; } + unset BOLD RED GREEN BROWN SGR0 say_color () { - ( - TERM=$ORIGINAL_TERM - export TERM case "$1" in - error) tput bold; tput setaf 1;; # bold red - skip) tput bold; tput setaf 2;; # bold green - pass) tput setaf 2;; # green - info) tput setaf 3;; # brown - *) test -n "$quiet" && return;; + error) b=${BOLD=`_tput bold`} + c=${RED=`_tput setaf 1`} ;; # bold red + skip) b=${BOLD=`_tput bold`} + c=${GREEN=`_tput setaf 2`} ;; # bold green + pass) b= c=${GREEN=`_tput setaf 2`} ;; # green + info) b= c=${BROWN=`_tput setaf 3`} ;; # brown + *) b= c=; test -n "$quiet" && return ;; esac - shift - printf " " - printf "$@" - tput sgr0 - print_subtest - ) + f=$2 + shift 2 + sgr0=${SGR0=`_tput sgr0`} + fmt_subtest st + printf " ${b}${c}${f}${sgr0}${st}" "$@" } else say_color() { test -z "$1" && test -n "$quiet" && return - shift - printf " " - printf "$@" - print_subtest + f=$2 + shift 2 + fmt_subtest st + printf " ${f}${st}" "$@" } fi -- 2.25.1