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

Re: [PATCH v5 4/6] dir_iterator: add tests for dir_iterator API

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Mar 30, 2017, 08:05 UTC
Message-ID
<a738d683-0f2d-61b9-5ecf-ef8bc8f98ff6@alum.mit.edu>
In-Reply-To
<1490844730-47634-5-git-send-email-bnmvco@gmail.com>
On 03/30/2017 05:32 AM, Daniel Ferreira wrote:
Show 42 quoted lines
> Create t/helper/test-dir-iterator.c, which prints relevant information
> about a directory tree iterated over with dir_iterator.
> 
> Create t/t0065-dir-iterator.sh, which tests that dir_iterator does
> iterate through a whole directory tree and that post-order directory
> iteration is correctly implemented.
> 
> [...]
> diff --git a/t/helper/test-dir-iterator.c b/t/helper/test-dir-iterator.c
> new file mode 100644
> index 0000000..b4a148f
> --- /dev/null
> +++ b/t/helper/test-dir-iterator.c
> @@ -0,0 +1,32 @@
> [...]
> +
> +int cmd_main(int argc, const char **argv) {
> +	if (argc < 2) {
> +		return 1;
> +	}
> +
> +	struct strbuf path = STRBUF_INIT;
> +	strbuf_add(&path, argv[1], strlen(argv[1]));
> +
> +	unsigned flag = 0;
> +	if (argc == 3 && strcmp(argv[2], "--post-order") == 0)
> +		flag = DIR_ITERATOR_POST_ORDER_TRAVERSAL;
> +
> +	struct dir_iterator *diter = dir_iterator_begin((&path)->buf, flag);
> +
> +	while (dir_iterator_advance(diter) == ITER_OK) {
> +		if (S_ISDIR(diter->st.st_mode))
> +			printf("[d] ");
> +		else
> +			printf("[f] ");
> +
> +		printf("(%s) %s\n", diter->relative_path, diter->path.buf);
> +	}
> +
> +	return 0;
> +}
> [...]

Oh I forgot to mention, in the Git project we don't allow declarations to be mixed with code. Apparently there's some ancient compiler somewhere that doesn't allow it. Declarations always have to be together, at the top of a block. (Compile with `-Werror=declaration-after-statement` to detect this.)

Michael
Previous: Michael HaggertyNext: Daniel Ferreira (theiostream)
Message 13 of 19 in “[GSoC] remove_subtree(): reimplement using iterators”
  1. 0/6 [GSoC] remove_subtree(): reimplement using iteratorsDaniel Ferreira, Mar 30, 2017
  2. 1/6 dir_iterator: add helpers to dir_iterator_advanceDaniel Ferreira, Mar 30, 2017
  3. 2/6 dir_iterator: refactor state machine modelDaniel Ferreira, Mar 30, 2017
  4. Michael HaggertyMar 30, 2017
  5. 3/6 dir_iterator: iterate over dir after its contentsDaniel Ferreira, Mar 30, 2017
  6. Michael HaggertyMar 30, 2017
  7. 4/6 dir_iterator: add tests for dir_iterator APIDaniel Ferreira, Mar 30, 2017
  8. Michael HaggertyMar 30, 2017
  9. Daniel Ferreira (theiostream)Mar 30, 2017
  10. Jeff KingApr 1, 2017
  11. Junio C HamanoApr 1, 2017
  12. Michael HaggertyMar 30, 2017
  13. Michael HaggertyMar 30, 2017
  14. Daniel Ferreira (theiostream)Mar 30, 2017
  15. 5/6 remove_subtree(): reimplement using iteratorsDaniel Ferreira, Mar 30, 2017
  16. 6/6 remove_subtree(): test removing nested directoriesDaniel Ferreira, Mar 30, 2017
  17. Michael HaggertyMar 30, 2017
  18. Michael HaggertyMar 30, 2017
  19. Duy NguyenMar 30, 2017

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.