From patchwork Tue Dec 31 10:15:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin via GitGitGadget X-Patchwork-Id: 11313927 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 23A891398 for ; Tue, 31 Dec 2019 10:15:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E7DFD206D9 for ; Tue, 31 Dec 2019 10:15:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ujf/2v0l" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726674AbfLaKPS (ORCPT ); Tue, 31 Dec 2019 05:15:18 -0500 Received: from mail-ed1-f42.google.com ([209.85.208.42]:43551 "EHLO mail-ed1-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726334AbfLaKPR (ORCPT ); Tue, 31 Dec 2019 05:15:17 -0500 Received: by mail-ed1-f42.google.com with SMTP id dc19so34898029edb.10 for ; Tue, 31 Dec 2019 02:15:16 -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=mamBTIpI6RUiZZQUNzSTGXXJMrKd9H7YNNiekVfn2Sg=; b=ujf/2v0lrZPMMTT/EWtY/4yx2yaTgo2RdcCYj//VTfoVc2ktptgs/QbxA/Qrvvm1HY BvGPeIcPMlQrR4KCa2e9f2b4WmiKhRBQCcwoKgtuzm6HE2sguDaMyg1odPGYpUTvimhE MlYysJd9ihtNingbrA0ye1JuliqFn/UwM8P4Ihg/0Bh7zWLRlaHDiugZoAXTiHmik46P pC9dXzQNhRI76l9D+3hMBJqhIVnw1X5kYD6py8XL/63E0ONLSasukLP9AYMXQJ14tjtK drwT0w58q8Yq4ZmwsD8CkkJDph6uhB1LixYKbAL4OeAjVmKjLhjGJE2BFY3M4ZYWZkjk 8Hkw== 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=mamBTIpI6RUiZZQUNzSTGXXJMrKd9H7YNNiekVfn2Sg=; b=T1lhm0WVWmSKUp+UQNRRflx/b2E8qP4H2lStaRNNLSj1hBeHA4/s+fNpbf6tNvvX5c amfCNgDAgs+vtHfF0fzLg8pnRqRUq4WwQLfk+DfYRruSstiTil3cX7ANHtnTBqu50C03 zAMpI6b6H5V5DW8P7A11Z1Asx381C6sXscX0AARgf9l/H47A6KT3C/Vw//1dILz9f9gr mYHsGHUYdcjYQbj+QYIzLaj620sYUyqur2/GH1KuuaH5R7GyAIF6XzFI1mWoiTNaE1lH n5ljEG/r/xLXQGKGSTxtlwogUISzRgEQLn7AQTI1ANh6I0117XNwRPqdh+hMWs5zPir1 CwwA== X-Gm-Message-State: APjAAAV6vIXzkfkX7M5wiUeO6q5rZSHMpUX3rPApaHn6KWG/p+dFCxIa FoQhWb8j3nU/IB4xrRBTdzrXbTel X-Google-Smtp-Source: APXvYqyaXeP2O28Wyt/n6eAncVtevtA+5xfeYB0iYGEIi4Ml8FI1DKbp71fjU127aAux9uhpViR4Uw== X-Received: by 2002:aa7:cac7:: with SMTP id l7mr74952491edt.25.1577787315048; Tue, 31 Dec 2019 02:15:15 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u26sm6096425ejj.7.2019.12.31.02.15.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 31 Dec 2019 02:15:14 -0800 (PST) Message-Id: In-Reply-To: References: From: "Alexandr Miloslavskiy via GitGitGadget" Date: Tue, 31 Dec 2019 10:15:11 +0000 Subject: [PATCH v4 1/3] t: fix quotes tests for --pathspec-from-file Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Nieder , Eric Sunshine , Alexandr Miloslavskiy , Junio C Hamano , Alexandr Miloslavskiy Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Alexandr Miloslavskiy While working on the next patch, I also noticed that quotes testing via `"\"file\\101.t\""` was somewhat incorrect: I escaped `\` one time while I had to escape it two times! Tests still worked due to `"` being preserved which in turn prevented pathspec from matching files. Fix this by using here-doc instead. Signed-off-by: Alexandr Miloslavskiy --- t/t2026-checkout-pathspec-file.sh | 11 +++++++++-- t/t2072-restore-pathspec-file.sh | 11 +++++++++-- t/t3704-add-pathspec-file.sh | 11 +++++++++-- t/t7107-reset-pathspec-file.sh | 12 +++++++++--- t/t7526-commit-pathspec-file.sh | 11 +++++++++-- 5 files changed, 45 insertions(+), 11 deletions(-) diff --git a/t/t2026-checkout-pathspec-file.sh b/t/t2026-checkout-pathspec-file.sh index f62fd27440..adad71f631 100755 --- a/t/t2026-checkout-pathspec-file.sh +++ b/t/t2026-checkout-pathspec-file.sh @@ -109,7 +109,11 @@ test_expect_success 'CRLF delimiters' ' test_expect_success 'quotes' ' restore_checkpoint && - printf "\"file\\101.t\"" | git checkout --pathspec-from-file=- HEAD^1 && + cat >list <<-\EOF && + "file\101.t" + EOF + + git checkout --pathspec-from-file=list HEAD^1 && cat >expect <<-\EOF && M fileA.t @@ -120,7 +124,10 @@ test_expect_success 'quotes' ' test_expect_success 'quotes not compatible with --pathspec-file-nul' ' restore_checkpoint && - printf "\"file\\101.t\"" >list && + cat >list <<-\EOF && + "file\101.t" + EOF + test_must_fail git checkout --pathspec-from-file=list --pathspec-file-nul HEAD^1 ' diff --git a/t/t2072-restore-pathspec-file.sh b/t/t2072-restore-pathspec-file.sh index db58e83735..b407f6b779 100755 --- a/t/t2072-restore-pathspec-file.sh +++ b/t/t2072-restore-pathspec-file.sh @@ -109,7 +109,11 @@ test_expect_success 'CRLF delimiters' ' test_expect_success 'quotes' ' restore_checkpoint && - printf "\"file\\101.t\"" | git restore --pathspec-from-file=- --source=HEAD^1 && + cat >list <<-\EOF && + "file\101.t" + EOF + + git restore --pathspec-from-file=list --source=HEAD^1 && cat >expect <<-\EOF && M fileA.t @@ -120,7 +124,10 @@ test_expect_success 'quotes' ' test_expect_success 'quotes not compatible with --pathspec-file-nul' ' restore_checkpoint && - printf "\"file\\101.t\"" >list && + cat >list <<-\EOF && + "file\101.t" + EOF + test_must_fail git restore --pathspec-from-file=list --pathspec-file-nul --source=HEAD^1 ' diff --git a/t/t3704-add-pathspec-file.sh b/t/t3704-add-pathspec-file.sh index 3cfdb669b7..61b6e51009 100755 --- a/t/t3704-add-pathspec-file.sh +++ b/t/t3704-add-pathspec-file.sh @@ -97,7 +97,11 @@ test_expect_success 'CRLF delimiters' ' test_expect_success 'quotes' ' restore_checkpoint && - printf "\"file\\101.t\"" | git add --pathspec-from-file=- && + cat >list <<-\EOF && + "file\101.t" + EOF + + git add --pathspec-from-file=list && cat >expect <<-\EOF && A fileA.t @@ -108,7 +112,10 @@ test_expect_success 'quotes' ' test_expect_success 'quotes not compatible with --pathspec-file-nul' ' restore_checkpoint && - printf "\"file\\101.t\"" >list && + cat >list <<-\EOF && + "file\101.t" + EOF + test_must_fail git add --pathspec-from-file=list --pathspec-file-nul ' diff --git a/t/t7107-reset-pathspec-file.sh b/t/t7107-reset-pathspec-file.sh index 6b1a731fff..b0e84cdb42 100755 --- a/t/t7107-reset-pathspec-file.sh +++ b/t/t7107-reset-pathspec-file.sh @@ -105,8 +105,12 @@ test_expect_success 'CRLF delimiters' ' test_expect_success 'quotes' ' restore_checkpoint && + cat >list <<-\EOF && + "file\101.t" + EOF + git rm fileA.t && - printf "\"file\\101.t\"" | git reset --pathspec-from-file=- && + git reset --pathspec-from-file=list && cat >expect <<-\EOF && D fileA.t @@ -117,8 +121,10 @@ test_expect_success 'quotes' ' test_expect_success 'quotes not compatible with --pathspec-file-nul' ' restore_checkpoint && - git rm fileA.t && - printf "\"file\\101.t\"" >list && + cat >list <<-\EOF && + "file\101.t" + EOF + # Note: "git reset" has not yet learned to fail on wrong pathspecs git reset --pathspec-from-file=list --pathspec-file-nul && diff --git a/t/t7526-commit-pathspec-file.sh b/t/t7526-commit-pathspec-file.sh index 4b58901ed6..4a7c11368d 100755 --- a/t/t7526-commit-pathspec-file.sh +++ b/t/t7526-commit-pathspec-file.sh @@ -100,7 +100,11 @@ test_expect_success 'CRLF delimiters' ' test_expect_success 'quotes' ' restore_checkpoint && - printf "\"file\\101.t\"" | git commit --pathspec-from-file=- -m "Commit" && + cat >list <<-\EOF && + "file\101.t" + EOF + + git commit --pathspec-from-file=list -m "Commit" && cat >expect <<-\EOF && A fileA.t @@ -111,7 +115,10 @@ test_expect_success 'quotes' ' test_expect_success 'quotes not compatible with --pathspec-file-nul' ' restore_checkpoint && - printf "\"file\\101.t\"" >list && + cat >list <<-\EOF && + "file\101.t" + EOF + test_must_fail git commit --pathspec-from-file=list --pathspec-file-nul -m "Commit" ' From patchwork Tue Dec 31 10:15:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin via GitGitGadget X-Patchwork-Id: 11313929 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 D1F0F1398 for ; Tue, 31 Dec 2019 10:15:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A4C7F206E6 for ; Tue, 31 Dec 2019 10:15:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="F3wFgS47" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726702AbfLaKPS (ORCPT ); Tue, 31 Dec 2019 05:15:18 -0500 Received: from mail-ed1-f65.google.com ([209.85.208.65]:40563 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726643AbfLaKPS (ORCPT ); Tue, 31 Dec 2019 05:15:18 -0500 Received: by mail-ed1-f65.google.com with SMTP id b8so34924341edx.7 for ; Tue, 31 Dec 2019 02:15:16 -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=By11ZhLNpGOJE7ks9nGpRahw14cn6l0tXfvSE8ofCmk=; b=F3wFgS47kINKg8okhGCRD6ol7d6QU4wCYcA9T4sfm6F4yx5Scd2CydGyXwaWGlPydm vt1JCBh0TbSTYSMg8AvQKwexN0NW9VMNbFOuuRm7ivN3UkIjfrM5DvyR0M4YSse6fZrv fOz29P9zeHaXrr0PJWLLI5XYO1VsP62w/XAyWlx4/BTv1t3vn2go+GSsFtkcFcXUlPM2 L1nxT03mrAP6tt8ZCd/Ug4FQ43c0nD+Nbm5zFqCvqvnUT7wXM0PS6ExSEebbIvbIqidP XL3t3jAJXqdih9E1LtGDQiYJm5MeEl8xVV8htgGu0AUnGCIXs0MPtDjmO/OtAoK4IFyN k0uA== 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=By11ZhLNpGOJE7ks9nGpRahw14cn6l0tXfvSE8ofCmk=; b=XBPWq0XX7+MU8zdMNpyHhzGZHQbITxNOM5QKaHAHUV8+OEydT/MMcR+MhkBff7/MTj PuWrN8A4TDUbkvcJms5dFRhuTJxFYiqcRrW1AM9/ua62wlo/3ofplYu8tIgvMqLVCxiN 6nIp69BXrNhjZRZGr+nm/vypY5yx9WWvbOtbZ9i2Yp1ccImIFxMtV77HXbN3Ih9X4z/X 59pvXLySe7t3TzIiUDlRrBLEMCeIBW1omIWQSN5sRDD3cof6U/ascBeVog4WYQ3z7iHs IEivLYjwvfceWo3oW/v2seVDbsD7XVepGF0BLQA/xQnMi8QyAxg3mZfijRVCrknTQwdd Co/g== X-Gm-Message-State: APjAAAVDdugYYcMK2plvCrhh9JGQNTyBkWP9QUusaoBZ6zXf/6o6eyaM MMyfSgKJ2pyUqY/MYRbL2hSadQtC X-Google-Smtp-Source: APXvYqxn03O1IWnxnt1Yuvx2cy9orGDkiS8/TR7TRFZ5lJwJYkjR/M36SVSXudV4EV1dDx1vreTXCg== X-Received: by 2002:a17:906:4f93:: with SMTP id o19mr75172509eju.52.1577787315985; Tue, 31 Dec 2019 02:15:15 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l26sm6011509ejr.23.2019.12.31.02.15.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 31 Dec 2019 02:15:15 -0800 (PST) Message-Id: <8748f3baf1d92f2e642c529ba3856714f847a468.1577787313.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Alexandr Miloslavskiy via GitGitGadget" Date: Tue, 31 Dec 2019 10:15:12 +0000 Subject: [PATCH v4 2/3] t: directly test parse_pathspec_file() Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Nieder , Eric Sunshine , Alexandr Miloslavskiy , Junio C Hamano , Alexandr Miloslavskiy Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Alexandr Miloslavskiy Previously, `parse_pathspec_file()` was tested indirectly by invoking git commands with properly crafted inputs. As demonstrated by the previous bugfix, testing complicated black boxes indirectly can lead to tests that silently test the wrong thing. Introduce direct tests for `parse_pathspec_file()`. Signed-off-by: Alexandr Miloslavskiy --- Makefile | 1 + t/helper/test-parse-pathspec-file.c | 33 +++++++++ t/helper/test-tool.c | 1 + t/helper/test-tool.h | 1 + t/t0067-parse_pathspec_file.sh | 108 ++++++++++++++++++++++++++++ 5 files changed, 144 insertions(+) create mode 100644 t/helper/test-parse-pathspec-file.c create mode 100755 t/t0067-parse_pathspec_file.sh diff --git a/Makefile b/Makefile index 09f98b777c..0061f96e8a 100644 --- a/Makefile +++ b/Makefile @@ -721,6 +721,7 @@ TEST_BUILTINS_OBJS += test-mktemp.o TEST_BUILTINS_OBJS += test-oidmap.o TEST_BUILTINS_OBJS += test-online-cpus.o TEST_BUILTINS_OBJS += test-parse-options.o +TEST_BUILTINS_OBJS += test-parse-pathspec-file.o TEST_BUILTINS_OBJS += test-path-utils.o TEST_BUILTINS_OBJS += test-pkt-line.o TEST_BUILTINS_OBJS += test-prio-queue.o diff --git a/t/helper/test-parse-pathspec-file.c b/t/helper/test-parse-pathspec-file.c new file mode 100644 index 0000000000..02f4ccfd2a --- /dev/null +++ b/t/helper/test-parse-pathspec-file.c @@ -0,0 +1,33 @@ +#include "test-tool.h" +#include "parse-options.h" +#include "pathspec.h" +#include "gettext.h" + +int cmd__parse_pathspec_file(int argc, const char **argv) +{ + struct pathspec pathspec; + const char *pathspec_from_file = 0; + int pathspec_file_nul = 0, i; + + static const char *const usage[] = { + "test-tool parse-pathspec-file --pathspec-from-file [--pathspec-file-nul]", + NULL + }; + + struct option options[] = { + OPT_PATHSPEC_FROM_FILE(&pathspec_from_file), + OPT_PATHSPEC_FILE_NUL(&pathspec_file_nul), + OPT_END() + }; + + parse_options(argc, argv, 0, options, usage, 0); + + parse_pathspec_file(&pathspec, 0, 0, 0, pathspec_from_file, + pathspec_file_nul); + + for (i = 0; i < pathspec.nr; i++) + printf("%s\n", pathspec.items[i].original); + + clear_pathspec(&pathspec); + return 0; +} diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c index f20989d449..c9a232d238 100644 --- a/t/helper/test-tool.c +++ b/t/helper/test-tool.c @@ -39,6 +39,7 @@ static struct test_cmd cmds[] = { { "oidmap", cmd__oidmap }, { "online-cpus", cmd__online_cpus }, { "parse-options", cmd__parse_options }, + { "parse-pathspec-file", cmd__parse_pathspec_file }, { "path-utils", cmd__path_utils }, { "pkt-line", cmd__pkt_line }, { "prio-queue", cmd__prio_queue }, diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h index 8ed2af71d1..c8549fd87f 100644 --- a/t/helper/test-tool.h +++ b/t/helper/test-tool.h @@ -29,6 +29,7 @@ int cmd__mktemp(int argc, const char **argv); int cmd__oidmap(int argc, const char **argv); int cmd__online_cpus(int argc, const char **argv); int cmd__parse_options(int argc, const char **argv); +int cmd__parse_pathspec_file(int argc, const char** argv); int cmd__path_utils(int argc, const char **argv); int cmd__pkt_line(int argc, const char **argv); int cmd__prio_queue(int argc, const char **argv); diff --git a/t/t0067-parse_pathspec_file.sh b/t/t0067-parse_pathspec_file.sh new file mode 100755 index 0000000000..7bab49f361 --- /dev/null +++ b/t/t0067-parse_pathspec_file.sh @@ -0,0 +1,108 @@ +#!/bin/sh + +test_description='Test parse_pathspec_file()' + +. ./test-lib.sh + +test_expect_success 'one item from stdin' ' + cat >expect <<-\EOF && + fileA.t + EOF + + echo fileA.t | + test-tool parse-pathspec-file --pathspec-from-file=- >actual && + + test_cmp expect actual +' + +test_expect_success 'one item from file' ' + cat >expect <<-\EOF && + fileA.t + EOF + + echo fileA.t >list && + test-tool parse-pathspec-file --pathspec-from-file=list >actual && + + test_cmp expect actual +' + +test_expect_success 'NUL delimiters' ' + cat >expect <<-\EOF && + fileA.t + fileB.t + EOF + + printf "fileA.t\0fileB.t\0" | + test-tool parse-pathspec-file --pathspec-from-file=- --pathspec-file-nul >actual && + + test_cmp expect actual +' + +test_expect_success 'LF delimiters' ' + cat >expect <<-\EOF && + fileA.t + fileB.t + EOF + + printf "fileA.t\nfileB.t\n" | + test-tool parse-pathspec-file --pathspec-from-file=- >actual && + + test_cmp expect actual +' + +test_expect_success 'no trailing delimiter' ' + cat >expect <<-\EOF && + fileA.t + fileB.t + EOF + + printf "fileA.t\nfileB.t" | + test-tool parse-pathspec-file --pathspec-from-file=- >actual && + + test_cmp expect actual +' + +test_expect_success 'CRLF delimiters' ' + cat >expect <<-\EOF && + fileA.t + fileB.t + EOF + + printf "fileA.t\r\nfileB.t\r\n" | + test-tool parse-pathspec-file --pathspec-from-file=- >actual && + + test_cmp expect actual +' + +test_expect_success 'quotes' ' + cat >expect <<-\EOF && + fileA.t + EOF + + cat >list <<-\EOF && + "file\101.t" + EOF + + test-tool parse-pathspec-file --pathspec-from-file=list >actual && + + test_cmp expect actual +' + +test_expect_success '--pathspec-file-nul takes quotes literally' ' + # Note: there is an extra newline because --pathspec-file-nul takes + # input \n literally, too + cat >expect <<-\EOF && + "file\101.t" + + EOF + + cat >list <<-\EOF && + "file\101.t" + EOF + + test-tool parse-pathspec-file --pathspec-from-file=list --pathspec-file-nul >actual && + + test_cmp expect actual +' + +test_done From patchwork Tue Dec 31 10:15:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin via GitGitGadget X-Patchwork-Id: 11313933 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 E88231398 for ; Tue, 31 Dec 2019 10:15:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B9A7F206E6 for ; Tue, 31 Dec 2019 10:15:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="THH2JXHc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727054AbfLaKPU (ORCPT ); Tue, 31 Dec 2019 05:15:20 -0500 Received: from mail-ed1-f65.google.com ([209.85.208.65]:40565 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726421AbfLaKPT (ORCPT ); Tue, 31 Dec 2019 05:15:19 -0500 Received: by mail-ed1-f65.google.com with SMTP id b8so34924375edx.7 for ; Tue, 31 Dec 2019 02:15:17 -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=FYFS63Zt9ictIT5yR3ucuMx8xPbha7+n8wNijfH71Es=; b=THH2JXHchGoLFKBqrf36yOjUif1GsUXTayrGYr8rnqmJdKQCPE8XgEAB7HAjSh3n7e OX3OfTq2XhLFXjeUfg2Z/Kw0zUjW1x0Gw/w/sRQOHu1qbr7pXpaBsrMpqfSYldDI3GNt lxJltdhXUBMCNq2+ujBiy2c+ejn3E3KaX3B+NqH4eDukqK3eejinZ+jfyECH+xA4ro1d e6QA/1VU29tUNFqJb7l32wj+Rwtdhqar85CSBz5l1TVlYp5a2fp/YL7WPqqEYgXLBAFv XBRTljP/IEOtdW4ft/dcXRvD6XEkJnaBE9tbRF58zLC45WQh9ye8aDhthd5Q6KkIUNTU LWmg== 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=FYFS63Zt9ictIT5yR3ucuMx8xPbha7+n8wNijfH71Es=; b=cLawXNELZxrTkoZfeImXIydjEQ6Mc1+5zKBUHZgAJBlcB+TK7p8+ck7rfP/QE6BWJs fmOOCA4k2FN5SSvK1SboV1NudlDvOq4xSX3n56baRIBrjxwOamnGR8FxBp280djNYvVb 8xQ2PQo8DG9DrKQJhHKJAk7SbefqM6C8kHw2/XsMSfRgF59dFaSIyeNxdhcolhzVn+bf dHcMOe3H/ohxicwhpLRnK2RYQX9nIOSNfBLQWNH8R3Z8xp0hekqlP/GFTzJeT8YR1q8r ZQoHP1dQhdkvysWBcGn/5dpAMGaU6iN8EOsx1DGd8nDlRlxKjCopbkVJbTQvgQZEM1F7 SYvw== X-Gm-Message-State: APjAAAV+Ghl3I91F4Z6ZwHyrZGnOohxlmNkQPQoR3+z44FG7hUHaK0eO PL0I0mH2D+NoT7/ogy2Kbmp9q1gQ X-Google-Smtp-Source: APXvYqxli3AD2gdZjLOBuOlisDNYvn59SYyx9lrpJMXvKf/bG6AKpqnSvFB5jrLhrwkmP8/sGXNRXw== X-Received: by 2002:a50:cd11:: with SMTP id z17mr75951392edi.178.1577787316863; Tue, 31 Dec 2019 02:15:16 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j3sm5757745edb.50.2019.12.31.02.15.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 31 Dec 2019 02:15:16 -0800 (PST) Message-Id: In-Reply-To: References: From: "Alexandr Miloslavskiy via GitGitGadget" Date: Tue, 31 Dec 2019 10:15:13 +0000 Subject: [PATCH v4 3/3] t: drop copy&pasted tests for --pathspec-from-file Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Nieder , Eric Sunshine , Alexandr Miloslavskiy , Junio C Hamano , Alexandr Miloslavskiy Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Alexandr Miloslavskiy With direct tests for `parse_pathspec_file()` already in place, it is not very reasonable to copy&paste 6 similar indirect tests for every git command that uses `parse_pathspec_file()`. I counted 13 potential git commands, which could eventually lead to 6*13=78 duplicate tests. I believe that indirect tests are redundant because I don't expect direct tests to ever disagree with indirect tests. Signed-off-by: Alexandr Miloslavskiy --- t/t2026-checkout-pathspec-file.sh | 77 +--------------------------- t/t2072-restore-pathspec-file.sh | 77 +--------------------------- t/t3704-add-pathspec-file.sh | 77 +--------------------------- t/t7107-reset-pathspec-file.sh | 85 +++---------------------------- t/t7526-commit-pathspec-file.sh | 77 +--------------------------- 5 files changed, 16 insertions(+), 377 deletions(-) diff --git a/t/t2026-checkout-pathspec-file.sh b/t/t2026-checkout-pathspec-file.sh index adad71f631..559b4528d7 100755 --- a/t/t2026-checkout-pathspec-file.sh +++ b/t/t2026-checkout-pathspec-file.sh @@ -35,7 +35,7 @@ verify_expect () { test_cmp expect actual } -test_expect_success '--pathspec-from-file from stdin' ' +test_expect_success 'simplest' ' restore_checkpoint && echo fileA.t | git checkout --pathspec-from-file=- HEAD^1 && @@ -46,19 +46,7 @@ test_expect_success '--pathspec-from-file from stdin' ' verify_expect ' -test_expect_success '--pathspec-from-file from file' ' - restore_checkpoint && - - echo fileA.t >list && - git checkout --pathspec-from-file=list HEAD^1 && - - cat >expect <<-\EOF && - M fileA.t - EOF - verify_expect -' - -test_expect_success 'NUL delimiters' ' +test_expect_success '--pathspec-file-nul' ' restore_checkpoint && printf "fileA.t\0fileB.t\0" | git checkout --pathspec-from-file=- --pathspec-file-nul HEAD^1 && @@ -70,67 +58,6 @@ test_expect_success 'NUL delimiters' ' verify_expect ' -test_expect_success 'LF delimiters' ' - restore_checkpoint && - - printf "fileA.t\nfileB.t\n" | git checkout --pathspec-from-file=- HEAD^1 && - - cat >expect <<-\EOF && - M fileA.t - M fileB.t - EOF - verify_expect -' - -test_expect_success 'no trailing delimiter' ' - restore_checkpoint && - - printf "fileA.t\nfileB.t" | git checkout --pathspec-from-file=- HEAD^1 && - - cat >expect <<-\EOF && - M fileA.t - M fileB.t - EOF - verify_expect -' - -test_expect_success 'CRLF delimiters' ' - restore_checkpoint && - - printf "fileA.t\r\nfileB.t\r\n" | git checkout --pathspec-from-file=- HEAD^1 && - - cat >expect <<-\EOF && - M fileA.t - M fileB.t - EOF - verify_expect -' - -test_expect_success 'quotes' ' - restore_checkpoint && - - cat >list <<-\EOF && - "file\101.t" - EOF - - git checkout --pathspec-from-file=list HEAD^1 && - - cat >expect <<-\EOF && - M fileA.t - EOF - verify_expect -' - -test_expect_success 'quotes not compatible with --pathspec-file-nul' ' - restore_checkpoint && - - cat >list <<-\EOF && - "file\101.t" - EOF - - test_must_fail git checkout --pathspec-from-file=list --pathspec-file-nul HEAD^1 -' - test_expect_success 'only touches what was listed' ' restore_checkpoint && diff --git a/t/t2072-restore-pathspec-file.sh b/t/t2072-restore-pathspec-file.sh index b407f6b779..9b3125d582 100755 --- a/t/t2072-restore-pathspec-file.sh +++ b/t/t2072-restore-pathspec-file.sh @@ -35,7 +35,7 @@ verify_expect () { test_cmp expect actual } -test_expect_success '--pathspec-from-file from stdin' ' +test_expect_success 'simplest' ' restore_checkpoint && echo fileA.t | git restore --pathspec-from-file=- --source=HEAD^1 && @@ -46,19 +46,7 @@ test_expect_success '--pathspec-from-file from stdin' ' verify_expect ' -test_expect_success '--pathspec-from-file from file' ' - restore_checkpoint && - - echo fileA.t >list && - git restore --pathspec-from-file=list --source=HEAD^1 && - - cat >expect <<-\EOF && - M fileA.t - EOF - verify_expect -' - -test_expect_success 'NUL delimiters' ' +test_expect_success '--pathspec-file-nul' ' restore_checkpoint && printf "fileA.t\0fileB.t\0" | git restore --pathspec-from-file=- --pathspec-file-nul --source=HEAD^1 && @@ -70,67 +58,6 @@ test_expect_success 'NUL delimiters' ' verify_expect ' -test_expect_success 'LF delimiters' ' - restore_checkpoint && - - printf "fileA.t\nfileB.t\n" | git restore --pathspec-from-file=- --source=HEAD^1 && - - cat >expect <<-\EOF && - M fileA.t - M fileB.t - EOF - verify_expect -' - -test_expect_success 'no trailing delimiter' ' - restore_checkpoint && - - printf "fileA.t\nfileB.t" | git restore --pathspec-from-file=- --source=HEAD^1 && - - cat >expect <<-\EOF && - M fileA.t - M fileB.t - EOF - verify_expect -' - -test_expect_success 'CRLF delimiters' ' - restore_checkpoint && - - printf "fileA.t\r\nfileB.t\r\n" | git restore --pathspec-from-file=- --source=HEAD^1 && - - cat >expect <<-\EOF && - M fileA.t - M fileB.t - EOF - verify_expect -' - -test_expect_success 'quotes' ' - restore_checkpoint && - - cat >list <<-\EOF && - "file\101.t" - EOF - - git restore --pathspec-from-file=list --source=HEAD^1 && - - cat >expect <<-\EOF && - M fileA.t - EOF - verify_expect -' - -test_expect_success 'quotes not compatible with --pathspec-file-nul' ' - restore_checkpoint && - - cat >list <<-\EOF && - "file\101.t" - EOF - - test_must_fail git restore --pathspec-from-file=list --pathspec-file-nul --source=HEAD^1 -' - test_expect_success 'only touches what was listed' ' restore_checkpoint && diff --git a/t/t3704-add-pathspec-file.sh b/t/t3704-add-pathspec-file.sh index 61b6e51009..9009f8a9ac 100755 --- a/t/t3704-add-pathspec-file.sh +++ b/t/t3704-add-pathspec-file.sh @@ -23,7 +23,7 @@ verify_expect () { test_cmp expect actual } -test_expect_success '--pathspec-from-file from stdin' ' +test_expect_success 'simplest' ' restore_checkpoint && echo fileA.t | git add --pathspec-from-file=- && @@ -34,19 +34,7 @@ test_expect_success '--pathspec-from-file from stdin' ' verify_expect ' -test_expect_success '--pathspec-from-file from file' ' - restore_checkpoint && - - echo fileA.t >list && - git add --pathspec-from-file=list && - - cat >expect <<-\EOF && - A fileA.t - EOF - verify_expect -' - -test_expect_success 'NUL delimiters' ' +test_expect_success '--pathspec-file-nul' ' restore_checkpoint && printf "fileA.t\0fileB.t\0" | git add --pathspec-from-file=- --pathspec-file-nul && @@ -58,67 +46,6 @@ test_expect_success 'NUL delimiters' ' verify_expect ' -test_expect_success 'LF delimiters' ' - restore_checkpoint && - - printf "fileA.t\nfileB.t\n" | git add --pathspec-from-file=- && - - cat >expect <<-\EOF && - A fileA.t - A fileB.t - EOF - verify_expect -' - -test_expect_success 'no trailing delimiter' ' - restore_checkpoint && - - printf "fileA.t\nfileB.t" | git add --pathspec-from-file=- && - - cat >expect <<-\EOF && - A fileA.t - A fileB.t - EOF - verify_expect -' - -test_expect_success 'CRLF delimiters' ' - restore_checkpoint && - - printf "fileA.t\r\nfileB.t\r\n" | git add --pathspec-from-file=- && - - cat >expect <<-\EOF && - A fileA.t - A fileB.t - EOF - verify_expect -' - -test_expect_success 'quotes' ' - restore_checkpoint && - - cat >list <<-\EOF && - "file\101.t" - EOF - - git add --pathspec-from-file=list && - - cat >expect <<-\EOF && - A fileA.t - EOF - verify_expect -' - -test_expect_success 'quotes not compatible with --pathspec-file-nul' ' - restore_checkpoint && - - cat >list <<-\EOF && - "file\101.t" - EOF - - test_must_fail git add --pathspec-from-file=list --pathspec-file-nul -' - test_expect_success 'only touches what was listed' ' restore_checkpoint && diff --git a/t/t7107-reset-pathspec-file.sh b/t/t7107-reset-pathspec-file.sh index b0e84cdb42..5b845f4f7c 100755 --- a/t/t7107-reset-pathspec-file.sh +++ b/t/t7107-reset-pathspec-file.sh @@ -25,7 +25,7 @@ verify_expect () { test_cmp expect actual } -test_expect_success '--pathspec-from-file from stdin' ' +test_expect_success 'simplest' ' restore_checkpoint && git rm fileA.t && @@ -37,20 +37,7 @@ test_expect_success '--pathspec-from-file from stdin' ' verify_expect ' -test_expect_success '--pathspec-from-file from file' ' - restore_checkpoint && - - git rm fileA.t && - echo fileA.t >list && - git reset --pathspec-from-file=list && - - cat >expect <<-\EOF && - D fileA.t - EOF - verify_expect -' - -test_expect_success 'NUL delimiters' ' +test_expect_success '--pathspec-file-nul' ' restore_checkpoint && git rm fileA.t fileB.t && @@ -63,77 +50,21 @@ test_expect_success 'NUL delimiters' ' verify_expect ' -test_expect_success 'LF delimiters' ' - restore_checkpoint && - - git rm fileA.t fileB.t && - printf "fileA.t\nfileB.t\n" | git reset --pathspec-from-file=- && - - cat >expect <<-\EOF && - D fileA.t - D fileB.t - EOF - verify_expect -' - -test_expect_success 'no trailing delimiter' ' - restore_checkpoint && - - git rm fileA.t fileB.t && - printf "fileA.t\nfileB.t" | git reset --pathspec-from-file=- && - - cat >expect <<-\EOF && - D fileA.t - D fileB.t - EOF - verify_expect -' - -test_expect_success 'CRLF delimiters' ' +test_expect_success 'only touches what was listed' ' restore_checkpoint && - git rm fileA.t fileB.t && - printf "fileA.t\r\nfileB.t\r\n" | git reset --pathspec-from-file=- && + git rm fileA.t fileB.t fileC.t fileD.t && + printf "fileB.t\nfileC.t\n" | git reset --pathspec-from-file=- && cat >expect <<-\EOF && - D fileA.t + D fileA.t D fileB.t + D fileC.t + D fileD.t EOF verify_expect ' -test_expect_success 'quotes' ' - restore_checkpoint && - - cat >list <<-\EOF && - "file\101.t" - EOF - - git rm fileA.t && - git reset --pathspec-from-file=list && - - cat >expect <<-\EOF && - D fileA.t - EOF - verify_expect -' - -test_expect_success 'quotes not compatible with --pathspec-file-nul' ' - restore_checkpoint && - - cat >list <<-\EOF && - "file\101.t" - EOF - - # Note: "git reset" has not yet learned to fail on wrong pathspecs - git reset --pathspec-from-file=list --pathspec-file-nul && - - cat >expect <<-\EOF && - D fileA.t - EOF - test_must_fail verify_expect -' - test_expect_success '--pathspec-from-file is not compatible with --soft or --hard' ' restore_checkpoint && diff --git a/t/t7526-commit-pathspec-file.sh b/t/t7526-commit-pathspec-file.sh index 4a7c11368d..8d6c652690 100755 --- a/t/t7526-commit-pathspec-file.sh +++ b/t/t7526-commit-pathspec-file.sh @@ -26,7 +26,7 @@ verify_expect () { test_cmp expect actual } -test_expect_success '--pathspec-from-file from stdin' ' +test_expect_success 'simplest' ' restore_checkpoint && echo fileA.t | git commit --pathspec-from-file=- -m "Commit" && @@ -37,19 +37,7 @@ test_expect_success '--pathspec-from-file from stdin' ' verify_expect ' -test_expect_success '--pathspec-from-file from file' ' - restore_checkpoint && - - echo fileA.t >list && - git commit --pathspec-from-file=list -m "Commit" && - - cat >expect <<-\EOF && - A fileA.t - EOF - verify_expect -' - -test_expect_success 'NUL delimiters' ' +test_expect_success '--pathspec-file-nul' ' restore_checkpoint && printf "fileA.t\0fileB.t\0" | git commit --pathspec-from-file=- --pathspec-file-nul -m "Commit" && @@ -61,67 +49,6 @@ test_expect_success 'NUL delimiters' ' verify_expect ' -test_expect_success 'LF delimiters' ' - restore_checkpoint && - - printf "fileA.t\nfileB.t\n" | git commit --pathspec-from-file=- -m "Commit" && - - cat >expect <<-\EOF && - A fileA.t - A fileB.t - EOF - verify_expect -' - -test_expect_success 'no trailing delimiter' ' - restore_checkpoint && - - printf "fileA.t\nfileB.t" | git commit --pathspec-from-file=- -m "Commit" && - - cat >expect <<-\EOF && - A fileA.t - A fileB.t - EOF - verify_expect -' - -test_expect_success 'CRLF delimiters' ' - restore_checkpoint && - - printf "fileA.t\r\nfileB.t\r\n" | git commit --pathspec-from-file=- -m "Commit" && - - cat >expect <<-\EOF && - A fileA.t - A fileB.t - EOF - verify_expect -' - -test_expect_success 'quotes' ' - restore_checkpoint && - - cat >list <<-\EOF && - "file\101.t" - EOF - - git commit --pathspec-from-file=list -m "Commit" && - - cat >expect <<-\EOF && - A fileA.t - EOF - verify_expect expect -' - -test_expect_success 'quotes not compatible with --pathspec-file-nul' ' - restore_checkpoint && - - cat >list <<-\EOF && - "file\101.t" - EOF - - test_must_fail git commit --pathspec-from-file=list --pathspec-file-nul -m "Commit" -' - test_expect_success 'only touches what was listed' ' restore_checkpoint &&