From: Junio C Hamano <gitster@pobox.com>
To: "Alexandr Miloslavskiy via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org,
Alexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com>
Subject: Re: [PATCH 2/3] t: directly test parse_pathspec_file()
Date: Mon, 30 Dec 2019 10:52:28 -0800 [thread overview]
Message-ID: <xmqq8smthcib.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <27383a5b084b5e68152b08eb96fb4ddaf6d87f82.1577727747.git.gitgitgadget@gmail.com> (Alexandr Miloslavskiy via GitGitGadget's message of "Mon, 30 Dec 2019 17:42:26 +0000")
"Alexandr Miloslavskiy via GitGitGadget" <gitgitgadget@gmail.com>
writes:
> diff --git a/t/helper/test-parse-pathspec-file.c b/t/helper/test-parse-pathspec-file.c
> new file mode 100644
> index 0000000000..e7f525feb9
> --- /dev/null
> +++ b/t/helper/test-parse-pathspec-file.c
> @@ -0,0 +1,34 @@
> +#include "test-tool.h"
> +#include "parse-options.h"
> +#include "pathspec.h"
> +#include "gettext.h"
> + ...
> + 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);
> + }
No need for {} around a single statement block.
> diff --git a/t/t0067-parse_pathspec_file.sh b/t/t0067-parse_pathspec_file.sh
> new file mode 100755
> index 0000000000..df7b319713
> --- /dev/null
> +++ b/t/t0067-parse_pathspec_file.sh
> @@ -0,0 +1,89 @@
> +#!/bin/sh
> +
> +test_description='Test parse_pathspec_file()'
> +
> +. ./test-lib.sh
> +
> +test_expect_success 'one item from stdin' '
> + echo fileA.t | test-tool parse-pathspec-file --pathspec-from-file=- >actual &&
> +
> + cat >expect <<-\EOF &&
> + fileA.t
> + EOF
> + test_cmp expect actual
> +'
The use of the blank lines are somewhat inconsistent here.
> + ...
> +test_expect_success 'NUL delimiters' '
> + printf "fileA.t\0fileB.t\0" | test-tool parse-pathspec-file --pathspec-from-file=- --pathspec-file-nul >actual &&
Fold line immediately after the pipe (same for the earlier and later ones).
> + cat >expect <<-\EOF &&
> + fileA.t
> + fileB.t
> + EOF
> + test_cmp expect actual
> +'
If you want to have a gap between the steps, i.e. "capturing the
actual output", "creating the ideal output", and "seeing how they
differ", using blank like this is OK:
printf "fileA.t\0fileB.t\0" |
test-tool parse-pathspec-file --pathspec-from-file=- --pathspec-file-nul >actual &&
cat >expect <<-\EOF &&
fileA.t
fileB.t
EOF
test_cmp expect actual
I thought we typically prepare the ideal output sample before
capturing the actual output, so if we follow that convention, the
above becomes
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 'quotes' '
> + # shell takes \\\\101 and spits \\101
> + # printf takes \\101 and spits \101
> + # git takes \101 and spits A
> + printf "\"file\\\\101.t\"" | test-tool parse-pathspec-file --pathspec-from-file=- >actual &&
> +
> + cat >expect <<-\EOF &&
> + fileA.t
> + EOF
> + test_cmp expect actual
> +'
> +
> +test_expect_success '--pathspec-file-nul takes quotes literally' '
> + # shell takes \\\\101 and spits \\101
> + # printf takes \\101 and spits \101
> + printf "\"file\\\\101.t\"" | test-tool parse-pathspec-file --pathspec-from-file=- --pathspec-file-nul >actual &&
> +
> + cat >expect <<-\EOF &&
> + "file\101.t"
> + EOF
> + test_cmp expect actual
> +'
Testing low level machinery like this is of course a good idea, in
addition to the end-to-end tests that make sure that the machinery
is called correctly from the higher layer.
Thanks.
next prev parent reply other threads:[~2019-12-30 18:52 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-30 17:42 [PATCH 0/3] t: rework tests for --pathspec-from-file Alexandr Miloslavskiy via GitGitGadget
2019-12-30 17:42 ` [PATCH 1/3] t: fix quotes " Alexandr Miloslavskiy via GitGitGadget
2019-12-30 17:42 ` [PATCH 2/3] t: directly test parse_pathspec_file() Alexandr Miloslavskiy via GitGitGadget
2019-12-30 18:52 ` Junio C Hamano [this message]
2019-12-30 19:16 ` Alexandr Miloslavskiy
2019-12-30 17:42 ` [PATCH 3/3] t: drop copy&pasted tests for --pathspec-from-file Alexandr Miloslavskiy via GitGitGadget
2019-12-30 19:15 ` [PATCH v2 0/3] t: rework " Alexandr Miloslavskiy via GitGitGadget
2019-12-30 19:15 ` [PATCH v2 1/3] t: fix quotes " Alexandr Miloslavskiy via GitGitGadget
2019-12-30 21:55 ` Eric Sunshine
2019-12-31 0:26 ` Jonathan Nieder
2019-12-31 10:01 ` Alexandr Miloslavskiy
2019-12-30 19:15 ` [PATCH v2 2/3] t: directly test parse_pathspec_file() Alexandr Miloslavskiy via GitGitGadget
2019-12-30 19:15 ` [PATCH v2 3/3] t: drop copy&pasted tests for --pathspec-from-file Alexandr Miloslavskiy via GitGitGadget
2019-12-31 9:53 ` [PATCH v3 0/3] t: rework " Alexandr Miloslavskiy via GitGitGadget
2019-12-31 9:53 ` [PATCH v3 1/3] t: fix quotes " Alexandr Miloslavskiy via GitGitGadget
2019-12-31 9:53 ` [PATCH v3 2/3] t: directly test parse_pathspec_file() Alexandr Miloslavskiy via GitGitGadget
2019-12-31 9:53 ` [PATCH v3 3/3] t: drop copy&pasted tests for --pathspec-from-file Alexandr Miloslavskiy via GitGitGadget
2019-12-31 10:15 ` [PATCH v4 0/3] t: rework " Alexandr Miloslavskiy via GitGitGadget
2019-12-31 10:15 ` [PATCH v4 1/3] t: fix quotes " Alexandr Miloslavskiy via GitGitGadget
2019-12-31 10:15 ` [PATCH v4 2/3] t: directly test parse_pathspec_file() Alexandr Miloslavskiy via GitGitGadget
2019-12-31 10:15 ` [PATCH v4 3/3] t: drop copy&pasted tests for --pathspec-from-file Alexandr Miloslavskiy via GitGitGadget
2020-01-07 21:13 ` [PATCH v4 0/3] t: rework " Junio C Hamano
2020-01-08 15:32 ` Alexandr Miloslavskiy
2020-01-08 17:26 ` Junio C Hamano
2020-01-08 17:42 ` Alexandr Miloslavskiy
2020-01-08 18:50 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq8smthcib.fsf@gitster-ct.c.googlers.com \
--to=gitster@pobox.com \
--cc=alexandr.miloslavskiy@syntevo.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).