2008-12-14 21:03:00 -05:00
|
|
|
IN: io.launcher.unix.tests
|
2008-12-14 22:21:44 -05:00
|
|
|
USING: io.files io.files.temp io.directories io.pathnames
|
|
|
|
tools.test io.launcher arrays io namespaces continuations math
|
|
|
|
io.encodings.binary io.encodings.ascii accessors kernel
|
|
|
|
sequences io.encodings.utf8 destructors io.streams.duplex locals
|
2010-09-03 01:11:45 -04:00
|
|
|
concurrency.promises threads unix.process calendar unix
|
|
|
|
unix.process debugger.unix io.timeouts io.launcher.unix ;
|
2008-03-04 16:07:57 -05:00
|
|
|
|
|
|
|
[ ] [
|
|
|
|
[ "launcher-test-1" temp-file delete-file ] ignore-errors
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ ] [
|
|
|
|
"touch"
|
|
|
|
"launcher-test-1" temp-file
|
|
|
|
2array
|
|
|
|
try-process
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ t ] [ "launcher-test-1" temp-file exists? ] unit-test
|
|
|
|
|
|
|
|
[ ] [
|
|
|
|
[ "launcher-test-1" temp-file delete-file ] ignore-errors
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ ] [
|
2008-03-06 21:44:52 -05:00
|
|
|
<process>
|
|
|
|
"echo Hello" >>command
|
|
|
|
"launcher-test-1" temp-file >>stdout
|
|
|
|
try-process
|
2008-03-04 16:07:57 -05:00
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ "Hello\n" ] [
|
|
|
|
"cat"
|
|
|
|
"launcher-test-1" temp-file
|
|
|
|
2array
|
2009-05-01 17:38:04 -04:00
|
|
|
ascii <process-reader> stream-contents
|
2008-03-04 16:07:57 -05:00
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ ] [
|
|
|
|
[ "launcher-test-1" temp-file delete-file ] ignore-errors
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ ] [
|
2008-03-06 21:44:52 -05:00
|
|
|
<process>
|
|
|
|
"cat" >>command
|
|
|
|
+closed+ >>stdin
|
|
|
|
"launcher-test-1" temp-file >>stdout
|
|
|
|
try-process
|
2008-03-04 16:07:57 -05:00
|
|
|
] unit-test
|
|
|
|
|
2009-05-10 17:39:51 -04:00
|
|
|
[ "" ] [
|
2008-03-04 16:07:57 -05:00
|
|
|
"cat"
|
|
|
|
"launcher-test-1" temp-file
|
|
|
|
2array
|
2009-05-01 17:38:04 -04:00
|
|
|
ascii <process-reader> stream-contents
|
2008-03-04 16:07:57 -05:00
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ ] [
|
|
|
|
2 [
|
2008-03-18 17:01:14 -04:00
|
|
|
"launcher-test-1" temp-file binary <file-appender> [
|
2008-03-06 21:44:52 -05:00
|
|
|
<process>
|
|
|
|
swap >>stdout
|
|
|
|
"echo Hello" >>command
|
|
|
|
try-process
|
2008-03-04 16:07:57 -05:00
|
|
|
] with-disposal
|
|
|
|
] times
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ "Hello\nHello\n" ] [
|
|
|
|
"cat"
|
|
|
|
"launcher-test-1" temp-file
|
|
|
|
2array
|
2009-05-01 17:38:04 -04:00
|
|
|
ascii <process-reader> stream-contents
|
2008-03-04 16:07:57 -05:00
|
|
|
] unit-test
|
2008-03-06 21:44:52 -05:00
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
<process>
|
|
|
|
"env" >>command
|
|
|
|
{ { "A" "B" } } >>environment
|
2009-05-01 17:38:04 -04:00
|
|
|
ascii <process-reader> stream-lines
|
2008-03-06 21:44:52 -05:00
|
|
|
"A=B" swap member?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ { "A=B" } ] [
|
|
|
|
<process>
|
|
|
|
"env" >>command
|
|
|
|
{ { "A" "B" } } >>environment
|
|
|
|
+replace-environment+ >>environment-mode
|
2009-05-01 17:38:04 -04:00
|
|
|
ascii <process-reader> stream-lines
|
2008-03-06 21:44:52 -05:00
|
|
|
] unit-test
|
2008-03-26 23:39:16 -04:00
|
|
|
|
|
|
|
[ "hi\n" ] [
|
|
|
|
temp-directory [
|
|
|
|
[ "aloha" delete-file ] ignore-errors
|
|
|
|
<process>
|
|
|
|
{ "echo" "hi" } >>command
|
|
|
|
"aloha" >>stdout
|
|
|
|
try-process
|
|
|
|
] with-directory
|
|
|
|
temp-directory "aloha" append-path
|
|
|
|
utf8 file-contents
|
|
|
|
] unit-test
|
2008-05-05 20:12:22 -04:00
|
|
|
|
2008-05-06 22:23:18 -04:00
|
|
|
[ "append-test" temp-file delete-file ] ignore-errors
|
2008-05-05 20:12:22 -04:00
|
|
|
|
|
|
|
[ "hi\nhi\n" ] [
|
|
|
|
2 [
|
|
|
|
<process>
|
|
|
|
"echo hi" >>command
|
|
|
|
"append-test" temp-file <appender> >>stdout
|
|
|
|
try-process
|
|
|
|
] times
|
|
|
|
"append-test" temp-file utf8 file-contents
|
|
|
|
] unit-test
|
2008-05-14 04:55:33 -04:00
|
|
|
|
2009-05-01 17:38:04 -04:00
|
|
|
[ t ] [ "ls" utf8 <process-stream> stream-contents >boolean ] unit-test
|
2008-07-24 22:47:09 -04:00
|
|
|
|
|
|
|
[ "Hello world.\n" ] [
|
|
|
|
"cat" utf8 <process-stream> [
|
|
|
|
"Hello world.\n" write
|
|
|
|
output-stream get dispose
|
2009-05-01 17:38:04 -04:00
|
|
|
input-stream get stream-contents
|
2008-07-24 22:47:09 -04:00
|
|
|
] with-stream
|
|
|
|
] unit-test
|
2008-12-10 18:30:07 -05:00
|
|
|
|
|
|
|
! Killed processes were exiting with code 0 on FreeBSD
|
|
|
|
[ f ] [
|
2009-10-27 22:50:31 -04:00
|
|
|
[let
|
|
|
|
<promise> :> p
|
|
|
|
<promise> :> s
|
2009-11-22 14:49:10 -05:00
|
|
|
|
2009-10-27 22:50:31 -04:00
|
|
|
[
|
|
|
|
"sleep 1000" run-detached
|
|
|
|
[ p fulfill ] [ wait-for-process s fulfill ] bi
|
|
|
|
] in-thread
|
|
|
|
|
2010-02-07 00:17:53 -05:00
|
|
|
p 1 seconds ?promise-timeout handle>> kill-process*
|
2010-05-02 20:06:45 -04:00
|
|
|
s 3 seconds ?promise-timeout 0 =
|
2008-12-10 18:30:07 -05:00
|
|
|
]
|
|
|
|
] unit-test
|
2010-09-03 01:11:45 -04:00
|
|
|
|
|
|
|
! Make sure that subprocesses don't inherit our signal mask
|
|
|
|
|
|
|
|
! First, ensure that the Factor VM ignores SIGPIPE
|
|
|
|
: send-sigpipe ( pid -- )
|
|
|
|
"SIGPIPE" signal-names index 1 +
|
|
|
|
kill io-error ;
|
|
|
|
|
|
|
|
[ ] [ current-process-handle send-sigpipe ] unit-test
|
|
|
|
|
|
|
|
! Spawn a process
|
|
|
|
[ T{ signal f 13 } ] [
|
|
|
|
"sleep 1000" run-detached
|
|
|
|
[ handle>> send-sigpipe ]
|
|
|
|
[ 2 seconds swap set-timeout ]
|
|
|
|
[ wait-for-process ]
|
|
|
|
tri
|
|
|
|
] unit-test
|