From patchwork Fri Dec 6 13:08:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11276111 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B6E2513B6 for ; Fri, 6 Dec 2019 13:08:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 949A22075C for ; Fri, 6 Dec 2019 13:08:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HW8Wpye5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726312AbfLFNIc (ORCPT ); Fri, 6 Dec 2019 08:08:32 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:50850 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726246AbfLFNIa (ORCPT ); Fri, 6 Dec 2019 08:08:30 -0500 Received: by mail-wm1-f66.google.com with SMTP id p9so7786579wmg.0 for ; Fri, 06 Dec 2019 05:08:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=dk4jHk9V8pKAO9UUtocjKNsOEWJO42Db7pR93uzxgG8=; b=HW8Wpye5UsXzKD0D/AntCvESL8d/zVvvtFatVXeIgIwpAOJu5FSWnGS5OtjwPzUKsH h55bIDKWfbsFVX6MXcSYor3cHUwcBS9fwhZ+yvgnZxQrWLV2YrTKTlGxNNbCs4xlBnqE h0gmULSFbMjZ5mTCSZT0/qiha7h3Ydl6HgcMWw7jlimMQp63NBRg9pYjqGwgpfpnLbY9 +LqJkiLdVGcBCdlZB8yysno2/MT7cVvmWMF5dclBDqJMmtA43K+DW+uZIYVbnoVBCAyO Tc5b6STfRusgHo3AZTUIpsKBB7LBcQdcB9CfVHa8L+j/4Cvxk0oFocfQE6Ss8IJlNgAU w/bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=dk4jHk9V8pKAO9UUtocjKNsOEWJO42Db7pR93uzxgG8=; b=h7PFjkBL87+ptX3ORQA6gEtL5EehLAJQ1HkZsmlRSVYR0zTKrVBLn3kbt5JyBCJa58 m+lJbmdrXRqZ8N9+4f431U/Xfi8TZg1MA4gWwf+lcB5GnJSdWPRqhEQ8ej/tYBWrYQiw KBfVw56F7HBKgH44H+eruV76PhKpCXGWYUcVb9+zgi6Fb9UqgXknFHySw5mu3Op2KVTs PoopOI2rNJXWVkcOkb8NLjg8z+ma0bLlre0eZ+01NAu42915+dw8PMRqG34UI3MbAIzX dSmzsGMGB7VIwC5BG8mwB/pG7Mty3wPolmySssFJxCk5CMwEbixR+mDEsIXpvbpnlHf6 qEQQ== X-Gm-Message-State: APjAAAU1GY1ZnvWHZR4hvbtNnyfK9sl6FEgRbVwIJQHrgJxryoxwcAQv bkVNzE+Jgwge9ID3VRtARLIBrlQW X-Google-Smtp-Source: APXvYqzqNq8RUde4XVK/ZmSR4RwBCuKxpBizkI1pDiIZqb5dqiEkLzQhv5Ngw5UgZ2PqcACDjhF9zw== X-Received: by 2002:a7b:cc81:: with SMTP id p1mr10831000wma.62.1575637708456; Fri, 06 Dec 2019 05:08:28 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id x18sm15963252wrr.75.2019.12.06.05.08.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Dec 2019 05:08:28 -0800 (PST) Message-Id: In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Date: Fri, 06 Dec 2019 13:08:20 +0000 Subject: [PATCH 2/7] t3701: avoid depending on the TTY prerequisite Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Junio C Hamano , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin The TTY prerequisite is a rather heavy one: it not only requires Perl to work, but also the IO/Pty.pm module (with native support, and it requires pseudo terminals, too). In particular, test cases marked with the TTY prerequisite would be skipped in Git for Windows' SDK. In the case of `git add -p`, we do not actually need that big a hammer, as we do not want to test any functionality that requires a pseudo terminal; all we want is for the interactive add command to use color, even when being called from within the test suite. And we found exactly such a trick earlier already: when we added a test case to verify that the main loop of `git add -i` is colored appropriately. Let's use that trick instead of the TTY prerequisite. While at it, we avoid the pipes, as we do not want a SIGPIPE to break the regression test cases (which will be much more likely when we do not run everything through Perl because that is inherently slower). Signed-off-by: Johannes Schindelin --- t/t3701-add-interactive.sh | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index 4da99e27af..793ce28297 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -23,6 +23,17 @@ diff_cmp () { test_cmp "$1.filtered" "$2.filtered" } +# This function uses a trick to manipulate the interactive add to use color: +# the `want_color()` function special-cases the situation where a pager was +# spawned and Git now wants to output colored text: to detect that situation, +# the environment variable `GIT_PAGER_IN_USE` is set. However, color is +# suppressed despite that environment variable if the `TERM` variable +# indicates a dumb terminal, so we set that variable, too. + +force_color () { + env GIT_PAGER_IN_USE=true TERM=vt100 "$@" +} + test_expect_success 'setup (initial)' ' echo content >file && git add file && @@ -451,35 +462,38 @@ test_expect_success 'patch mode ignores unmerged entries' ' diff_cmp expected diff ' -test_expect_success TTY 'diffs can be colorized' ' +test_expect_success 'diffs can be colorized' ' git reset --hard && echo content >test && - printf y | test_terminal git add -p >output 2>&1 && + printf y >y && + force_color git add -p >output 2>&1 test && test_config interactive.diffFilter "sed s/^/foo:/" && - printf y | test_terminal git add -p >output 2>&1 && + printf y >y && + force_color git add -p >output 2>&1 test && test_config interactive.diffFilter "echo too-short" && - printf y | test_must_fail test_terminal git add -p + printf y >y && + test_must_fail force_color git add -p What now>$SP Bye. EOF - test_write_lines h | GIT_PAGER_IN_USE=true TERM=vt100 git add -i >actual.colored && + test_write_lines h | force_color git add -i >actual.colored && test_decode_color actual && test_i18ncmp expect actual '