1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
return require('lib/tap')(function (test)
test("test disable_stdio_inheritance", function (print, p, expect, uv)
uv.disable_stdio_inheritance()
end)
test("process stdout", function (print, p, expect, uv)
local stdout = uv.new_pipe(false)
local handle, pid
handle, pid = uv.spawn(uv.exepath(), {
args = {"-e", "print 'Hello World'"},
stdio = {nil, stdout},
}, expect(function (code, signal)
p("exit", {code=code, signal=signal})
uv.close(handle)
end))
p{
handle=handle,
pid=pid
}
uv.read_start(stdout, expect(function (err, chunk)
p("stdout", {err=err,chunk=chunk})
assert(not err, err)
uv.close(stdout)
end))
end)
if _G.isWindows then return end
test("spawn and kill by pid", function (print, p, expect, uv)
local handle, pid
handle, pid = uv.spawn("sleep", {
args = {1},
}, expect(function (status, signal)
p("exit", handle, {status=status,signal=signal})
assert(status == 0)
assert(signal == 2)
uv.close(handle)
end))
p{handle=handle,pid=pid}
uv.kill(pid, "sigint")
end)
test("spawn and kill by handle", function (print, p, expect, uv)
local handle, pid
handle, pid = uv.spawn("sleep", {
args = {1},
}, expect(function (status, signal)
p("exit", handle, {status=status,signal=signal})
assert(status == 0)
assert(signal == 15)
uv.close(handle)
end))
p{handle=handle,pid=pid}
uv.process_kill(handle, "sigterm")
end)
test("invalid command", function (print, p, expect, uv)
local handle, err
handle, err = uv.spawn("ksjdfksjdflkjsflksdf", {}, function(exit, code)
assert(false)
end)
assert(handle == nil)
assert(err)
end)
test("process stdio", function (print, p, expect, uv)
local stdin = uv.new_pipe(false)
local stdout = uv.new_pipe(false)
local handle, pid
handle, pid = uv.spawn("cat", {
stdio = {stdin, stdout},
}, expect(function (code, signal)
p("exit", {code=code, signal=signal})
uv.close(handle)
end))
p{
handle=handle,
pid=pid
}
uv.read_start(stdout, expect(function (err, chunk)
p("stdout", {err=err,chunk=chunk})
assert(not err, err)
uv.close(stdout)
end))
uv.write(stdin, "Hello World")
uv.shutdown(stdin, expect(function ()
uv.close(stdin)
end))
end)
end)
|