io: fix some temp-files in the tests to use unique-files.

locals-and-roots
John Benediktsson 2016-03-31 00:23:13 -07:00
parent 498285d7dd
commit d2daa05790
4 changed files with 231 additions and 205 deletions

View File

@ -1,7 +1,7 @@
USING: continuations destructors io io.directories USING: continuations destructors io io.directories
io.directories.hierarchy io.encodings.ascii io.encodings.utf8 io.directories.hierarchy io.encodings.ascii io.encodings.utf8
io.files io.files.info io.files.temp io.launcher io.pathnames io.files io.files.info io.files.temp io.files.unique io.launcher
kernel sequences tools.test ; io.pathnames kernel sequences tools.test ;
IN: io.directories.tests IN: io.directories.tests
{ { "kernel" } } [ { { "kernel" } } [
@ -77,113 +77,119 @@ IN: io.directories.tests
] with-temp-directory ] with-temp-directory
] unit-test ] unit-test
{ } [ [
[
{ } [
{ "Hello world." } { "Hello world." }
"test-foo.txt" temp-file ascii set-file-lines "test-foo.txt" ascii set-file-lines
] unit-test ] unit-test
{ } [ { } [
"test-foo.txt" temp-file ascii [ "test-foo.txt" ascii [
"Hello appender." print "Hello appender." print
] with-file-appender ] with-file-appender
] unit-test ] unit-test
{ } [ { } [
"test-bar.txt" temp-file ascii [ "test-bar.txt" ascii [
"Hello appender." print "Hello appender." print
] with-file-appender ] with-file-appender
] unit-test ] unit-test
{ "Hello world.\nHello appender.\n" } [ { "Hello world.\nHello appender.\n" } [
"test-foo.txt" temp-file ascii file-contents "test-foo.txt" ascii file-contents
] unit-test ] unit-test
{ "Hello appender.\n" } [ { "Hello appender.\n" } [
"test-bar.txt" temp-file ascii file-contents "test-bar.txt" ascii file-contents
] unit-test ] unit-test
{ } [ "test-foo.txt" temp-file delete-file ] unit-test { } [ "test-foo.txt" delete-file ] unit-test
{ } [ "test-bar.txt" delete-file ] unit-test
{ } [ "test-bar.txt" temp-file delete-file ] unit-test { f } [ "test-foo.txt" exists? ] unit-test
{ f } [ "test-bar.txt" exists? ] unit-test
] cleanup-unique-directory
] with-temp-directory
{ f } [ "test-foo.txt" temp-file exists? ] unit-test [
[
{ } [ "test-blah" make-directory ] unit-test
{ f } [ "test-bar.txt" temp-file exists? ] unit-test { } [
"test-blah/fooz" ascii <file-writer> dispose
] unit-test
[ "test-blah" temp-file delete-tree ] ignore-errors { t } [
"test-blah/fooz" exists?
] unit-test
{ } [ "test-blah" temp-file make-directory ] unit-test { } [ "test-blah/fooz" delete-file ] unit-test
{ } [ "test-blah" delete-directory ] unit-test
{ } [ { f } [ "test-blah" exists? ] unit-test
"test-blah/fooz" temp-file ascii <file-writer> dispose ] cleanup-unique-directory
] unit-test ] with-temp-directory
{ t } [ [
"test-blah/fooz" temp-file exists? [
] unit-test { } [ "delete-tree-test/a/b/c" make-directories ] unit-test
{ } [ "test-blah/fooz" temp-file delete-file ] unit-test { } [
{ "Hi" } "delete-tree-test/a/b/c/d" ascii set-file-lines
] unit-test
{ } [ "test-blah" temp-file delete-directory ] unit-test { } [ "delete-tree-test" delete-tree ] unit-test
] cleanup-unique-directory
] with-temp-directory
{ f } [ "test-blah" temp-file exists? ] unit-test [
[
{ } [
"copy-tree-test/a/b/c" make-directories
] unit-test
{ } [ "delete-tree-test/a/b/c" temp-file make-directories ] unit-test { } [
{ } [
{ "Hi" }
"delete-tree-test/a/b/c/d" temp-file ascii set-file-lines
] unit-test
{ } [
"delete-tree-test" temp-file delete-tree
] unit-test
{ } [
"copy-tree-test/a/b/c" temp-file make-directories
] unit-test
{ } [
"Foobar" "Foobar"
"copy-tree-test/a/b/c/d" temp-file "copy-tree-test/a/b/c/d"
ascii set-file-contents ascii set-file-contents
] unit-test ] unit-test
{ } [ { } [
"copy-tree-test" temp-file "copy-tree-test" "copy-destination" copy-tree
"copy-destination" temp-file copy-tree ] unit-test
] unit-test
{ "Foobar" } [ { "Foobar" } [
"copy-destination/a/b/c/d" temp-file ascii file-contents "copy-destination/a/b/c/d" ascii file-contents
] unit-test ] unit-test
{ } [ { } [
"copy-destination" temp-file delete-tree "copy-destination" delete-tree
] unit-test ] unit-test
{ } [ { } [
"copy-tree-test" temp-file "copy-tree-test" "copy-destination" copy-tree-into
"copy-destination" temp-file copy-tree-into ] unit-test
] unit-test
{ "Foobar" } [ { "Foobar" } [
"copy-destination/copy-tree-test/a/b/c/d" temp-file ascii file-contents "copy-destination/copy-tree-test/a/b/c/d" ascii file-contents
] unit-test ] unit-test
{ } [ { } [
"copy-destination/copy-tree-test/a/b/c/d" temp-file "" temp-file copy-file-into "copy-destination/copy-tree-test/a/b/c/d" "." copy-file-into
] unit-test ] unit-test
{ "Foobar" } [ { "Foobar" } [
"d" temp-file ascii file-contents "d" ascii file-contents
] unit-test ] unit-test
{ } [ "d" temp-file delete-file ] unit-test { } [ "d" delete-file ] unit-test
{ } [ "copy-destination" temp-file delete-tree ] unit-test { } [ "copy-destination" delete-tree ] unit-test
{ } [ "copy-tree-test" temp-file delete-tree ] unit-test { } [ "copy-tree-test" delete-tree ] unit-test
] cleanup-unique-directory
] with-temp-directory
{ } [ "resource:deleteme" touch-file ] unit-test { } [ "resource:deleteme" touch-file ] unit-test
{ } [ "resource:deleteme" delete-file ] unit-test { } [ "resource:deleteme" delete-file ] unit-test

View File

@ -1,37 +1,41 @@
IN: io.monitors.linux.tests IN: io.monitors.linux.tests
USING: io.monitors tools.test io.files io.files.temp USING: io.monitors tools.test io.files io.files.temp
io.directories system sequences continuations namespaces io.files.unique io.directories io.pathnames system sequences
concurrency.count-downs kernel io threads calendar prettyprint continuations namespaces concurrency.count-downs kernel io
destructors io.timeouts accessors ; threads calendar prettyprint destructors io.timeouts accessors ;
! On Linux, a notification on the directory itself would report an invalid ! On Linux, a notification on the directory itself would report an invalid
! path name ! path name
[ [
[ ] [ "monitor-test-self" temp-file make-directories ] unit-test [
[
! Non-recursive ! Non-recursive
[ ] [ "monitor-test-self" temp-file f <monitor> "m" set ] unit-test { } [
[ ] [ 3 seconds "m" get set-timeout ] unit-test "." f <monitor> "m" set
3 seconds "m" get set-timeout
[ ] [ "monitor-test-self" temp-file touch-file ] unit-test "." touch-file
[ t ] [
"m" get next-change path>>
[ "" = ] [ "monitor-test-self" temp-file = ] bi or
] unit-test ] unit-test
[ ] [ "m" get dispose ] unit-test { t } [
"m" get next-change path>>
[ "" = ] [ "." absolute-path = ] bi or
] unit-test
{ } [ "m" get dispose ] unit-test
! Recursive ! Recursive
[ ] [ "monitor-test-self" temp-file t <monitor> "m" set ] unit-test { } [
[ ] [ 3 seconds "m" get set-timeout ] unit-test "." t <monitor> "m" set
3 seconds "m" get set-timeout
[ ] [ "monitor-test-self" temp-file touch-file ] unit-test "." touch-file
[ t ] [
"m" get next-change path>>
[ "" = ] [ "monitor-test-self" temp-file = ] bi or
] unit-test ] unit-test
[ ] [ "m" get dispose ] unit-test { t } [
] with-monitors "m" get next-change path>>
[ "" = ] [ "." absolute-path = ] bi or
] unit-test
{ } [ "m" get dispose ] unit-test
] with-monitors
] cleanup-unique-directory
] with-temp-directory

View File

@ -1,49 +1,46 @@
USING: accessors calendar concurrency.count-downs USING: accessors calendar concurrency.count-downs
concurrency.promises continuations destructors io io.directories concurrency.promises continuations destructors io io.directories
io.directories.hierarchy io.files io.files.temp io.monitors io.files io.files.temp io.files.unique io.monitors io.pathnames
io.pathnames io.timeouts kernel namespaces sequences system io.timeouts kernel namespaces sequences threads tools.test ;
threads tools.test ;
IN: io.monitors.tests IN: io.monitors.tests
os { windows linux macosx } member? [ [
[ [
[ "monitor-test" temp-file delete-tree ] ignore-errors [
{ } [ "." t <monitor> "m" set ] unit-test
[ ] [ "monitor-test" temp-file make-directory ] unit-test { } [ "a1" make-directory ] unit-test
{ } [ "a2" make-directory ] unit-test
{ } [ "a1" "a2" move-file-into ] unit-test
[ ] [ "monitor-test" temp-file t <monitor> "m" set ] unit-test { t } [ "a2/a1" exists? ] unit-test
[ ] [ "monitor-test/a1" temp-file make-directory ] unit-test { } [ "a2/a1/a3.txt" touch-file ] unit-test
[ ] [ "monitor-test/a2" temp-file make-directory ] unit-test { t } [ "a2/a1/a3.txt" exists? ] unit-test
[ ] [ "monitor-test/a1" temp-file "monitor-test/a2" temp-file move-file-into ] unit-test { } [ "a2/a1/a4.txt" touch-file ] unit-test
{ } [ "a2/a1/a5.txt" touch-file ] unit-test
{ } [ "a2/a1/a4.txt" delete-file ] unit-test
{ } [ "a2/a1/a5.txt" "a2/a1/a4.txt" move-file ] unit-test
[ t ] [ "monitor-test/a2/a1" temp-file exists? ] unit-test { t } [ "a2/a1/a4.txt" exists? ] unit-test
[ ] [ "monitor-test/a2/a1/a3.txt" temp-file touch-file ] unit-test { } [ "m" get dispose ] unit-test
[ t ] [ "monitor-test/a2/a1/a3.txt" temp-file exists? ] unit-test
[ ] [ "monitor-test/a2/a1/a4.txt" temp-file touch-file ] unit-test
[ ] [ "monitor-test/a2/a1/a5.txt" temp-file touch-file ] unit-test
[ ] [ "monitor-test/a2/a1/a4.txt" temp-file delete-file ] unit-test
[ ] [ "monitor-test/a2/a1/a5.txt" temp-file "monitor-test/a2/a1/a4.txt" temp-file move-file ] unit-test
[ t ] [ "monitor-test/a2/a1/a4.txt" temp-file exists? ] unit-test
[ ] [ "m" get dispose ] unit-test
] with-monitors ] with-monitors
] cleanup-unique-directory
] with-temp-directory
[
[ [
[ "monitor-test" temp-file delete-tree ] ignore-errors [
[ ] [ "monitor-test/xyz" temp-file make-directories ] unit-test { } [ "xyz" make-directory ] unit-test
[ ] [ "monitor-test" temp-file t <monitor> "m" set ] unit-test { } [ "." t <monitor> "m" set ] unit-test
{ } [ 1 <count-down> "b" set ] unit-test
{ } [ 1 <count-down> "c1" set ] unit-test
{ } [ 1 <count-down> "c2" set ] unit-test
[ ] [ 1 <count-down> "b" set ] unit-test
[ ] [ 1 <count-down> "c1" set ] unit-test
[ ] [ 1 <count-down> "c2" set ] unit-test
[ ] [
[ [
"b" get count-down "b" get count-down
@ -64,47 +61,56 @@ os { windows linux macosx } member? [
"c2" get count-down "c2" get count-down
] "Monitor test thread" spawn drop ] "Monitor test thread" spawn drop
] unit-test
[ ] [ "b" get await ] unit-test { } [ "b" get await ] unit-test
[ ] [ "monitor-test/xyz/test.txt" temp-file touch-file ] unit-test { } [ "xyz/test.txt" touch-file ] unit-test
[ ] [ "c1" get 1 minutes await-timeout ] unit-test { } [ "c1" get 1 minutes await-timeout ] unit-test
[ ] [ "monitor-test/subdir/blah/yxy" temp-file make-directories ] unit-test { } [ "subdir/blah/yxy" make-directories ] unit-test
[ ] [ "monitor-test/subdir/blah/yxy/test.txt" temp-file touch-file ] unit-test { } [ "subdir/blah/yxy/test.txt" touch-file ] unit-test
[ ] [ "c2" get 1 minutes await-timeout ] unit-test { } [ "c2" get 1 minutes await-timeout ] unit-test
! Dispose twice ! Dispose twice
[ ] [ "m" get dispose ] unit-test { } [ "m" get dispose ] unit-test
[ ] [ "m" get dispose ] unit-test { } [ "m" get dispose ] unit-test
] with-monitors ] with-monitors
] cleanup-unique-directory
] with-temp-directory
! Out-of-scope disposal should not fail ! Out-of-scope disposal should not fail
[ ] [ [ "" resource-path f <monitor> ] with-monitors dispose ] unit-test { } [ [ "resource:" f <monitor> ] with-monitors dispose ] unit-test
[ ] [ [ "" resource-path t <monitor> ] with-monitors dispose ] unit-test { } [ [ "resource:" t <monitor> ] with-monitors dispose ] unit-test
! Timeouts ! Timeouts
[
[
[ [
[ ] [ "monitor-timeout-test" temp-file make-directories ] unit-test
! Non-recursive ! Non-recursive
[ ] [ "monitor-timeout-test" temp-file f <monitor> "m" set ] unit-test { } [
[ ] [ 100 milliseconds "m" get set-timeout ] unit-test "." f <monitor> "m" set
100 milliseconds "m" get set-timeout
[ [ t ] [ "m" get next-change drop ] while ] must-fail [ [ t ] [ "m" get next-change drop ] while ] must-fail
[ ] [ "m" get dispose ] unit-test "m" get dispose
] unit-test
! Recursive ! Recursive
[ ] [ "monitor-timeout-test" temp-file t <monitor> "m" set ] unit-test { } [
[ ] [ 100 milliseconds "m" get set-timeout ] unit-test "." t <monitor> "m" set
100 milliseconds "m" get set-timeout
[ [ t ] [ "m" get next-change drop ] while ] must-fail [ [ t ] [ "m" get next-change drop ] while ] must-fail
[ ] [ "m" get dispose ] unit-test "m" get dispose
] unit-test
] with-monitors ] with-monitors
] cleanup-unique-directory
] with-temp-directory
! Disposing a monitor should throw an error in any threads ! Disposing a monitor should throw an error in any threads
! waiting on notifications ! waiting on notifications
[
[ [
[ ] [ [
{ } [
<promise> "p" set <promise> "p" set
"monitor-test" temp-file t <monitor> "m" set "." t <monitor> "m" set
10 seconds "m" get set-timeout 10 seconds "m" get set-timeout
] unit-test ] unit-test
@ -113,8 +119,15 @@ os { windows linux macosx } member? [
"p" get fulfill "p" get fulfill
] in-thread ] in-thread
[ ] [ 100 milliseconds sleep ] unit-test { } [
[ ] [ "m" get dispose ] unit-test 100 milliseconds sleep
[ t ] [ "p" get 10 seconds ?promise-timeout already-disposed? ] unit-test "m" get dispose
] unit-test
{ t } [
"p" get 10 seconds ?promise-timeout
already-disposed?
] unit-test
] with-monitors ] with-monitors
] when ] cleanup-unique-directory
] with-temp-directory

View File

@ -1,30 +1,33 @@
USING: accessors alien.c-types alien.data destructors io USING: accessors alien.c-types alien.data destructors io
io.directories io.encodings.ascii io.encodings.binary io.encodings.ascii io.encodings.binary io.encodings.string
io.encodings.string io.encodings.utf8 io.files io.files.temp io.encodings.utf8 io.files io.files.temp io.files.unique
io.pipes io.sockets kernel libc math namespaces sequences io.pipes io.sockets kernel libc locals math namespaces sequences
tools.test ; tools.test ;
IN: io.ports.tests IN: io.ports.tests
! Make sure that writing malloced storage to a file works, and ! Make sure that writing malloced storage to a file works, and
! also make sure that writes larger than the buffer size work ! also make sure that writes larger than the buffer size work
{ } [ [
"test.txt" temp-file binary [ "test" ".txt" [| path |
{ } [
path binary [
[ [
100,000 iota 100,000 iota
0 0
100,000 int malloc-array &free [ copy ] keep write 100,000 int malloc-array &free [ copy ] keep write
] with-destructors ] with-destructors
] with-file-writer ] with-file-writer
] unit-test ] unit-test
{ t } [ { t } [
"test.txt" temp-file binary [ path binary [
100,000 4 * read int cast-array 100,000 iota sequence= 100,000 4 * read int cast-array 100,000 iota sequence=
] with-file-reader ] with-file-reader
] unit-test ] unit-test
] cleanup-unique-file
{ } [ "test.txt" temp-file delete-file ] unit-test ] with-temp-directory
! Getting the stream-element-type of an output-port was broken ! Getting the stream-element-type of an output-port was broken
{ +byte+ } [ binary <pipe> [ stream-element-type ] with-disposal ] unit-test { +byte+ } [ binary <pipe> [ stream-element-type ] with-disposal ] unit-test