]> gitweb.factorcode.org Git - factor.git/blob - basis/io/launcher/unix/unix-tests.factor
Merge branch 'master' into experimental
[factor.git] / basis / io / launcher / unix / unix-tests.factor
1 IN: io.launcher.unix.tests
2 USING: io.files io.files.temp io.directories io.pathnames
3 tools.test io.launcher arrays io namespaces continuations math
4 io.encodings.binary io.encodings.ascii accessors kernel
5 sequences io.encodings.utf8 destructors io.streams.duplex locals
6 concurrency.promises threads unix.process ;
7
8 [ ] [
9     [ "launcher-test-1" temp-file delete-file ] ignore-errors
10 ] unit-test
11
12 [ ] [
13     "touch"
14     "launcher-test-1" temp-file
15     2array
16     try-process
17 ] unit-test
18
19 [ t ] [ "launcher-test-1" temp-file exists? ] unit-test
20
21 [ ] [
22     [ "launcher-test-1" temp-file delete-file ] ignore-errors
23 ] unit-test
24
25 [ ] [
26     <process>
27         "echo Hello" >>command
28         "launcher-test-1" temp-file >>stdout
29     try-process
30 ] unit-test
31
32 [ "Hello\n" ] [
33     "cat"
34     "launcher-test-1" temp-file
35     2array
36     ascii <process-reader> contents
37 ] unit-test
38
39 [ ] [
40     [ "launcher-test-1" temp-file delete-file ] ignore-errors
41 ] unit-test
42
43 [ ] [
44     <process>
45         "cat" >>command
46         +closed+ >>stdin
47         "launcher-test-1" temp-file >>stdout
48     try-process
49 ] unit-test
50
51 [ f ] [
52     "cat"
53     "launcher-test-1" temp-file
54     2array
55     ascii <process-reader> contents
56 ] unit-test
57
58 [ ] [
59     2 [
60         "launcher-test-1" temp-file binary <file-appender> [
61             <process>
62                 swap >>stdout
63                 "echo Hello" >>command
64             try-process
65         ] with-disposal
66     ] times
67 ] unit-test
68
69 [ "Hello\nHello\n" ] [
70     "cat"
71     "launcher-test-1" temp-file
72     2array
73     ascii <process-reader> contents
74 ] unit-test
75
76 [ t ] [
77     <process>
78         "env" >>command
79         { { "A" "B" } } >>environment
80     ascii <process-reader> lines
81     "A=B" swap member?
82 ] unit-test
83
84 [ { "A=B" } ] [
85     <process>
86         "env" >>command
87         { { "A" "B" } } >>environment
88         +replace-environment+ >>environment-mode
89     ascii <process-reader> lines
90 ] unit-test
91
92 [ "hi\n" ] [
93     temp-directory [
94         [ "aloha" delete-file ] ignore-errors
95         <process>
96             { "echo" "hi" } >>command
97             "aloha" >>stdout
98         try-process
99     ] with-directory
100     temp-directory "aloha" append-path
101     utf8 file-contents
102 ] unit-test
103
104 [ "append-test" temp-file delete-file ] ignore-errors
105
106 [ "hi\nhi\n" ] [
107     2 [
108         <process>
109             "echo hi" >>command
110             "append-test" temp-file <appender> >>stdout
111         try-process
112     ] times
113     "append-test" temp-file utf8 file-contents
114 ] unit-test
115
116 [ t ] [ "ls" utf8 <process-stream> contents >boolean ] unit-test
117
118 [ "Hello world.\n" ] [
119     "cat" utf8 <process-stream> [
120         "Hello world.\n" write
121         output-stream get dispose
122         input-stream get contents
123     ] with-stream
124 ] unit-test
125
126 ! Killed processes were exiting with code 0 on FreeBSD
127 [ f ] [
128     [let | p [ <promise> ]
129            s [ <promise> ] |
130        [
131            "sleep 1000" run-detached
132            [ p fulfill ] [ wait-for-process s fulfill ] bi
133        ] in-thread
134
135        p ?promise handle>> 9 kill drop
136        s ?promise 0 =
137     ]
138 ] unit-test