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
namespaces tools.test continuations strings byte-arrays
sequences prettyprint system io.encodings.binary io.encodings.ascii
io.streams.duplex destructors make io.launcher ;
IN: io.backend.unix.tests
! Unix domain stream sockets
: socket-server ( -- path ) "unix-domain-socket-test" temp-file ;
USING: byte-arrays destructors io io.directories
io.encodings.ascii io.encodings.binary io.files io.files.temp
io.files.unique io.launcher io.sockets io.streams.duplex kernel
make namespaces prettyprint sequences strings system threads
tools.test ;
[
[ socket-server delete-file ] ignore-errors
socket-server <local>
[
[
"socket-server" <local>
ascii <server> [
accept drop [
"Hello world" print flush
@ -18,14 +15,14 @@ IN: io.backend.unix.tests
] with-stream
] with-disposal
socket-server delete-file
"socket-server" delete-file
] "Test" spawn drop
yield
{ { "Hello world" "FOO" } } [
[
socket-server <local> ascii [
"socket-server" <local> ascii [
readln ,
"XYZ" print flush
readln ,
@ -33,15 +30,9 @@ yield
] { } make
] 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
[ 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
@ -65,52 +56,47 @@ yield
"Done" print
datagram-server delete-file
"datagram-server" delete-file
] with-variable
] "Test" spawn drop
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
datagram-server <local>
"datagram-server" <local>
"d" get send
] unit-test
{ "olleh" t } [
"d" get receive
datagram-server <local> =
"datagram-server" <local> =
[ >string ] dip
] unit-test
{ } [
"hello" >byte-array
datagram-server <local>
"datagram-server" <local>
"d" get send
] unit-test
{ "hello world" t } [
"d" get receive
datagram-server <local> =
"datagram-server" <local> =
[ >string ] dip
] unit-test
{ } [ "d" get dispose ] unit-test
! 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
@ -118,7 +104,7 @@ datagram-client delete-file
[ "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
@ -132,11 +118,14 @@ datagram-client delete-file
[
image-path binary [
B{ 1 2 } datagram-server <local>
B{ 1 2 } "datagram-server" <local>
input-stream get send
] with-file-reader
] must-fail
] cleanup-unique-directory
] with-temp-directory
! closing stdin caused some problems
{ } [
[

View File

@ -1,68 +1,55 @@
USING: accessors arrays bootstrap.image calendar
concurrency.promises continuations debugger.unix destructors io
io.backend.unix io.directories io.encodings.ascii
io.encodings.binary io.encodings.utf8 io.files io.files.temp
io.launcher io.launcher.unix io.pathnames io.streams.duplex
io.timeouts kernel libc locals math namespaces sequences
threads tools.test unix unix.process ;
USING: accessors calendar concurrency.promises continuations
debugger.unix destructors io io.backend.unix io.directories
io.encodings.ascii io.encodings.binary io.encodings.utf8
io.files io.files.temp io.files.unique io.launcher
io.launcher.unix io.streams.duplex io.timeouts kernel libc
locals math namespaces sequences threads tools.test unix.process
;
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
] 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
[ "launcher-test-1" delete-file ] ignore-errors
] unit-test
{ } [
<process>
"echo Hello" >>command
"launcher-test-1" arch-temp-file >>stdout
"launcher-test-1" >>stdout
try-process
] unit-test
{ "Hello\n" } [
"cat"
"launcher-test-1" arch-temp-file
2array
{ "cat" "launcher-test-1" }
ascii <process-reader> stream-contents
] unit-test
{ } [
[ "launcher-test-1" arch-temp-file delete-file ] ignore-errors
[ "launcher-test-1" delete-file ] ignore-errors
] unit-test
{ } [
<process>
"cat" >>command
+closed+ >>stdin
"launcher-test-1" arch-temp-file >>stdout
"launcher-test-1" >>stdout
try-process
] unit-test
{ "" } [
"cat"
"launcher-test-1" arch-temp-file
2array
{ "cat" "launcher-test-1" }
ascii <process-reader> stream-contents
] unit-test
{ } [
2 [
"launcher-test-1" arch-temp-file binary <file-appender> [
"launcher-test-1" binary <file-appender> [
<process>
swap >>stdout
"echo Hello" >>command
@ -72,12 +59,31 @@ IN: io.launcher.unix.tests
] unit-test
{ "Hello\nHello\n" } [
"cat"
"launcher-test-1" arch-temp-file
2array
{ "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 } [
<process>
"env" >>command
@ -94,31 +100,10 @@ IN: io.launcher.unix.tests
ascii <process-reader> stream-lines
] unit-test
{ "hi\n" } [
[
[ "aloha" delete-file ] ignore-errors
<process>
{ "echo" "hi" } >>command
"aloha" >>stdout
try-process
"aloha" utf8 file-contents
] with-temp-directory
{ t } [
"ls" utf8 <process-stream> stream-contents >boolean
] 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" } [
"cat" utf8 <process-stream> [
"Hello world.\n" write