io: fix some temp-file uses in tests.

locals-and-roots
John Benediktsson 2016-03-31 21:08:03 -07:00
parent 9a8f35c23b
commit 68b0f7d0f0
2 changed files with 166 additions and 192 deletions

View File

@ -1,141 +1,130 @@
USING: io.files io.files.temp io.directories io.sockets io kernel threads USING: byte-arrays destructors io io.directories
namespaces tools.test continuations strings byte-arrays io.encodings.ascii io.encodings.binary io.files io.files.temp
sequences prettyprint system io.encodings.binary io.encodings.ascii io.files.unique io.launcher io.sockets io.streams.duplex kernel
io.streams.duplex destructors make io.launcher ; make namespaces prettyprint sequences strings system threads
IN: io.backend.unix.tests tools.test ;
! Unix domain stream sockets
: socket-server ( -- path ) "unix-domain-socket-test" temp-file ;
[ [
[ socket-server delete-file ] ignore-errors
socket-server <local>
ascii <server> [
accept drop [
"Hello world" print flush
readln "XYZ" = "FOO" "BAR" ? print flush
] with-stream
] with-disposal
socket-server delete-file
] "Test" spawn drop
yield
{ { "Hello world" "FOO" } } [
[ [
socket-server <local> ascii [ [
readln , "socket-server" <local>
"XYZ" print flush ascii <server> [
readln , accept drop [
] with-client "Hello world" print flush
] { } make readln "XYZ" = "FOO" "BAR" ? print flush
] unit-test ] with-stream
] with-disposal
: datagram-server ( -- path ) "unix-domain-datagram-test" temp-file ; "socket-server" delete-file
: datagram-client ( -- path ) "unix-domain-datagram-test-2" temp-file ; ] "Test" spawn drop
! Unix domain datagram sockets yield
[ datagram-server delete-file ] ignore-errors
[ datagram-client delete-file ] ignore-errors
[ { { "Hello world" "FOO" } } [
datagram-server <local> <datagram> "d" [ [
"socket-server" <local> ascii [
readln ,
"XYZ" print flush
readln ,
] with-client
] { } make
] unit-test
"Receive 1" print ! Unix domain datagram sockets
[
"datagram-server" <local> <datagram> "d" [
"d" get receive [ reverse ] dip "Receive 1" print
"Send 1" print "d" get receive [ reverse ] dip
dup .
"d" get send "Send 1" print
dup .
"Receive 2" print "d" get send
"d" get receive [ " world" append ] dip "Receive 2" print
"Send 1" print "d" get receive [ " world" append ] dip
dup .
"d" get send "Send 1" print
dup .
"d" get dispose "d" get send
"Done" print "d" get dispose
datagram-server delete-file "Done" print
] with-variable
] "Test" spawn drop
yield "datagram-server" delete-file
] with-variable
] "Test" spawn drop
[ datagram-client delete-file ] ignore-errors yield
{ } [ datagram-client <local> <datagram> "d" set ] unit-test { } [ "datagram-client" <local> <datagram> "d" set ] unit-test
{ } [ { } [
"hello" >byte-array "hello" >byte-array
datagram-server <local> "datagram-server" <local>
"d" get send "d" get send
] unit-test ] unit-test
{ "olleh" t } [ { "olleh" t } [
"d" get receive "d" get receive
datagram-server <local> = "datagram-server" <local> =
[ >string ] dip [ >string ] dip
] unit-test ] unit-test
{ } [ { } [
"hello" >byte-array "hello" >byte-array
datagram-server <local> "datagram-server" <local>
"d" get send "d" get send
] unit-test ] unit-test
{ "hello world" t } [ { "hello world" t } [
"d" get receive "d" get receive
datagram-server <local> = "datagram-server" <local> =
[ >string ] dip [ >string ] dip
] unit-test ] unit-test
{ } [ "d" get dispose ] unit-test { } [ "d" get dispose ] unit-test
! Test error behavior ! Test error behavior
: another-datagram ( -- path ) "unix-domain-datagram-test-3" temp-file ;
[ another-datagram delete-file ] ignore-errors "datagram-client" delete-file
datagram-client delete-file { } [ "datagram-client" <local> <datagram> "d" set ] unit-test
{ } [ datagram-client <local> <datagram> "d" set ] unit-test [ B{ 1 2 3 } "another-datagram" <local> "d" get send ] must-fail
[ B{ 1 2 3 } another-datagram <local> "d" get send ] must-fail { } [ "d" get dispose ] unit-test
{ } [ "d" get dispose ] unit-test ! See what happens on send/receive after close
! See what happens on send/receive after close [ "d" get receive ] must-fail
[ "d" get receive ] must-fail [ B{ 1 2 } "datagram-server" <local> "d" get send ] must-fail
[ B{ 1 2 } datagram-server <local> "d" get send ] must-fail ! Invalid parameter tests
! Invalid parameter tests [
image-path binary [ input-stream get accept ] with-file-reader
] must-fail
[ [
image-path binary [ input-stream get accept ] with-file-reader image-path binary [ input-stream get receive ] with-file-reader
] must-fail ] must-fail
[ [
image-path binary [ input-stream get receive ] with-file-reader image-path binary [
] must-fail B{ 1 2 } "datagram-server" <local>
input-stream get send
] with-file-reader
] must-fail
[ ] cleanup-unique-directory
image-path binary [ ] with-temp-directory
B{ 1 2 } datagram-server <local>
input-stream get send
] with-file-reader
] must-fail
! closing stdin caused some problems ! closing stdin caused some problems
{ } [ { } [

View File

@ -1,82 +1,88 @@
USING: accessors arrays bootstrap.image calendar USING: accessors calendar concurrency.promises continuations
concurrency.promises continuations debugger.unix destructors io debugger.unix destructors io io.backend.unix io.directories
io.backend.unix io.directories io.encodings.ascii io.encodings.ascii io.encodings.binary io.encodings.utf8
io.encodings.binary io.encodings.utf8 io.files io.files.temp io.files io.files.temp io.files.unique io.launcher
io.launcher io.launcher.unix io.pathnames io.streams.duplex io.launcher.unix io.streams.duplex io.timeouts kernel libc
io.timeouts kernel libc locals math namespaces sequences locals math namespaces sequences threads tools.test unix.process
threads tools.test unix unix.process ; ;
IN: io.launcher.unix.tests IN: io.launcher.unix.tests
: arch-temp-file ( str -- str' )
"-" my-arch-name 3append temp-file ;
{ } [ [
[ "launcher-test-1" arch-temp-file delete-file ] ignore-errors [
] unit-test { } [ { "touch" "launcher-test-1" } try-process ] unit-test
{ } [ { t } [ "launcher-test-1" exists? ] unit-test
"touch"
"launcher-test-1" arch-temp-file
2array
try-process
] unit-test
{ t } [ "launcher-test-1" arch-temp-file exists? ] unit-test { } [
[ "launcher-test-1" delete-file ] ignore-errors
] unit-test
{ } [ { } [
[ "launcher-test-1" arch-temp-file delete-file ] ignore-errors
] unit-test
{ } [
<process>
"echo Hello" >>command
"launcher-test-1" arch-temp-file >>stdout
try-process
] unit-test
{ "Hello\n" } [
"cat"
"launcher-test-1" arch-temp-file
2array
ascii <process-reader> stream-contents
] unit-test
{ } [
[ "launcher-test-1" arch-temp-file delete-file ] ignore-errors
] unit-test
{ } [
<process>
"cat" >>command
+closed+ >>stdin
"launcher-test-1" arch-temp-file >>stdout
try-process
] unit-test
{ "" } [
"cat"
"launcher-test-1" arch-temp-file
2array
ascii <process-reader> stream-contents
] unit-test
{ } [
2 [
"launcher-test-1" arch-temp-file binary <file-appender> [
<process> <process>
swap >>stdout
"echo Hello" >>command "echo Hello" >>command
"launcher-test-1" >>stdout
try-process try-process
] with-disposal ] unit-test
] times
] unit-test
{ "Hello\nHello\n" } [ { "Hello\n" } [
"cat" { "cat" "launcher-test-1" }
"launcher-test-1" arch-temp-file ascii <process-reader> stream-contents
2array ] unit-test
ascii <process-reader> stream-contents
] unit-test { } [
[ "launcher-test-1" delete-file ] ignore-errors
] unit-test
{ } [
<process>
"cat" >>command
+closed+ >>stdin
"launcher-test-1" >>stdout
try-process
] unit-test
{ "" } [
{ "cat" "launcher-test-1" }
ascii <process-reader> stream-contents
] unit-test
{ } [
2 [
"launcher-test-1" binary <file-appender> [
<process>
swap >>stdout
"echo Hello" >>command
try-process
] with-disposal
] times
] unit-test
{ "Hello\nHello\n" } [
{ "cat" "launcher-test-1" }
ascii <process-reader> stream-contents
] unit-test
{ "hi\n" } [
<process>
{ "echo" "hi" } >>command
"launcher-test-2" >>stdout
try-process
"launcher-test-2" utf8 file-contents
] unit-test
{ "hi\nhi\n" } [
2 [
<process>
"echo hi" >>command
"launcher-test-3" <appender> >>stdout
try-process
] times
"launcher-test-3" utf8 file-contents
] unit-test
] cleanup-unique-directory
] with-temp-directory
{ t } [ { t } [
<process> <process>
@ -94,31 +100,10 @@ IN: io.launcher.unix.tests
ascii <process-reader> stream-lines ascii <process-reader> stream-lines
] unit-test ] unit-test
{ "hi\n" } [ { t } [
[ "ls" utf8 <process-stream> stream-contents >boolean
[ "aloha" delete-file ] ignore-errors
<process>
{ "echo" "hi" } >>command
"aloha" >>stdout
try-process
"aloha" utf8 file-contents
] with-temp-directory
] unit-test ] unit-test
[ "append-test" arch-temp-file delete-file ] ignore-errors
{ "hi\nhi\n" } [
2 [
<process>
"echo hi" >>command
"append-test" arch-temp-file <appender> >>stdout
try-process
] times
"append-test" arch-temp-file utf8 file-contents
] unit-test
{ t } [ "ls" utf8 <process-stream> stream-contents >boolean ] unit-test
{ "Hello world.\n" } [ { "Hello world.\n" } [
"cat" utf8 <process-stream> [ "cat" utf8 <process-stream> [
"Hello world.\n" write "Hello world.\n" write