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

View File

@ -1,37 +1,41 @@
IN: io.monitors.linux.tests
USING: io.monitors tools.test io.files io.files.temp
io.directories system sequences continuations namespaces
concurrency.count-downs kernel io threads calendar prettyprint
destructors io.timeouts accessors ;
io.files.unique io.directories io.pathnames system sequences
continuations namespaces concurrency.count-downs kernel io
threads calendar prettyprint destructors io.timeouts accessors ;
! On Linux, a notification on the directory itself would report an invalid
! path name
[
[ ] [ "monitor-test-self" temp-file make-directories ] unit-test
[
[
! Non-recursive
{ } [
"." f <monitor> "m" set
3 seconds "m" get set-timeout
"." touch-file
] unit-test
! Non-recursive
[ ] [ "monitor-test-self" temp-file f <monitor> "m" set ] unit-test
[ ] [ 3 seconds "m" get set-timeout ] unit-test
{ t } [
"m" get next-change path>>
[ "" = ] [ "." absolute-path = ] bi or
] unit-test
[ ] [ "monitor-test-self" temp-file touch-file ] unit-test
{ } [ "m" get dispose ] unit-test
[ t ] [
"m" get next-change path>>
[ "" = ] [ "monitor-test-self" temp-file = ] bi or
] unit-test
! Recursive
{ } [
"." t <monitor> "m" set
3 seconds "m" get set-timeout
"." touch-file
] unit-test
[ ] [ "m" get dispose ] unit-test
{ t } [
"m" get next-change path>>
[ "" = ] [ "." absolute-path = ] bi or
] unit-test
! Recursive
[ ] [ "monitor-test-self" temp-file t <monitor> "m" set ] unit-test
[ ] [ 3 seconds "m" get set-timeout ] unit-test
[ ] [ "monitor-test-self" temp-file touch-file ] unit-test
[ t ] [
"m" get next-change path>>
[ "" = ] [ "monitor-test-self" temp-file = ] bi or
] unit-test
[ ] [ "m" get dispose ] unit-test
] with-monitors
{ } [ "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
concurrency.promises continuations destructors io io.directories
io.directories.hierarchy io.files io.files.temp io.monitors
io.pathnames io.timeouts kernel namespaces sequences system
threads tools.test ;
io.files io.files.temp io.files.unique io.monitors io.pathnames
io.timeouts kernel namespaces sequences threads tools.test ;
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
[ 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
{ } [ "m" get dispose ] unit-test
] 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
[ ] [ "monitor-test" temp-file t <monitor> "m" set ] unit-test
[
{ } [ "xyz" make-directory ] 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
@ -64,57 +61,73 @@ os { windows linux macosx } member? [
"c2" get count-down
] "Monitor test thread" spawn drop
] unit-test
[ ] [ "b" get await ] unit-test
[ ] [ "monitor-test/xyz/test.txt" temp-file touch-file ] unit-test
[ ] [ "c1" get 1 minutes await-timeout ] unit-test
[ ] [ "monitor-test/subdir/blah/yxy" temp-file make-directories ] unit-test
[ ] [ "monitor-test/subdir/blah/yxy/test.txt" temp-file touch-file ] unit-test
[ ] [ "c2" get 1 minutes await-timeout ] unit-test
{ } [ "b" get await ] unit-test
{ } [ "xyz/test.txt" touch-file ] unit-test
{ } [ "c1" get 1 minutes await-timeout ] unit-test
{ } [ "subdir/blah/yxy" make-directories ] unit-test
{ } [ "subdir/blah/yxy/test.txt" touch-file ] unit-test
{ } [ "c2" get 1 minutes await-timeout ] unit-test
! Dispose twice
[ ] [ "m" get dispose ] unit-test
[ ] [ "m" get dispose ] unit-test
] with-monitors
! Dispose twice
{ } [ "m" get dispose ] unit-test
{ } [ "m" get dispose ] unit-test
] with-monitors
] cleanup-unique-directory
] with-temp-directory
! Out-of-scope disposal should not fail
[ ] [ [ "" resource-path f <monitor> ] with-monitors dispose ] unit-test
[ ] [ [ "" resource-path t <monitor> ] with-monitors dispose ] unit-test
! Out-of-scope disposal should not fail
{ } [ [ "resource:" f <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
[ ] [ "monitor-timeout-test" temp-file f <monitor> "m" set ] unit-test
[ ] [ 100 milliseconds "m" get set-timeout ] unit-test
[ [ t ] [ "m" get next-change drop ] while ] must-fail
[ ] [ "m" get dispose ] unit-test
! Recursive
[ ] [ "monitor-timeout-test" temp-file t <monitor> "m" set ] unit-test
[ ] [ 100 milliseconds "m" get set-timeout ] unit-test
[ [ t ] [ "m" get next-change drop ] while ] must-fail
[ ] [ "m" get dispose ] unit-test
] with-monitors
! Disposing a monitor should throw an error in any threads
! waiting on notifications
[
[ ] [
<promise> "p" set
"monitor-test" temp-file t <monitor> "m" set
10 seconds "m" get set-timeout
] unit-test
[
[ "m" get next-change ] [ ] recover
"p" get fulfill
] in-thread
! Non-recursive
{ } [
"." f <monitor> "m" set
100 milliseconds "m" get set-timeout
[ [ t ] [ "m" get next-change drop ] while ] must-fail
"m" get dispose
] unit-test
[ ] [ 100 milliseconds sleep ] unit-test
[ ] [ "m" get dispose ] unit-test
[ t ] [ "p" get 10 seconds ?promise-timeout already-disposed? ] unit-test
] with-monitors
] when
! Recursive
{ } [
"." t <monitor> "m" set
100 milliseconds "m" get set-timeout
[ [ t ] [ "m" get next-change drop ] while ] must-fail
"m" get dispose
] unit-test
] with-monitors
] cleanup-unique-directory
] with-temp-directory
! Disposing a monitor should throw an error in any threads
! waiting on notifications
[
[
[
{ } [
<promise> "p" set
"." t <monitor> "m" set
10 seconds "m" get set-timeout
] unit-test
[
[ "m" get next-change ] [ ] recover
"p" get fulfill
] in-thread
{ } [
100 milliseconds sleep
"m" get dispose
] unit-test
{ t } [
"p" get 10 seconds ?promise-timeout
already-disposed?
] unit-test
] with-monitors
] cleanup-unique-directory
] with-temp-directory

View File

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