On 03/30/2017 05:32 AM, Daniel Ferreira wrote:
> 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

Reply via email to