io.directories.search: fix traversal test case cross-platform issues.

on Linux and macOS mojave they entries might traverse (a,c,b)
instead of (a,b.c) so we preserve the traversal method order
but sort for cross-platform testing.
windows-drag
John Benediktsson 2019-03-16 20:29:19 -07:00
parent ada81e77f5
commit b942caf3d7
1 changed files with 46 additions and 48 deletions

View File

@ -1,7 +1,7 @@
USING: combinators fry io.directories io.directories.hierarchy USING: combinators fry io.directories io.directories.hierarchy
io.directories.search io.files.unique io.pathnames kernel io.directories.search io.files.unique io.pathnames kernel math
namespaces sequences sorting splitting strings system namespaces sequences sorting splitting splitting.monotonic
tools.test ; strings tools.test ;
{ t } [ { t } [
[ [
@ -47,49 +47,42 @@ tools.test ;
[ drop f ] find-up-to-root [ drop f ] find-up-to-root
] unit-test ] unit-test
os linux? [ [
{ {
V{ 1 2 3 2 3 1 2 3 2 3 1 2 3 2 3 } "/a"
V{ 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3 } "/a/a"
"/a/a/a"
"/a/b"
"/a/b/a"
"/b"
"/b/a"
"/b/a/a"
"/b/b"
"/b/b/a"
"/c"
"/c/a"
"/c/a/a"
"/c/b"
"/c/b/a"
}
{
"/a"
"/b"
"/c"
"/a/a"
"/a/b"
"/b/a"
"/b/b"
"/c/a"
"/c/b"
"/a/a/a"
"/a/b/a"
"/b/a/a"
"/b/b/a"
"/c/a/a"
"/c/b/a"
} }
] [ ] [
{
V{
"/a"
"/a/a"
"/a/a/a"
"/a/b"
"/a/b/a"
"/b"
"/b/a"
"/b/a/a"
"/b/b"
"/b/b/a"
"/c"
"/c/a"
"/c/a/a"
"/c/b"
"/c/b/a"
}
V{
"/a"
"/b"
"/c"
"/a/a"
"/a/b"
"/b/a"
"/b/b"
"/c/a"
"/c/b"
"/a/a/a"
"/a/b/a"
"/b/a/a"
"/b/b/a"
"/c/a/a"
"/c/b/a"
}
}
] if [
[ [
"a" make-directory "a" make-directory
"a/a" make-directory "a/a" make-directory
@ -110,16 +103,21 @@ os linux? [
+depth-first+ traversal-method [ +depth-first+ traversal-method [
"." recursive-directory-files "." recursive-directory-files
current-directory get '[ _ ?head drop ] map current-directory get '[ _ ?head drop ] map
! preserve file traversal order, but sort
! alphabetically for cross-platform testing
[ [ length ] bi@ < ] monotonic-split
[ natural-sort ] map natural-sort concat
] with-variable ] with-variable
+breadth-first+ traversal-method [ +breadth-first+ traversal-method [
"." recursive-directory-files "." recursive-directory-files
current-directory get '[ _ ?head drop ] map current-directory get '[ _ ?head drop ] map
] with-variable
! Linux doesn't return alphabetic ordering ! preserve file traversal order, but sort
os linux? [ ! alphabetically for cross-platform testing
[ [ path-components length ] map ] bi@ [ [ length ] bi@ = ] monotonic-split
] when [ natural-sort ] map concat
] with-variable
] with-test-directory ] with-test-directory
] unit-test ] unit-test