dir-iterator: add tests for dir-iterator API
Create t/helper/test-dir-iterator.c, which prints relevant information about a directory tree iterated over with dir-iterator. Create t/t0066-dir-iterator.sh, which tests that dir-iterator does iterate through a whole directory tree as expected. Signed-off-by: Daniel Ferreira <bnmvco@gmail.com> [matheus.bernardino: update to use test-tool and some minor aesthetics] Helped-by: Matheus Tavares <matheus.bernardino@usp.br> Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
36596fd2df
commit
150791adbf
33
t/helper/test-dir-iterator.c
Normal file
33
t/helper/test-dir-iterator.c
Normal file
@ -0,0 +1,33 @@
|
||||
#include "test-tool.h"
|
||||
#include "git-compat-util.h"
|
||||
#include "strbuf.h"
|
||||
#include "iterator.h"
|
||||
#include "dir-iterator.h"
|
||||
|
||||
/* Argument is a directory path to iterate over */
|
||||
int cmd__dir_iterator(int argc, const char **argv)
|
||||
{
|
||||
struct strbuf path = STRBUF_INIT;
|
||||
struct dir_iterator *diter;
|
||||
|
||||
if (argc < 2)
|
||||
die("BUG: test-dir-iterator needs one argument");
|
||||
|
||||
strbuf_add(&path, argv[1], strlen(argv[1]));
|
||||
|
||||
diter = dir_iterator_begin(path.buf);
|
||||
|
||||
while (dir_iterator_advance(diter) == ITER_OK) {
|
||||
if (S_ISDIR(diter->st.st_mode))
|
||||
printf("[d] ");
|
||||
else if (S_ISREG(diter->st.st_mode))
|
||||
printf("[f] ");
|
||||
else
|
||||
printf("[?] ");
|
||||
|
||||
printf("(%s) [%s] %s\n", diter->relative_path, diter->basename,
|
||||
diter->path.buf);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user