Skip to content

Commit 61b85e1

Browse files
authored
Merge pull request #20281 from JuliaLang/tk/readlines-cmd
Fix readlines(::Cmd), was accidentally broken in #20203
2 parents d233cf9 + 443893d commit 61b85e1

File tree

3 files changed

+37
-32
lines changed

3 files changed

+37
-32
lines changed

base/io.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ function readlines(filename::AbstractString; chomp::Bool=true)
211211
readlines(f, chomp=chomp)
212212
end
213213
end
214-
readlines(s::IO=STDIN; chomp::Bool=true) = collect(eachline(s, chomp=chomp))
214+
readlines(s=STDIN; chomp::Bool=true) = collect(eachline(s, chomp=chomp))
215215

216216
## byte-order mark, ntoh & hton ##
217217

test/spawn.jl

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,52 @@
66

77
valgrind_off = ccall(:jl_running_on_valgrind, Cint, ()) == 0
88

9-
yes = `yes`
10-
echo = `echo`
9+
yescmd = `yes`
10+
echocmd = `echo`
1111
sortcmd = `sort`
12-
printf = `printf`
12+
printfcmd = `printf`
1313
truecmd = `true`
1414
falsecmd = `false`
1515
catcmd = `cat`
1616
shcmd = `sh`
1717
sleepcmd = `sleep`
18+
lscmd = `ls`
1819
if is_windows()
1920
try # use busybox-w32 on windows
2021
success(`busybox`)
21-
yes = `busybox yes`
22-
echo = `busybox echo`
22+
yescmd = `busybox yes`
23+
echocmd = `busybox echo`
2324
sortcmd = `busybox sort`
24-
printf = `busybox printf`
25+
printfcmd = `busybox printf`
2526
truecmd = `busybox true`
2627
falsecmd = `busybox false`
2728
catcmd = `busybox cat`
2829
shcmd = `busybox sh`
2930
sleepcmd = `busybox sleep`
31+
lscmd = `busybox ls`
3032
end
3133
end
3234

3335
#### Examples used in the manual ####
3436

35-
@test readstring(`$echo hello \| sort`) == "hello | sort\n"
36-
@test readstring(pipeline(`$echo hello`, sortcmd)) == "hello\n"
37-
@test length(spawn(pipeline(`$echo hello`, sortcmd)).processes) == 2
37+
@test readstring(`$echocmd hello \| sort`) == "hello | sort\n"
38+
@test readstring(pipeline(`$echocmd hello`, sortcmd)) == "hello\n"
39+
@test length(spawn(pipeline(`$echocmd hello`, sortcmd)).processes) == 2
3840

39-
out = readstring(`$echo hello` & `$echo world`)
41+
out = readstring(`$echocmd hello` & `$echocmd world`)
4042
@test search(out,"world") != 0:-1
4143
@test search(out,"hello") != 0:-1
42-
@test readstring(pipeline(`$echo hello` & `$echo world`, sortcmd)) == "hello\nworld\n"
44+
@test readstring(pipeline(`$echocmd hello` & `$echocmd world`, sortcmd)) == "hello\nworld\n"
4345

44-
@test (run(`$printf " \033[34m[stdio passthrough ok]\033[0m\n"`); true)
46+
@test (run(`$printfcmd " \033[34m[stdio passthrough ok]\033[0m\n"`); true)
4547

4648
# Test for SIGPIPE being treated as normal termination (throws an error if broken)
47-
is_unix() && run(pipeline(yes, `head`, DevNull))
49+
is_unix() && run(pipeline(yescmd, `head`, DevNull))
4850

4951
begin
5052
a = Base.Condition()
5153
@schedule begin
52-
p = spawn(pipeline(yes,DevNull))
54+
p = spawn(pipeline(yescmd,DevNull))
5355
Base.notify(a,p)
5456
@test !success(p)
5557
end
@@ -84,7 +86,7 @@ end
8486

8587
# STDIN Redirection
8688
let file = tempname()
87-
run(pipeline(`$echo hello world`, file))
89+
run(pipeline(`$echocmd hello world`, file))
8890
@test readstring(pipeline(file, catcmd)) == "hello world\n"
8991
@test open(readstring, pipeline(file, catcmd), "r") == "hello world\n"
9092
rm(file)
@@ -104,7 +106,7 @@ if !is_windows() # WINNT reports operation not supported on socket (ENOTSUP) for
104106
end
105107
t2 = @async begin
106108
sock = connect(fetch(r))
107-
run(pipeline(`$echo hello world`, sock))
109+
run(pipeline(`$echocmd hello world`, sock))
108110
close(sock)
109111
return true
110112
end
@@ -212,7 +214,7 @@ if valgrind_off
212214
end
213215

214216
# issue #6310
215-
@test readstring(pipeline(`$echo "2+2"`, `$exename --startup-file=no`)) == "4\n"
217+
@test readstring(pipeline(`$echocmd "2+2"`, `$exename --startup-file=no`)) == "4\n"
216218

217219
# issue #5904
218220
@test run(pipeline(ignorestatus(falsecmd), truecmd)) === nothing
@@ -270,9 +272,9 @@ end
270272
# issue #10994: libuv can't handle strings containing NUL
271273
let bad = "bad\0name"
272274
@test_throws ArgumentError run(`$bad`)
273-
@test_throws ArgumentError run(`$echo $bad`)
274-
@test_throws ArgumentError run(setenv(`$echo hello`, bad=>"good"))
275-
@test_throws ArgumentError run(setenv(`$echo hello`, "good"=>bad))
275+
@test_throws ArgumentError run(`$echocmd $bad`)
276+
@test_throws ArgumentError run(setenv(`$echocmd hello`, bad=>"good"))
277+
@test_throws ArgumentError run(setenv(`$echocmd hello`, "good"=>bad))
276278
end
277279

278280
# issue #12829
@@ -391,17 +393,17 @@ end
391393
# equality tests for Cmd
392394
@test Base.Cmd(``) == Base.Cmd(``)
393395
@test Base.Cmd(`lsof -i :9090`) == Base.Cmd(`lsof -i :9090`)
394-
@test Base.Cmd(`$echo test`) == Base.Cmd(`$echo test`)
395-
@test Base.Cmd(``) != Base.Cmd(`$echo test`)
396+
@test Base.Cmd(`$echocmd test`) == Base.Cmd(`$echocmd test`)
397+
@test Base.Cmd(``) != Base.Cmd(`$echocmd test`)
396398
@test Base.Cmd(``, ignorestatus=true) != Base.Cmd(``, ignorestatus=false)
397399
@test Base.Cmd(``, dir="TESTS") != Base.Cmd(``, dir="TEST")
398400
@test Base.Set([``, ``]) == Base.Set([``])
399-
@test Set([``, echo]) != Set([``, ``])
400-
@test Set([echo, ``, ``, echo]) == Set([echo, ``])
401+
@test Set([``, echocmd]) != Set([``, ``])
402+
@test Set([echocmd, ``, ``, echocmd]) == Set([echocmd, ``])
401403

402404
# equality tests for AndCmds
403-
@test Base.AndCmds(`$echo abc`, `$echo def`) == Base.AndCmds(`$echo abc`, `$echo def`)
404-
@test Base.AndCmds(`$echo abc`, `$echo def`) != Base.AndCmds(`$echo abc`, `$echo xyz`)
405+
@test Base.AndCmds(`$echocmd abc`, `$echocmd def`) == Base.AndCmds(`$echocmd abc`, `$echocmd def`)
406+
@test Base.AndCmds(`$echocmd abc`, `$echocmd def`) != Base.AndCmds(`$echocmd abc`, `$echocmd xyz`)
405407

406408
# test for correct error when an empty command is spawned (Issue 19094)
407409
@test_throws ArgumentError run(Base.Cmd(``))
@@ -411,13 +413,13 @@ end
411413

412414
@test_throws ArgumentError spawn(Base.Cmd(``))
413415
@test_throws ArgumentError spawn(Base.AndCmds(``, ``))
414-
@test_throws ArgumentError spawn(Base.AndCmds(``, `$echo test`))
415-
@test_throws ArgumentError spawn(Base.AndCmds(`$echo test`, ``))
416+
@test_throws ArgumentError spawn(Base.AndCmds(``, `$echocmd test`))
417+
@test_throws ArgumentError spawn(Base.AndCmds(`$echocmd test`, ``))
416418

417419
# tests for reducing over collection of Cmd
418420
@test_throws ArgumentError reduce(&, Base.AbstractCmd[])
419421
@test_throws ArgumentError reduce(&, Base.Cmd[])
420-
@test reduce(&, [`$echo abc`, `$echo def`, `$echo hij`]) == `$echo abc` & `$echo def` & `$echo hij`
422+
@test reduce(&, [`$echocmd abc`, `$echocmd def`, `$echocmd hij`]) == `$echocmd abc` & `$echocmd def` & `$echocmd hij`
421423

422424
# test for proper handling of FD exhaustion
423425
if is_unix()
@@ -453,3 +455,6 @@ let p=Pipe()
453455
@async close(p.in)
454456
@test readstring(p.out) == "Int128(0xffffffffffffffffffffffffffffffff)"
455457
end
458+
459+
# readlines(::Cmd), accidentally broken in #20203
460+
@test sort(readlines(`$lscmd -A`)) == sort(readdir())

test/test.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ let io = IOBuffer()
426426
@test !contains(str, "backtrace()")
427427
end
428428

429-
msg = readstring(ignorestatus(`$(Base.julia_cmd()) --startup-file=no --color=no -e '
429+
msg = readstring(pipeline(ignorestatus(`$(Base.julia_cmd()) --startup-file=no --color=no -e '
430430
using Base.Test
431431
432432
foo(x) = length(x)^2
@@ -444,7 +444,7 @@ foo(x) = length(x)^2
444444
@test foo(zeros(2)) == 4
445445
@test foo(ones(4)) == 15
446446
end
447-
end'`))
447+
end'`), stderr=DevNull))
448448

449449
@test contains(msg,
450450
"""

0 commit comments

Comments
 (0)