Re: [PATCH 3/4] unit-tests: do show relative file paths
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Sep 18, 2023, 21:00 UTC
- Message-ID
- <b14a99f8-46c2-b54d-e24b-919f3ac8f2e0@gmx.de>
- In-Reply-To
- <69f6f263-06e1-4fef-abd9-d6c03ae0c148@gmail.com>
Hi Phillip,
On Mon, 11 Sep 2023, Phillip Wood wrote:
Show 34 quoted lines
> 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.I changed the code not to use a strbuf, and I'm now working exclusively on static buffers instead of `malloc()`ing anything.
Thank you, Johannes