Skip to content

Commit

Permalink
Use busybox-w32 in spawn and cmdlineargs tests on Windows
Browse files Browse the repository at this point in the history
note that one test involving perl is being skipped, but it
had been disabled until recently - ref e412c69
  • Loading branch information
tkelman committed Jul 13, 2016
1 parent 68d991d commit b847d10
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 62 deletions.
10 changes: 5 additions & 5 deletions test/cmdlineargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,11 @@ let exename = `$(Base.julia_cmd()) --precompiled=yes`
@test readchomp(`$exename -e 'println(ARGS);' ''`) == "String[\"\"]"

# issue #12679
# TODO fix this on windows via busybox-w32
@test readchomp(pipeline(ignorestatus(`$exename --startup-file=no --compile=yes -ioo`),stderr=`cat`)) == "ERROR: unknown option `-o`"
@test readchomp(pipeline(ignorestatus(`$exename --startup-file=no -p`),stderr=`cat`)) == "ERROR: option `-p/--procs` is missing an argument"
@test readchomp(pipeline(ignorestatus(`$exename --startup-file=no --inline`),stderr=`cat`)) == "ERROR: option `--inline` is missing an argument"
@test readchomp(pipeline(ignorestatus(`$exename --startup-file=no -e "@show ARGS" -now -- julia RUN.jl`),stderr=`cat`)) == "ERROR: unknown option `-n`"
catcmd = is_unix() ? `cat` : `busybox cat`
@test readchomp(pipeline(ignorestatus(`$exename --startup-file=no --compile=yes -ioo`),stderr=catcmd)) == "ERROR: unknown option `-o`"
@test readchomp(pipeline(ignorestatus(`$exename --startup-file=no -p`),stderr=catcmd)) == "ERROR: option `-p/--procs` is missing an argument"
@test readchomp(pipeline(ignorestatus(`$exename --startup-file=no --inline`),stderr=catcmd)) == "ERROR: option `--inline` is missing an argument"
@test readchomp(pipeline(ignorestatus(`$exename --startup-file=no -e "@show ARGS" -now -- julia RUN.jl`),stderr=catcmd)) == "ERROR: unknown option `-n`"

# --compilecache={yes|no}
@test readchomp(`$exename -E "Bool(Base.JLOptions().use_compilecache)"`) == "true"
Expand Down
121 changes: 64 additions & 57 deletions test/spawn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,31 @@
# Cross Plaform tests for spawn. #
##################################

# Assumes the following are available in the
# - GNU coreutils (or equivalent)
# - perl

#TODO:
# - Windows:
# - fix coreutils dependent tests using busybox-w32, skip tests for no-gpl build

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

yes = `perl -le 'while (1) {print STDOUT "y"}'`
# use busybox-w32 on windows
yes = is_unix() ? `perl -le 'while (1) {print STDOUT "y"}'` : `busybox yes`
echo = is_unix() ? `echo` : `busybox echo`
sortcmd = is_unix() ? `sort` : `busybox sort`
printf = is_unix() ? `printf` : `busybox printf`
truecmd = is_unix() ? `true` : `busybox true`
falsecmd = is_unix() ? `false` : `busybox false`
catcmd = is_unix() ? `cat` : `busybox cat`
shcmd = is_unix() ? `sh` : `busybox sh`
sleepcmd = is_unix() ? `sleep` : `busybox sleep`

#### Examples used in the manual ####

@test readstring(`echo hello | sort`) == "hello | sort\n"
@test readstring(pipeline(`echo hello`, `sort`)) == "hello\n"
@test length(spawn(pipeline(`echo hello`, `sort`)).processes) == 2
@test readstring(`$echo hello | sort`) == "hello | sort\n"
@test readstring(pipeline(`$echo hello`, sortcmd)) == "hello\n"
@test length(spawn(pipeline(`$echo hello`, sortcmd)).processes) == 2

out = readstring(`echo hello` & `echo world`)
out = readstring(`$echo hello` & `$echo world`)
@test search(out,"world") != 0:-1
@test search(out,"hello") != 0:-1
@test readstring(pipeline(`echo hello` & `echo world`, `sort`)) == "hello\nworld\n"
@test readstring(pipeline(`$echo hello` & `$echo world`, sortcmd)) == "hello\nworld\n"

@test (run(`printf " \033[34m[stdio passthrough ok]\033[0m\n"`); true)
@test (run(`$printf " \033[34m[stdio passthrough ok]\033[0m\n"`); true)

# Test for SIGPIPE being treated as normal termination (throws an error if broken)
is_unix() && run(pipeline(yes, `head`, DevNull))
Expand All @@ -49,28 +50,30 @@ if valgrind_off
@test_throws Base.UVError run(`foo_is_not_a_valid_command`)
end

prefixer(prefix, sleep) = `perl -nle '$|=1; print "'$prefix' ", $_; sleep '$sleep';'`
@test success(pipeline(`perl -le '$|=1; for(0..2){ print; sleep 1 }'`,
if is_unix()
prefixer(prefix, sleep) = `perl -nle '$|=1; print "'$prefix' ", $_; sleep '$sleep';'`
@test success(pipeline(`perl -le '$|=1; for(0..2){ print; sleep 1 }'`,
prefixer("A",2) & prefixer("B",2)))
@test success(pipeline(`perl -le '$|=1; for(0..2){ print; sleep 1 }'`,
@test success(pipeline(`perl -le '$|=1; for(0..2){ print; sleep 1 }'`,
prefixer("X",3) & prefixer("Y",3) & prefixer("Z",3),
prefixer("A",2) & prefixer("B",2)))
end

@test success(`true`)
@test !success(`false`)
@test success(pipeline(`true`, `true`))
@test_broken success(ignorestatus(`false`))
@test_broken success(pipeline(ignorestatus(`false`), `true`))
@test !success(pipeline(ignorestatus(`false`), `false`))
@test !success(ignorestatus(`false`) & `false`)
@test_broken success(ignorestatus(pipeline(`false`, `false`)))
@test_broken success(ignorestatus(`false` & `false`))
@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
file = tempname()
run(pipeline(`echo hello world`, file))
@test readstring(pipeline(file, `cat`)) == "hello world\n"
@test open(readstring, pipeline(file, `cat`), "r") == "hello world\n"
run(pipeline(`$echo hello world`, file))
@test readstring(pipeline(file, catcmd)) == "hello world\n"
@test open(readstring, pipeline(file, catcmd), "r") == "hello world\n"
rm(file)

# Stream Redirection
Expand All @@ -80,23 +83,23 @@ if !is_windows() # WINNT reports operation not supported on socket (ENOTSUP) for
port, server = listenany(2326)
put!(r, port)
client = accept(server)
@test readstring(pipeline(client, `cat`)) == "hello world\n"
@test readstring(pipeline(client, catcmd)) == "hello world\n"
close(server)
end
@async begin
sock = connect(fetch(r))
run(pipeline(`echo hello world`, sock))
run(pipeline(`$echo hello world`, sock))
close(sock)
end
end

@test readstring(setenv(`sh -c "echo \$TEST"`,["TEST=Hello World"])) == "Hello World\n"
@test readstring(setenv(`sh -c "echo \$TEST"`,Dict("TEST"=>"Hello World"))) == "Hello World\n"
@test readstring(setenv(`sh -c "echo \$TEST"`,"TEST"=>"Hello World")) == "Hello World\n"
@test readstring(setenv(`$shcmd -c "echo \$TEST"`,["TEST=Hello World"])) == "Hello World\n"
@test readstring(setenv(`$shcmd -c "echo \$TEST"`,Dict("TEST"=>"Hello World"))) == "Hello World\n"
@test readstring(setenv(`$shcmd -c "echo \$TEST"`,"TEST"=>"Hello World")) == "Hello World\n"
@test (withenv("TEST"=>"Hello World") do
readstring(`sh -c "echo \$TEST"`); end) == "Hello World\n"
pathA = readchomp(setenv(`sh -c "pwd -P"`;dir=".."))
pathB = readchomp(setenv(`sh -c "cd .. && pwd -P"`))
readstring(`$shcmd -c "echo \$TEST"`); end) == "Hello World\n"
pathA = readchomp(setenv(`$shcmd -c "pwd -P"`;dir=".."))
pathB = readchomp(setenv(`$shcmd -c "cd .. && pwd -P"`))
if is_windows()
# on windows, sh returns posix-style paths that are not valid according to ispath
@test pathA == pathB
Expand All @@ -109,15 +112,15 @@ str = ""
for i=1:1000
str = "$str\n $(randstring(10))"
end
stdout, stdin, proc = readandwrite(`cat -`)
stdout, stdin, proc = readandwrite(`$catcmd -`)
write(stdin, str)
close(stdin)
str2 = readstring(stdout)
@test str2 == str

# 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(`cat -`, file), "w") do io
open(pipeline(`$catcmd -`, file), "w") do io
write(io, str)
end
rm(file)
Expand All @@ -129,7 +132,7 @@ t = @async begin
try
wait(r)
end
p = spawn(`sleep 1`); wait(p)
p = spawn(`$sleepcmd 1`); wait(p)
@test p.exitcode == 0
end
yield()
Expand Down Expand Up @@ -172,7 +175,7 @@ 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 readstring(pipeline(`$exename --startup-file=no -e 'println(STDERR,"Hello World")'`, stderr=`cat`)) == "Hello World\n"
@test readstring(pipeline(`$exename --startup-file=no -e 'println(STDERR,"Hello World")'`, stderr=catcmd)) == "Hello World\n"
out = Pipe()
proc = spawn(pipeline(`$exename --startup-file=no -e 'println(STDERR,"Hello World")'`, stderr = out))
close(out.in)
Expand All @@ -181,10 +184,10 @@ if valgrind_off
end

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

# issue #5904
@test run(pipeline(ignorestatus(`false`), `true`)) === nothing
@test run(pipeline(ignorestatus(falsecmd), truecmd)) === nothing


# issue #6010
Expand Down Expand Up @@ -244,9 +247,9 @@ end
# issue #10994: libuv can't handle strings containing NUL
let bad = "bad\0name"
@test_throws ArgumentError run(`$bad`)
@test_throws ArgumentError run(`echo $bad`)
@test_throws ArgumentError run(setenv(`echo hello`, bad=>"good"))
@test_throws ArgumentError run(setenv(`echo hello`, "good"=>bad))
@test_throws ArgumentError run(`$echo $bad`)
@test_throws ArgumentError run(setenv(`$echo hello`, bad=>"good"))
@test_throws ArgumentError run(setenv(`$echo hello`, "good"=>bad))
end

# issue #12829
Expand Down Expand Up @@ -300,10 +303,14 @@ let fname = tempname()
write(fname, "test\n")
code = """
for line in eachline(STDIN)
run(pipeline(`echo asdf`,`cat`))
if is_unix()
run(pipeline(`echo asdf`,`cat`))
else
run(pipeline(`busybox echo asdf`,`busybox cat`))
end
end
"""
@test success(pipeline(`cat $fname`, `$exename -e $code`))
@test success(pipeline(`$catcmd $fname`, `$exename -e $code`))
rm(fname)
end

Expand Down Expand Up @@ -332,7 +339,7 @@ end
@test Base.shell_split("\"\\\\\"") == ["\\"]

# issue #13616
@test_throws ErrorException collect(eachline(pipeline(`cat _doesnt_exist__111_`, stderr=DevNull)))
@test_throws ErrorException collect(eachline(pipeline(`$catcmd _doesnt_exist__111_`, stderr=DevNull)))

# make sure windows_verbatim strips quotes
if is_windows()
Expand All @@ -345,19 +352,19 @@ end
# equality tests for Cmd
@test Base.Cmd(``) == Base.Cmd(``)
@test Base.Cmd(`lsof -i :9090`) == Base.Cmd(`lsof -i :9090`)
@test Base.Cmd(`echo test`) == Base.Cmd(`echo test`)
@test Base.Cmd(``) != Base.Cmd(`echo test`)
@test Base.Cmd(`$echo test`) == Base.Cmd(`$echo test`)
@test Base.Cmd(``) != Base.Cmd(`$echo 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([``, `echo`]) != Set([``, ``])
@test Set([`echo`, ``, ``, `echo`]) == Set([`echo`, ``])
@test Set([``, echo]) != Set([``, ``])
@test Set([echo, ``, ``, echo]) == Set([echo, ``])

# equality tests for AndCmds
@test Base.AndCmds(`echo abc`, `echo def`) == Base.AndCmds(`echo abc`, `echo def`)
@test Base.AndCmds(`echo abc`, `echo def`) != Base.AndCmds(`echo abc`, `echo xyz`)
@test Base.AndCmds(`$echo abc`, `$echo def`) == Base.AndCmds(`$echo abc`, `$echo def`)
@test Base.AndCmds(`$echo abc`, `$echo def`) != Base.AndCmds(`$echo abc`, `$echo xyz`)

# tests for reducing over collection of Cmd
@test_throws ArgumentError reduce(&, Base.AbstractCmd[])
@test_throws ArgumentError reduce(&, Base.Cmd[])
@test reduce(&, [`echo abc`, `echo def`, `echo hij`]) == `echo abc` & `echo def` & `echo hij`
@test reduce(&, [`$echo abc`, `$echo def`, `$echo hij`]) == `$echo abc` & `$echo def` & `$echo hij`

0 comments on commit b847d10

Please sign in to comment.