From: Phillip Wood <phillip.wood123@gmail.com>
To: Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>,
git@vger.kernel.org
Cc: Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: Re: [PATCH 3/4] unit-tests: do show relative file paths
Date: Mon, 11 Sep 2023 14:25:09 +0100 [thread overview]
Message-ID: <69f6f263-06e1-4fef-abd9-d6c03ae0c148@gmail.com> (raw)
In-Reply-To: <2b4e36c05c9e01b1e489100531fd01515b0786ab.1693462532.git.gitgitgadget@gmail.com>
Hi Johannes
On 31/08/2023 07:15, Johannes Schindelin via GitGitGadget wrote:
> From: Johannes Schindelin <johannes.schindelin@gmx.de>
>
> Visual C interpolates `__FILE__` with the absolute _Windows_ path of
> the source file. GCC interpolates it with the relative path, and the
> tests even verify that.
Oh, that's a pain
> So let's make sure that the unit tests only emit such paths.
Makes sense
> +#ifndef _MSC_VER
> +#define make_relative(location) location
> +#else
> +/*
> + * Visual C interpolates the absolute Windows path for `__FILE__`,
> + * but we want to see relative paths, as verified by t0080.
> + */
> +#include "strbuf.h"
> +#include "dir.h"
> +
> +static const char *make_relative(const char *location)
> +{
> + static const char *prefix;
> + static size_t prefix_len;
> + static struct strbuf buf = STRBUF_INIT;
So far test-lib.c avoids using things like struct strbuf that it will be
used to test. In this instance we're only using it on one particular
compiler so it may not matter so much. We could avoid it but I'm not
sure it is worth the extra complexity. One thing I noted in this patch
is that prefix is leaked but I'm not sure if you run any leak checkers
on the msvc build.
static const char *make_relative(const char *location)
{
static char prefix[] = __FILE__
static size_t *prefix_len = (size_t)-1;
static char buf[PATH_MAX];
if (prefix == (size_t)-1) {
const char *path = "\\t\unit-tests\\test-lib.c";
size_t path_len = strlen(path);
prefix_len = strlen(prefix);
if (prefix_len < path_len) ||
memcmp(prefix + prefix_len - path_len, path, path_len)
die(...);
prefix_len -= path_len - 1; /* keep trailing '\\' */
prefix[prefix_len] = '\0';
}
/* Does it not start with the expected prefix? */
if (fspathncmp(location, prefix, prefix_len))
return location;
if (strlen(location) - prefix_len > sizeof(buf) - 1)
die(...)
/* +1 to copy NUL terminator */
memcpy(buf, location + prefix_len, strlen(location) - prefix_len + 1);
convert_slashes(buf);
return buf;
}
Best Wishes
Phillip
next prev parent reply other threads:[~2023-09-11 21:39 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-31 6:15 [PATCH 0/4] CMake(Visual C) support for js/doc-unit-tests Johannes Schindelin via GitGitGadget
2023-08-31 6:15 ` [PATCH 1/4] cmake: also build unit tests Johannes Schindelin via GitGitGadget
2023-09-11 13:23 ` Phillip Wood
2023-09-18 20:58 ` Johannes Schindelin
2023-08-31 6:15 ` [PATCH 2/4] unit-tests: do not mistake `.pdb` files for being executable Johannes Schindelin via GitGitGadget
2023-08-31 6:15 ` [PATCH 3/4] unit-tests: do show relative file paths Johannes Schindelin via GitGitGadget
2023-09-11 13:25 ` Phillip Wood [this message]
2023-09-18 21:00 ` Johannes Schindelin
2023-08-31 6:15 ` [PATCH 4/4] artifacts-tar: when including `.dll` files, don't forget the unit-tests Johannes Schindelin via GitGitGadget
2023-09-18 20:54 ` [PATCH v2 0/7] CMake(Visual C) support for js/doc-unit-tests Johannes Schindelin via GitGitGadget
2023-09-18 20:54 ` [PATCH v2 1/7] cmake: also build unit tests Johannes Schindelin via GitGitGadget
2023-09-18 20:54 ` [PATCH v2 2/7] unit-tests: do not mistake `.pdb` files for being executable Johannes Schindelin via GitGitGadget
2023-09-18 20:54 ` [PATCH v2 3/7] unit-tests: do show relative file paths Johannes Schindelin via GitGitGadget
2023-09-22 14:35 ` Phillip Wood
2023-09-18 20:54 ` [PATCH v2 4/7] artifacts-tar: when including `.dll` files, don't forget the unit-tests Johannes Schindelin via GitGitGadget
2023-09-18 20:54 ` [PATCH v2 5/7] cmake: fix typo in variable name Johannes Schindelin via GitGitGadget
2023-09-18 20:54 ` [PATCH v2 6/7] cmake: use test names instead of full paths Johannes Schindelin via GitGitGadget
2023-09-22 14:37 ` Phillip Wood
2023-09-25 9:06 ` Johannes Schindelin
2023-09-18 20:54 ` [PATCH v2 7/7] cmake: handle also unit tests Johannes Schindelin via GitGitGadget
2023-09-22 14:39 ` Phillip Wood
2023-09-25 11:20 ` [PATCH v3 0/7] CMake(Visual C) support for js/doc-unit-tests Johannes Schindelin via GitGitGadget
2023-09-25 11:20 ` [PATCH v3 1/7] cmake: also build unit tests Johannes Schindelin via GitGitGadget
2023-09-25 11:20 ` [PATCH v3 2/7] unit-tests: do not mistake `.pdb` files for being executable Johannes Schindelin via GitGitGadget
2023-09-25 11:20 ` [PATCH v3 3/7] unit-tests: do show relative file paths Johannes Schindelin via GitGitGadget
2023-09-25 11:20 ` [PATCH v3 4/7] artifacts-tar: when including `.dll` files, don't forget the unit-tests Johannes Schindelin via GitGitGadget
2023-09-25 11:20 ` [PATCH v3 5/7] cmake: fix typo in variable name Johannes Schindelin via GitGitGadget
2023-09-25 11:20 ` [PATCH v3 6/7] cmake: use test names instead of full paths Johannes Schindelin via GitGitGadget
2023-09-25 11:20 ` [PATCH v3 7/7] cmake: handle also unit tests Johannes Schindelin via GitGitGadget
2023-09-25 19:09 ` [PATCH v3 0/7] CMake(Visual C) support for js/doc-unit-tests 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=69f6f263-06e1-4fef-abd9-d6c03ae0c148@gmail.com \
--to=phillip.wood123@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=johannes.schindelin@gmx.de \
--cc=phillip.wood@dunelm.org.uk \
/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).