forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspawn.jl
616 lines (553 loc) · 20.5 KB
/
spawn.jl
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
# This file is a part of Julia. License is MIT: https://julialang.org/license
###################################
# Cross Platform tests for spawn. #
###################################
using Random, Sockets
valgrind_off = ccall(:jl_running_on_valgrind, Cint, ()) == 0
yescmd = `yes`
echocmd = `echo`
sortcmd = `sort`
printfcmd = `printf`
truecmd = `true`
falsecmd = `false`
catcmd = `cat`
shcmd = `sh`
sleepcmd = `sleep`
lscmd = `ls`
havebb = false
if Sys.iswindows()
busybox = joinpath(Sys.BINDIR, "busybox.exe")
havebb = try # use busybox-w32 on windows, if available
success(`$busybox`)
true
catch
false
end
if havebb
yescmd = `$busybox yes`
echocmd = `$busybox echo`
sortcmd = `$busybox sort`
printfcmd = `$busybox printf`
truecmd = `$busybox true`
falsecmd = `$busybox false`
catcmd = `$busybox cat`
shcmd = `$busybox sh`
sleepcmd = `$busybox sleep`
lscmd = `$busybox ls`
end
end
#### Examples used in the manual ####
@test read(`$echocmd hello \| sort`, String) == "hello | sort\n"
@test read(pipeline(`$echocmd hello`, sortcmd), String) == "hello\n"
@test length(run(pipeline(`$echocmd hello`, sortcmd), wait=false).processes) == 2
out = read(`$echocmd hello` & `$echocmd world`, String)
@test occursin("world", out)
@test occursin("hello", out)
@test read(pipeline(`$echocmd hello` & `$echocmd world`, sortcmd), String) == "hello\nworld\n"
@test (run(`$printfcmd " \033[34m[stdio passthrough ok]\033[0m\n"`); true)
# Test for SIGPIPE being treated as normal termination (throws an error if broken)
Sys.isunix() && run(pipeline(yescmd, `head`, devnull))
let a, p
a = Base.Condition()
t = @async begin
p = run(pipeline(yescmd,devnull), wait=false)
Base.notify(a,p)
@test !success(p)
end
p = wait(a)
kill(p)
wait(t)
end
if valgrind_off
# If --trace-children=yes is passed to valgrind, valgrind will
# exit here with an error code, and no IOError will be raised.
@test_throws Base.IOError run(`foo_is_not_a_valid_command`)
end
if Sys.isunix()
prefixer(prefix, sleep) = `sh -c "while IFS= read REPLY; do echo '$prefix ' \$REPLY; sleep $sleep; done"`
@test success(pipeline(`sh -c "for i in 1 2 3 4 5 6 7 8 9 10; do echo \$i; sleep 0.1; done"`,
prefixer("A", 0.2) & prefixer("B", 0.2)))
@test success(pipeline(`sh -c "for i in 1 2 3 4 5 6 7 8 9 10; do echo \$i; sleep 0.1; done"`,
prefixer("X", 0.3) & prefixer("Y", 0.3) & prefixer("Z", 0.3),
prefixer("A", 0.2) & prefixer("B", 0.2)))
end
@test success(truecmd)
@test !success(falsecmd)
@test success(pipeline(truecmd, truecmd))
@test_broken success(ignorestatus(falsecmd))
@test_broken success(pipeline(ignorestatus(falsecmd), truecmd))
@test !success(pipeline(ignorestatus(falsecmd), falsecmd))
@test !success(ignorestatus(falsecmd) & falsecmd)
@test_broken success(ignorestatus(pipeline(falsecmd, falsecmd)))
@test_broken success(ignorestatus(falsecmd & falsecmd))
# stdin Redirection
let file = tempname()
run(pipeline(`$echocmd hello world`, file))
@test read(pipeline(file, catcmd), String) == "hello world\n"
@test open(x->read(x,String), pipeline(file, catcmd), "r") == "hello world\n"
rm(file)
end
# Stream Redirection
if !Sys.iswindows() # WINNT reports operation not supported on socket (ENOTSUP) for this test
local r = Channel(1)
local port, server, sock, client, t1, t2
t1 = @async begin
port, server = listenany(2326)
put!(r, port)
client = accept(server)
@test read(pipeline(client, catcmd), String) == "hello world\n"
close(server)
return true
end
t2 = @async begin
sock = connect(fetch(r))
run(pipeline(`$echocmd hello world`, sock))
close(sock)
return true
end
@test fetch(t1)
@test fetch(t2)
end
@test read(setenv(`$shcmd -c "echo \$TEST"`,["TEST=Hello World"]), String) == "Hello World\n"
@test read(setenv(`$shcmd -c "echo \$TEST"`,Dict("TEST"=>"Hello World")), String) == "Hello World\n"
@test read(setenv(`$shcmd -c "echo \$TEST"`,"TEST"=>"Hello World"), String) == "Hello World\n"
@test (withenv("TEST"=>"Hello World") do
read(`$shcmd -c "echo \$TEST"`, String); end) == "Hello World\n"
let pathA = readchomp(setenv(`$shcmd -c "pwd -P"`;dir="..")),
pathB = readchomp(setenv(`$shcmd -c "cd .. && pwd -P"`))
if Sys.iswindows()
# on windows, sh returns posix-style paths that are not valid according to ispath
@test pathA == pathB
else
@test Base.samefile(pathA, pathB)
end
end
let str = "", proc, str2, file
for i = 1:1000
str = "$str\n $(randstring(10))"
end
# Here we test that if we close a stream with pending writes, we don't lose the writes.
@sync begin
proc = open(`$catcmd -`, "r+")
@async begin
write(proc, str) # TODO: use Base.uv_write_async to restore the intended functionality of this test
close(proc.in)
end
str2 = read(proc, String)
@test str2 == str
end
# This test hangs if the end-of-run-walk-across-uv-streams calls shutdown on a stream that is shutting down.
file = tempname()
open(pipeline(`$catcmd -`, file), "w") do io
write(io, str)
end
rm(file)
end
# issue #3373
# fixing up Conditions after interruptions
let r, t
r = Channel(1)
t = @async begin
try
wait(r)
catch
end
p = run(`$sleepcmd 1`, wait=false); wait(p)
@test p.exitcode == 0
return true
end
yield()
schedule(t, InterruptException(), error=true)
yield()
put!(r,11)
yield()
@test fetch(t)
end
# Test marking of IO
let r, t, sock
r = Channel(1)
t = @async begin
port, server = listenany(2327)
put!(r, port)
client = accept(server)
write(client, "Hello, world!\n")
write(client, "Goodbye, world...\n")
close(server)
return true
end
sock = connect(fetch(r))
mark(sock)
@test ismarked(sock)
@test readline(sock) == "Hello, world!"
@test readline(sock) == "Goodbye, world..."
@test reset(sock) == 0
@test !ismarked(sock)
mark(sock)
@test ismarked(sock)
@test readline(sock) == "Hello, world!"
unmark(sock)
@test !ismarked(sock)
@test_throws ArgumentError reset(sock)
@test !unmark(sock)
@test readline(sock) == "Goodbye, world..."
#@test eof(sock) ## doesn't work
close(sock)
@test fetch(t)
end
# issue #4535
exename = Base.julia_cmd()
if valgrind_off
# If --trace-children=yes is passed to valgrind, we will get a
# valgrind banner here, not "Hello World\n".
@test read(pipeline(`$exename --startup-file=no -e 'println(stderr,"Hello World")'`, stderr=catcmd), String) == "Hello World\n"
out = Pipe()
proc = run(pipeline(`$exename --startup-file=no -e 'println(stderr,"Hello World")'`, stderr = out), wait=false)
close(out.in)
@test read(out, String) == "Hello World\n"
@test success(proc)
end
# setup_stdio for AbstractPipe
let out = Pipe(), proc = run(pipeline(`$echocmd "Hello World"`, stdout=IOContext(out,stdout)), wait=false)
close(out.in)
@test read(out, String) == "Hello World\n"
@test success(proc)
end
# issue #5904
@test run(pipeline(ignorestatus(falsecmd), truecmd)) isa Base.AbstractPipe
@testset "redirect_*" begin
let OLD_STDOUT = stdout,
fname = tempname(),
f = open(fname,"w")
redirect_stdout(f)
println("Hello World")
redirect_stdout(OLD_STDOUT)
close(f)
@test "Hello World\n" == read(fname, String)
@test OLD_STDOUT === stdout
rm(fname)
end
end
# Test that redirecting an IOStream does not crash the process
let fname = tempname(), p
cmd = """
# Overwrite libuv memory before freeing it, to make sure that a use after free
# triggers an assertion.
function thrash(handle::Ptr{Cvoid})
# Kill the memory, but write a nice low value in the libuv type field to
# trigger the right code path
ccall(:memset, Ptr{Cvoid}, (Ptr{Cvoid}, Cint, Csize_t), handle, 0xee, 3 * sizeof(Ptr{Cvoid}))
unsafe_store!(convert(Ptr{Cint}, handle + 2 * sizeof(Ptr{Cvoid})), 15)
nothing
end
OLD_STDERR = stderr
redirect_stderr(open($(repr(fname)), "w"))
# Usually this would be done by GC. Do it manually, to make the failure
# case more reliable.
oldhandle = OLD_STDERR.handle
OLD_STDERR.status = Base.StatusClosing
OLD_STDERR.handle = C_NULL
ccall(:uv_close, Cvoid, (Ptr{Cvoid}, Ptr{Cvoid}), oldhandle, @cfunction(thrash, Cvoid, (Ptr{Cvoid},)))
sleep(1)
import Base.zzzInvalidIdentifier
"""
try
io = open(pipeline(`$exename --startup-file=no`, stderr=stderr), "w")
write(io, cmd)
close(io)
wait(io)
catch
error("IOStream redirect failed. Child stderr was \n$(read(fname, String))\n")
finally
rm(fname)
end
end
# issue #10994: libuv can't handle strings containing NUL
let bad = "bad\0name"
@test_throws ArgumentError run(`$bad`)
@test_throws ArgumentError run(`$echocmd $bad`)
@test_throws ArgumentError run(setenv(`$echocmd hello`, bad=>"good"))
@test_throws ArgumentError run(setenv(`$echocmd hello`, "good"=>bad))
end
# issue #12829
let out = Pipe(), echo = `$exename --startup-file=no -e 'print(stdout, " 1\t", read(stdin, String))'`, ready = Condition(), t, infd, outfd
@test_throws ArgumentError write(out, "not open error")
t = @async begin # spawn writer task
open(echo, "w", out) do in1
open(echo, "w", out) do in2
notify(ready)
write(in1, 'h')
write(in2, UInt8['w'])
println(in1, "ello")
write(in2, "orld\n")
end
end
infd = Base._fd(out.in)
outfd = Base._fd(out.out)
show(out, out)
notify(ready)
@test isreadable(out)
@test iswritable(out)
close(out.in)
@test !isopen(out.in)
@test !iswritable(out)
if !Sys.iswindows()
# on UNIX, we expect the pipe buffer is big enough that the write queue was immediately emptied
# and so we should already be notified of EPIPE on out.out by now
# and the other task should have already managed to consume all of the output
# it takes longer to propagate EOF through the Windows event system
# since it appears to be unwilling to buffer as much data
@test !isopen(out.out)
@test !isreadable(out)
end
@test_throws ArgumentError write(out, "now closed error")
if Sys.iswindows()
# WINNT kernel appears to not provide a fast mechanism for async propagation
# of EOF for a blocking stream, so just wait for it to catch up.
# This shouldn't take much more than 32ms.
Base.wait_close(out)
# it's closed now, but the other task is expected to be behind this task
# in emptying the read buffer
@test isreadable(out)
end
@test !isopen(out)
end
wait(ready) # wait for writer task to be ready before using `out`
@test bytesavailable(out) == 0
@test endswith(readuntil(out, '1', keep=true), '1')
@test Char(read(out, UInt8)) == '\t'
c = UInt8[0]
@test c == read!(out, c)
Base.wait_readnb(out, 1)
@test bytesavailable(out) > 0
ln1 = readline(out)
ln2 = readline(out)
desc = read(out, String)
@test !isreadable(out)
@test !iswritable(out)
@test !isopen(out)
@test infd != Base._fd(out.in) == Base.INVALID_OS_HANDLE
@test outfd != Base._fd(out.out) == Base.INVALID_OS_HANDLE
@test bytesavailable(out) == 0
@test c == UInt8['w']
@test lstrip(ln2) == "1\thello"
@test ln1 == "orld"
@test isempty(read(out))
@test eof(out)
@test desc == "Pipe($infd open => $outfd active, 0 bytes waiting)"
Base.wait(t)
end
# issue #8529
let fname = tempname()
write(fname, "test\n")
code = """
$(if havebb
"cmd = pipeline(`\$$(repr(busybox)) echo asdf`, `\$$(repr(busybox)) cat`)"
else
"cmd = pipeline(`echo asdf`, `cat`)"
end)
for line in eachline(stdin)
run(cmd)
end
"""
@test success(pipeline(`$catcmd $fname`, `$exename --startup-file=no -e $code`))
rm(fname)
end
# Ensure that quoting works
@test Base.shell_split("foo bar baz") == ["foo", "bar", "baz"]
@test Base.shell_split("foo\\ bar baz") == ["foo bar", "baz"]
@test Base.shell_split("'foo bar' baz") == ["foo bar", "baz"]
@test Base.shell_split("\"foo bar\" baz") == ["foo bar", "baz"]
# "Over quoted"
@test Base.shell_split("'foo\\ bar' baz") == ["foo\\ bar", "baz"]
@test Base.shell_split("\"foo\\ bar\" baz") == ["foo\\ bar", "baz"]
# Ensure that shell_split handles quoted spaces
let cmd = ["/Volumes/External HD/program", "-a"]
@test Base.shell_split("/Volumes/External\\ HD/program -a") == cmd
@test Base.shell_split("'/Volumes/External HD/program' -a") == cmd
@test Base.shell_split("\"/Volumes/External HD/program\" -a") == cmd
end
# Test shell_escape printing quoting
# Backticks should automatically quote where necessary
let cmd = ["foo bar", "baz", "a'b", "a\"b", "a\"b\"c", "-L/usr/+", "a=b", "``", "\$", "&&", "z"]
@test string(`$cmd`) ==
"""`'foo bar' baz "a'b" 'a"b' 'a"b"c' -L/usr/+ a=b \\`\\` '\$' '&&' z`"""
@test Base.shell_escape(`$cmd`) ==
"""'foo bar' baz "a'b" 'a"b' 'a"b"c' -L/usr/+ a=b `` '\$' && z"""
@test Base.shell_escape_posixly(`$cmd`) ==
"""'foo bar' baz a\\'b a\\"b 'a"b"c' -L/usr/+ a=b '``' '\$' '&&' z"""
end
let cmd = ["foo=bar", "baz"]
@test string(`$cmd`) == "`foo=bar baz`"
@test Base.shell_escape(`$cmd`) == "foo=bar baz"
@test Base.shell_escape_posixly(`$cmd`) == "'foo=bar' baz"
end
@test Base.shell_split("\"\\\\\"") == ["\\"]
# issue #13616
pcatcmd = `$catcmd _doesnt_exist__111_`
let p = eachline(pipeline(`$catcmd _doesnt_exist__111_`, stderr=devnull))
@test_throws(ErrorException("failed process: Process($pcatcmd, ProcessExited(1)) [1]"),
collect(p))
end
# make sure windows_verbatim strips quotes
if Sys.iswindows()
@test read(`cmd.exe /c dir /b spawn.jl`, String) == read(Cmd(`cmd.exe /c dir /b "\"spawn.jl\""`, windows_verbatim=true), String)
end
# make sure Cmd is nestable
@test string(Cmd(Cmd(`ls`, detach=true))) == "`ls`"
# equality tests for Cmd
@test Base.Cmd(``) == Base.Cmd(``)
@test Base.Cmd(`lsof -i :9090`) == Base.Cmd(`lsof -i :9090`)
@test Base.Cmd(`$echocmd test`) == Base.Cmd(`$echocmd test`)
@test Base.Cmd(``) != Base.Cmd(`$echocmd test`)
@test Base.Cmd(``, ignorestatus=true) != Base.Cmd(``, ignorestatus=false)
@test Base.Cmd(``, dir="TESTS") != Base.Cmd(``, dir="TEST")
@test Base.Set([``, ``]) == Base.Set([``])
@test Set([``, echocmd]) != Set([``, ``])
@test Set([echocmd, ``, ``, echocmd]) == Set([echocmd, ``])
# equality tests for AndCmds
@test Base.AndCmds(`$echocmd abc`, `$echocmd def`) == Base.AndCmds(`$echocmd abc`, `$echocmd def`)
@test Base.AndCmds(`$echocmd abc`, `$echocmd def`) != Base.AndCmds(`$echocmd abc`, `$echocmd xyz`)
# test for correct error when an empty command is spawned (Issue 19094)
@test_throws ArgumentError run(Base.Cmd(``))
@test_throws ArgumentError run(Base.AndCmds(``, ``))
@test_throws ArgumentError run(Base.AndCmds(``, `$truecmd`))
@test_throws ArgumentError run(Base.AndCmds(`$truecmd`, ``))
# tests for reducing over collection of Cmd
@test_throws ArgumentError reduce(&, Base.AbstractCmd[])
@test_throws ArgumentError reduce(&, Base.Cmd[])
@test reduce(&, [`$echocmd abc`, `$echocmd def`, `$echocmd hij`]) == `$echocmd abc` & `$echocmd def` & `$echocmd hij`
# readlines(::Cmd), accidentally broken in #20203
@test sort(readlines(`$lscmd -A`)) == sort(readdir())
# issue #19864 (PR #20497)
let c19864 = readchomp(pipeline(ignorestatus(
`$exename --startup-file=no -e '
struct Error19864 <: Exception; end
Base.showerror(io::IO, e::Error19864) = print(io, "correct19864")
throw(Error19864())'`),
stderr=catcmd))
@test occursin("ERROR: correct19864", c19864)
end
# accessing the command elements as an array or iterator:
let c = `ls -l "foo bar"`
@test collect(c) == ["ls", "-l", "foo bar"]
@test first(c) == "ls" == c[1]
@test last(c) == "foo bar" == c[3] == c[end]
@test c[1:2] == ["ls", "-l"]
@test eltype(c) == String
@test length(c) == 3
@test eachindex(c) == 1:3
end
## Deadlock in spawning a cmd (#22832)
let out = Pipe(), inpt = Pipe()
Base.link_pipe!(out, reader_supports_async=true)
Base.link_pipe!(inpt, writer_supports_async=true)
p = run(pipeline(catcmd, stdin=inpt, stdout=out, stderr=devnull), wait=false)
t = @async begin # feed cat with 2 MB of data (zeros)
write(inpt, zeros(UInt8, 1048576 * 2))
close(inpt)
end
sleep(1) # give cat a chance to fill the write buffer for stdout
close(inpt.out)
close(out.in) # make sure we can still close the write end
@test sizeof(read(out)) == 1048576 * 2 # make sure we get all the data
@test success(p)
wait(t)
end
# `kill` error conditions
let p = run(`$sleepcmd 100`, wait=false)
# Should throw on invalid signals
@test_throws Base.IOError kill(p, typemax(Cint))
kill(p)
wait(p)
# Should not throw if already dead
kill(p)
end
# Second argument of shell_parse
let s = " \$abc "
@test s[Base.shell_parse(s)[2]] == "abc"
end
# Logging macros should not output to finalized streams (#26687)
let
cmd = `$(Base.julia_cmd()) -e 'finalizer(x->@info(x), "Hello")'`
output = readchomp(pipeline(cmd, stderr=catcmd))
@test occursin("Info: Hello", output)
end
# Sys.which() testing
psep = if Sys.iswindows() ";" else ":" end
withenv("PATH" => "$(Sys.BINDIR)$(psep)$(ENV["PATH"])") do
julia_exe = joinpath(Sys.BINDIR, "julia")
if Sys.iswindows()
julia_exe *= ".exe"
end
@test Sys.which("julia") == realpath(julia_exe)
@test Sys.which(julia_exe) == realpath(julia_exe)
end
mktempdir() do dir
withenv("PATH" => "$(dir)$(psep)$(ENV["PATH"])") do
# Test that files lacking executable permissions fail Sys.which
# but only on non-Windows systems, as Windows doesn't care...
foo_path = joinpath(dir, "foo")
touch(foo_path)
chmod(foo_path, 0o777)
if !Sys.iswindows()
@test Sys.which("foo") == realpath(foo_path)
@test Sys.which(foo_path) == realpath(foo_path)
chmod(foo_path, 0o666)
@test Sys.which("foo") === nothing
@test Sys.which(foo_path) === nothing
end
# Test that completely missing files also return nothing
@test Sys.which("this_is_not_a_command") === nothing
end
end
mktempdir() do dir
withenv("PATH" => "$(joinpath(dir, "bin1"))$(psep)$(joinpath(dir, "bin2"))$(psep)$(ENV["PATH"])") do
# Test that we have proper priorities
mkpath(joinpath(dir, "bin1"))
mkpath(joinpath(dir, "bin2"))
foo1_path = joinpath(dir, "bin1", "foo")
foo2_path = joinpath(dir, "bin2", "foo")
# On windows, we find things with ".exe" and ".com"
if Sys.iswindows()
foo1_path *= ".exe"
foo2_path *= ".com"
end
touch(foo1_path)
touch(foo2_path)
chmod(foo1_path, 0o777)
chmod(foo2_path, 0o777)
@test Sys.which("foo") == realpath(foo1_path)
# chmod() doesn't change which() on Windows, so don't bother to test that
if !Sys.iswindows()
chmod(foo1_path, 0o666)
@test Sys.which("foo") == realpath(foo2_path)
chmod(foo1_path, 0o777)
end
if Sys.iswindows()
# On windows, check that pwd() takes precedence, except when we provide a path
cd(joinpath(dir, "bin2")) do
@test Sys.which("foo") == realpath(foo2_path)
@test Sys.which(foo1_path) == realpath(foo1_path)
end
end
# Check that "bin1/bar" will actually run "bin1/bar"
bar_path = joinpath(dir, "bin1", "bar")
if Sys.iswindows()
bar_path *= ".exe"
end
touch(bar_path)
chmod(bar_path, 0o777)
cd(dir) do
@test Sys.which(joinpath("bin1", "bar")) == realpath(bar_path)
end
end
end
# Issue #27550: make sure `peek` works when slurping a Char from an AbstractPipe
open(`$catcmd`, "r+") do f
t = @async begin
write(f, "δ")
close(f.in)
end
@test read(f, Char) == 'δ'
wait(t)
end