From: Daniel Ferreira <bnmvco@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, sbeller@google.com, pclouds@gmail.com,
mhagger@alum.mit.edu, Daniel Ferreira <bnmvco@gmail.com>
Subject: [PATCH v5 4/6] dir_iterator: add tests for dir_iterator API
Date: Thu, 30 Mar 2017 00:32:08 -0300 [thread overview]
Message-ID: <1490844730-47634-5-git-send-email-bnmvco@gmail.com> (raw)
In-Reply-To: <1490844730-47634-1-git-send-email-bnmvco@gmail.com>
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.
Signed-off-by: Daniel Ferreira <bnmvco@gmail.com>
---
Makefile | 1 +
t/helper/test-dir-iterator.c | 32 +++++++++++++++++++++++++++++++
t/t0065-dir-iterator.sh | 45 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 78 insertions(+)
create mode 100644 t/helper/test-dir-iterator.c
create mode 100755 t/t0065-dir-iterator.sh
diff --git a/Makefile b/Makefile
index a5a11e7..d0245f3 100644
--- a/Makefile
+++ b/Makefile
@@ -607,6 +607,7 @@ TEST_PROGRAMS_NEED_X += test-ctype
TEST_PROGRAMS_NEED_X += test-config
TEST_PROGRAMS_NEED_X += test-date
TEST_PROGRAMS_NEED_X += test-delta
+TEST_PROGRAMS_NEED_X += test-dir-iterator
TEST_PROGRAMS_NEED_X += test-dump-cache-tree
TEST_PROGRAMS_NEED_X += test-dump-split-index
TEST_PROGRAMS_NEED_X += test-dump-untracked-cache
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 @@
+#include "cache.h"
+#include "blob.h"
+#include "dir.h"
+#include "streaming.h"
+#include "iterator.h"
+#include "dir-iterator.h"
+
+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;
+}
diff --git a/t/t0065-dir-iterator.sh b/t/t0065-dir-iterator.sh
new file mode 100755
index 0000000..3c8ea9a
--- /dev/null
+++ b/t/t0065-dir-iterator.sh
@@ -0,0 +1,45 @@
+#!/bin/sh
+
+test_description='Test directory iteration.'
+
+. ./test-lib.sh
+
+ITER_SORTED_OUTPUT='[d] (a) ./dir/a
+[d] (a/b) ./dir/a/b
+[d] (a/b/c) ./dir/a/b/c
+[d] (d) ./dir/d
+[d] (d/e) ./dir/d/e
+[d] (d/e/d) ./dir/d/e/d
+[f] (a/b/c/d) ./dir/a/b/c/d
+[f] (a/e) ./dir/a/e
+[f] (b) ./dir/b
+[f] (c) ./dir/c
+[f] (d/e/d/a) ./dir/d/e/d/a'
+
+test_expect_success 'dir-iterator should iterate through all files' '
+ mkdir -p dir &&
+ mkdir -p dir/a/b/c/ &&
+ date >dir/b &&
+ date >dir/c &&
+ mkdir -p dir/d/e/d/ &&
+ date >dir/a/b/c/d &&
+ date >dir/a/e &&
+ date >dir/d/e/d/a &&
+
+ test-dir-iterator ./dir >it &&
+ test "$(sort it)" == "$ITER_SORTED_OUTPUT"
+'
+
+ITER_POST_ORDER_OUTPUT='[f] (a/b/c/d) ./dir2/a/b/c/d
+[d] (a/b/c) ./dir2/a/b/c
+[d] (a/b) ./dir2/a/b
+[d] (a) ./dir2/a'
+
+test_expect_success 'dir-iterator should list files properly on post-order mode' '
+ mkdir -p dir2/a/b/c/ &&
+ date >dir2/a/b/c/d &&
+
+ test "$(test-dir-iterator ./dir2 --post-order)" == "$ITER_POST_ORDER_OUTPUT"
+'
+
+test_done
--
2.7.4 (Apple Git-66)
next prev parent reply other threads:[~2017-03-30 3:32 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-30 3:32 [PATCH v5 0/6] [GSoC] remove_subtree(): reimplement using iterators Daniel Ferreira
2017-03-30 3:32 ` [PATCH v5 1/6] dir_iterator: add helpers to dir_iterator_advance Daniel Ferreira
2017-03-30 3:32 ` [PATCH v5 2/6] dir_iterator: refactor state machine model Daniel Ferreira
2017-03-30 8:18 ` Michael Haggerty
2017-03-30 3:32 ` [PATCH v5 3/6] dir_iterator: iterate over dir after its contents Daniel Ferreira
2017-03-30 11:03 ` Michael Haggerty
2017-03-30 3:32 ` Daniel Ferreira [this message]
2017-03-30 7:46 ` [PATCH v5 4/6] dir_iterator: add tests for dir_iterator API Michael Haggerty
2017-03-30 18:25 ` Daniel Ferreira (theiostream)
2017-04-01 9:03 ` Jeff King
2017-04-01 17:16 ` Junio C Hamano
2017-03-30 7:48 ` Michael Haggerty
2017-03-30 8:05 ` Michael Haggerty
2017-03-30 18:26 ` Daniel Ferreira (theiostream)
2017-03-30 3:32 ` [PATCH v5 5/6] remove_subtree(): reimplement using iterators Daniel Ferreira
2017-03-30 3:32 ` [PATCH v5 6/6] remove_subtree(): test removing nested directories Daniel Ferreira
2017-03-30 11:07 ` Michael Haggerty
2017-03-30 11:27 ` [PATCH v5 0/6] [GSoC] remove_subtree(): reimplement using iterators Michael Haggerty
2017-03-30 12:10 ` Duy Nguyen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1490844730-47634-5-git-send-email-bnmvco@gmail.com \
--to=bnmvco@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=mhagger@alum.mit.edu \
--cc=pclouds@gmail.com \
--cc=sbeller@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).