git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [GSoC][PATCH] t: migrate helper/test-urlmatch-normalization to unit tests

From
Ghanshyam Thakkar <shyamthakkar001@gmail.com>
Date
Jul 24, 2024, 07:06 UTC
Message-ID
<D2XKUY6MQJOR.2B3YHEXQPOQQL@gmail.com>
In-Reply-To
<ZqCO6JTQqdxD73Wq@tanuki>
Patrick Steinhardt <ps@pks.im> wrote:
Show 34 quoted lines
> On Wed, Jul 24, 2024 at 05:54:33AM +0530, Ghanshyam Thakkar wrote:
> > Patrick Steinhardt <ps@pks.im> wrote:
> > > On Fri, Jun 28, 2024 at 06:26:24PM +0530, Ghanshyam Thakkar wrote:
> > > > +	free(url1_norm);
> > > > +	free(url2_norm);
> > > > +}
> > > > +
> > > > +static void check_normalized_url_from_file(const char *file, const char *expect)
> > > > +{
> > > > +	struct strbuf content = STRBUF_INIT, path = STRBUF_INIT;
> > > > +
> > > > +	strbuf_getcwd(&path);
> > > > +	strbuf_strip_suffix(&path, "/unit-tests/bin"); /* because 'unit-tests-test-tool' is run from 'bin' directory */
> > >
> > > Curious: is this a new requirement or do other tests have the same
> > > requirement? I was under the impression that I could execude the
> > > resulting unit test binaries from whatever directory I wanted to, but
> > > didn't verify.
> > 
> > I am not aware of any requirements, but if we want to interact with
> > other files like in this case (and where we potentially have to
> > interact with a test repository), we'd need to have some requirement
> > to construct the path to these data files (and the test repository),
> > similar to end-to-end tests where they can be run in only t/
> > directory. Do you think calling `setup_git_directory()` and then using
> > `the_repository->worktree` to get the root of the worktree of Git source
> > and then construct the path relative to that, would be useful? That way
> > we can atleast call the binaries from anywhere within the tree.
>
> Instead of using the working directory, you can also use the `__FILE__`
> preprocessor macro to access the files relative to the directory of the
> original source file. That at least makes it possible to execute the
> result from all directories, but still obviously ties us to the location
> of the source directory.

But doesn't '__FILE__' give relative path instead of absolute? A quick test_msg() tells me that '__FILE__' gives the path 't/unit-tests/t-urlmatch-normalization.c' for me. So, I don't know how we would be able to execute from _all_ directories. Although, I think the restriction of running from only 't/' would be fine as end-to-end tests have similar restrictions.

> Whether that's ultimately much better.. dunno. But I guess this should
> at least be discussed in the commit message.
Will update.
Show 6 quoted lines
>
> > (P.S. I know we want to avoid using `the_repository`, but I don't know
> > any other way yet.)
>
> You can use e.g. "t/helper/test-repository.c" as an example, where we
> use `repo_init()` to initialize a local repository variable.

But it requires us to know the path to the repo and worktree in advance, which kinda defeats the purpose of using 'repository->worktree'. setup_git_directory() sets up 'the_repository' from any subdirectory of the worktree, so we can get the root without us having to know which sub-directory (of the worktree) we are in.

Thanks.
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 9 of 23 in “t: migrate helper/test-urlmatch-normalization to unit tests”
  1. Ghanshyam ThakkarJun 28, 2024
  2. Ghanshyam ThakkarJul 9, 2024
  3. Karthik NayakJul 22, 2024
  4. Ghanshyam ThakkarJul 22, 2024
  5. Karthik NayakJul 23, 2024
  6. Patrick SteinhardtJul 23, 2024
  7. Ghanshyam ThakkarJul 24, 2024
  8. Patrick SteinhardtJul 24, 2024
  9. Ghanshyam ThakkarJul 24, 2024
  10. Patrick SteinhardtJul 24, 2024
  11. [GSoC][PATCH v2] t: migrate t0110-urlmatch-normalization to the new frameworkGhanshyam Thakkar, Aug 13, 2024
  12. Junio C HamanoAug 13, 2024
  13. Kaartic SivaraamAug 14, 2024
  14. Junio C HamanoAug 14, 2024
  15. Ghanshyam ThakkarAug 14, 2024
  16. Kaartic SivaraamAug 14, 2024
  17. [GSoC][PATCH v3] t: migrate t0110-urlmatch-normalization to the new frameworkGhanshyam Thakkar, Aug 14, 2024
  18. Junio C HamanoAug 14, 2024
  19. Christian CouderAug 19, 2024
  20. [GSoC][PATCH v4] t: migrate t0110-urlmatch-normalization to the new frameworkGhanshyam Thakkar, Aug 20, 2024
  21. Ghanshyam ThakkarAug 20, 2024
  22. Christian CouderAug 21, 2024
  23. Junio C HamanoAug 21, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.