git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Chandra Pratap <chandrapratap3519@gmail.com>
Cc: git@vger.kernel.org, Christian Couder <chriscool@tuxfamily.org>
Subject: Re: [PATCH 5/5] t-reftable-readwrite: add tests for print functions
Date: Thu, 8 Aug 2024 14:00:45 +0200	[thread overview]
Message-ID: <ZrSzbdNkCS2LOXaL@tanuki> (raw)
In-Reply-To: <ZrR91dR3G06L9dy7@tanuki>

[-- Attachment #1: Type: text/plain, Size: 3516 bytes --]

On Thu, Aug 08, 2024 at 10:12:07AM +0200, Patrick Steinhardt wrote:
> On Wed, Aug 07, 2024 at 07:42:01PM +0530, Chandra Pratap wrote:
> > +static void t_table_print(void)
> > +{
> > +	char name[100];
> > +	struct reftable_write_options opts = {
> > +		.block_size = 512,
> > +		.hash_id = GIT_SHA1_FORMAT_ID,
> > +	};
> > +	struct reftable_ref_record ref = { 0 };
> > +	struct reftable_log_record log = { 0 };
> > +	struct reftable_writer *w = NULL;
> > +	struct tempfile *tmp = NULL;
> > +	size_t i, N = 3;
> > +	int n, fd;
> > +
> > +	xsnprintf(name, sizeof(name), "t-reftable-readwrite-%d-XXXXXX", __LINE__);
> 
> Is it really required to include the line number in this file? This
> feels unnecessarily defensive to me as `mks_tempfile_t()` should already
> make sure that we get a unique filename. So if we drop that, we could
> skip this call to `xsnprintf()`.
> 
> > +	tmp = mks_tempfile_t(name);
> > +	fd = get_tempfile_fd(tmp);
> > +	w = reftable_new_writer(&fd_write, &fd_flush, &fd, &opts);
> > +	reftable_writer_set_limits(w, 0, update_index);
> > +
> > +	for (i = 0; i < N; i++) {
> > +		xsnprintf(name, sizeof(name), "refs/heads/branch%02"PRIuMAX, (uintmax_t)i);
> > +		ref.refname = name;
> > +		ref.update_index = i;
> > +		ref.value_type = REFTABLE_REF_VAL1;
> > +		set_test_hash(ref.value.val1, i);
> > +
> > +		n = reftable_writer_add_ref(w, &ref);
> > +		check_int(n, ==, 0);
> > +	}
> > +
> > +	for (i = 0; i < N; i++) {
> > +		xsnprintf(name, sizeof(name), "refs/heads/branch%02"PRIuMAX, (uintmax_t)i);
> > +		log.refname = name;
> > +		log.update_index = i;
> > +		log.value_type = REFTABLE_LOG_UPDATE;
> > +		set_test_hash(log.value.update.new_hash, i);
> > +		log.value.update.name = (char *) "John Doe";
> > +		log.value.update.email = (char *) "johndoe@anon.org";
> > +		log.value.update.time = 0x6673e5b9;
> > +		log.value.update.message = (char *) "message";
> > +
> > +		n = reftable_writer_add_log(w, &log);
> > +		check_int(n, ==, 0);
> > +	}
> > +
> > +	n = reftable_writer_close(w);
> > +	check_int(n, ==, 0);
> > +
> > +	test_msg("testing printing functionality:");
> 
> Is it intentionally that this line still exists? If so, I think it
> really only causes unnecessary noise and should rather be dropped.
> 
> > +	n = reftable_reader_print_file(tmp->filename.buf);
> > +	check_int(n, ==, 0);
> 
> Wait, doesn't this print to stdout? I don't think it is a good idea to
> exercise the function as-is. For one, it would pollute stdout with data
> that we shouldn't care about. Second, it doesn't verify that the result
> is actually what we expect.
> 
> I can see two options:
> 
>   1. Refactor these interfaces such that they take a file descriptor as
>      input that they are writing to. This would allow us to exercise
>      that the output is correct.
> 
>   2. Rip out this function. I don't think this functionality should be
>      part of the library in the first place, and it really only exists
>      because of "reftable/dump.c".
> 
> I think the latter is the better option. The functionality exists to
> drive `cmd__dump_reftable()` in our reftable test helper. We should
> likely make the whole implementation of this an internal implementation
> detail and not expose it.

For the record: I've got a bigger patch series in development that drops
the generic reftable interfaces. As part of this, I'll also rip out the
functionality provided by "reftabel/dump.c".

Patrick

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2024-08-08 12:00 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-07 14:11 [GSoC][PATCH 0/5] t: port reftable/readwrite_test.c to the unit testing framework Chandra Pratap
2024-08-07 14:11 ` [PATCH 1/5] t: move " Chandra Pratap
2024-08-07 14:11 ` [PATCH 2/5] t-reftable-readwrite: use free_names() instead of a for loop Chandra Pratap
2024-08-07 14:11 ` [PATCH 3/5] t-reftable-readwrite: use 'for' in place of infinite 'while' loops Chandra Pratap
2024-08-07 14:12 ` [PATCH 4/5] t-reftable-readwrite: add test for known error Chandra Pratap
2024-08-07 14:12 ` [PATCH 5/5] t-reftable-readwrite: add tests for print functions Chandra Pratap
2024-08-08  8:12   ` Patrick Steinhardt
2024-08-08 12:00     ` Patrick Steinhardt [this message]
2024-08-08 14:25       ` Chandra Pratap
2024-08-09 16:56     ` Junio C Hamano
2024-08-09 11:05 ` [GSoC][PATCH v2 0/4] t: port reftable/readwrite_test.c to the unit testing framework Chandra Pratap
2024-08-09 11:05   ` [PATCH v2 1/4] t: move " Chandra Pratap
2024-08-09 18:12     ` Junio C Hamano
2024-08-12 14:50       ` Chandra Pratap
2024-08-09 11:05   ` [PATCH v2 2/4] t-reftable-readwrite: use free_names() instead of a for loop Chandra Pratap
2024-08-09 18:57     ` Junio C Hamano
2024-08-10  5:50       ` Chandra Pratap
2024-08-10  6:10         ` Junio C Hamano
2024-08-09 11:05   ` [PATCH v2 3/4] t-reftable-readwrite: use 'for' in place of infinite 'while' loops Chandra Pratap
2024-08-09 19:06     ` Junio C Hamano
2024-08-09 11:05   ` [PATCH v2 4/4] t-reftable-readwrite: add test for known error Chandra Pratap
2024-08-13 14:34   ` [GSoC][PATCH v3 0/4] t: port reftable/readwrite_test.c to the unit testing framework Chandra Pratap
2024-08-13 14:34     ` [PATCH v3 1/4] t: move " Chandra Pratap
2024-08-13 22:33       ` Josh Steadmon
2024-08-14 11:48         ` Chandra Pratap
2024-08-14 13:08         ` Patrick Steinhardt
2024-08-13 14:34     ` [PATCH v3 2/4] t-reftable-readwrite: use free_names() instead of a for loop Chandra Pratap
2024-08-13 14:34     ` [PATCH v3 3/4] t-reftable-readwrite: use 'for' in place of infinite 'while' loops Chandra Pratap
2024-08-13 14:34     ` [PATCH v3 4/4] t-reftable-readwrite: add test for known error Chandra Pratap
2024-08-13 17:10     ` [GSoC][PATCH v3 0/4] t: port reftable/readwrite_test.c to the unit testing framework 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=ZrSzbdNkCS2LOXaL@tanuki \
    --to=ps@pks.im \
    --cc=chandrapratap3519@gmail.com \
    --cc=chriscool@tuxfamily.org \
    --cc=git@vger.kernel.org \
    /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).