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,16 +1,13 @@
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> "socket-server" <local>
ascii <server> [ ascii <server> [
accept drop [ accept drop [
"Hello world" print flush "Hello world" print flush
@ -18,14 +15,14 @@ IN: io.backend.unix.tests
] with-stream ] with-stream
] with-disposal ] with-disposal
socket-server delete-file "socket-server" delete-file
] "Test" spawn drop ] "Test" spawn drop
yield yield
{ { "Hello world" "FOO" } } [ { { "Hello world" "FOO" } } [
[ [
socket-server <local> ascii [ "socket-server" <local> ascii [
readln , readln ,
"XYZ" print flush "XYZ" print flush
readln , readln ,
@ -33,15 +30,9 @@ yield
] { } make ] { } make
] unit-test ] unit-test
: datagram-server ( -- path ) "unix-domain-datagram-test" temp-file ;
: datagram-client ( -- path ) "unix-domain-datagram-test-2" temp-file ;
! Unix domain datagram sockets ! Unix domain datagram sockets
[ datagram-server delete-file ] ignore-errors
[ datagram-client delete-file ] ignore-errors
[ [
datagram-server <local> <datagram> "d" [ "datagram-server" <local> <datagram> "d" [
"Receive 1" print "Receive 1" print
@ -65,52 +56,47 @@ yield
"Done" print "Done" print
datagram-server delete-file "datagram-server" delete-file
] with-variable ] with-variable
] "Test" spawn drop ] "Test" spawn drop
yield yield
[ datagram-client delete-file ] ignore-errors { } [ "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
@ -118,7 +104,7 @@ datagram-client delete-file
[ "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
@ -132,11 +118,14 @@ datagram-client delete-file
[ [
image-path binary [ image-path binary [
B{ 1 2 } datagram-server <local> B{ 1 2 } "datagram-server" <local>
input-stream get send input-stream get send
] with-file-reader ] with-file-reader
] must-fail ] must-fail
] cleanup-unique-directory
] with-temp-directory
! closing stdin caused some problems ! closing stdin caused some problems
{ } [ { } [
[ [

View File

@ -1,68 +1,55 @@
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 ; [
[
{ } [ { "touch" "launcher-test-1" } try-process ] unit-test
{ t } [ "launcher-test-1" exists? ] unit-test
{ } [ { } [
[ "launcher-test-1" arch-temp-file delete-file ] ignore-errors [ "launcher-test-1" delete-file ] ignore-errors
] 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" arch-temp-file delete-file ] ignore-errors
] unit-test ] unit-test
{ } [ { } [
<process> <process>
"echo Hello" >>command "echo Hello" >>command
"launcher-test-1" arch-temp-file >>stdout "launcher-test-1" >>stdout
try-process try-process
] unit-test ] unit-test
{ "Hello\n" } [ { "Hello\n" } [
"cat" { "cat" "launcher-test-1" }
"launcher-test-1" arch-temp-file
2array
ascii <process-reader> stream-contents ascii <process-reader> stream-contents
] unit-test ] unit-test
{ } [ { } [
[ "launcher-test-1" arch-temp-file delete-file ] ignore-errors [ "launcher-test-1" delete-file ] ignore-errors
] unit-test ] unit-test
{ } [ { } [
<process> <process>
"cat" >>command "cat" >>command
+closed+ >>stdin +closed+ >>stdin
"launcher-test-1" arch-temp-file >>stdout "launcher-test-1" >>stdout
try-process try-process
] unit-test ] unit-test
{ "" } [ { "" } [
"cat" { "cat" "launcher-test-1" }
"launcher-test-1" arch-temp-file
2array
ascii <process-reader> stream-contents ascii <process-reader> stream-contents
] unit-test ] unit-test
{ } [ { } [
2 [ 2 [
"launcher-test-1" arch-temp-file binary <file-appender> [ "launcher-test-1" binary <file-appender> [
<process> <process>
swap >>stdout swap >>stdout
"echo Hello" >>command "echo Hello" >>command
@ -72,12 +59,31 @@ IN: io.launcher.unix.tests
] unit-test ] unit-test
{ "Hello\nHello\n" } [ { "Hello\nHello\n" } [
"cat" { "cat" "launcher-test-1" }
"launcher-test-1" arch-temp-file
2array
ascii <process-reader> stream-contents ascii <process-reader> stream-contents
] unit-test ] 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>
"env" >>command "env" >>command
@ -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