From e412c69a6e77b0751e0fa0303633e52154937a46 Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Mon, 14 Jan 2013 21:51:39 -0500 Subject: [PATCH] run should return nothing or error out; ignorestatus is broken. --- base/process.jl | 10 ++---- test/spawn.jl | 82 ++++++++++++++++++++++++++----------------------- 2 files changed, 45 insertions(+), 47 deletions(-) diff --git a/base/process.jl b/base/process.jl index 806229a57a8bd..a3adb1a57fa98 100644 --- a/base/process.jl +++ b/base/process.jl @@ -367,12 +367,7 @@ end function run(cmds::AbstractCmd,args...) ps = spawn(cmds,spawn_opts_inherit(args...)...) - success = wait_success(ps) - if success - return true - else - return pipeline_error(ps) - end + wait_success(ps) ? nothing : pipeline_error(ps) end success(proc::Process) = (assert(process_exited(proc)); proc.exit_code==0) @@ -384,7 +379,7 @@ function pipeline_error(proc::Process) if !proc.cmd.ignorestatus error("failed process: ",proc," [",proc.exit_code,"]") end - true + nothing end function pipeline_error(procs::ProcessChain) @@ -401,7 +396,6 @@ function pipeline_error(procs::ProcessChain) msg = string(msg,"\n ",proc," [",proc.exit_code,"]") end error(msg) - return false end function exec(thunk::Function) diff --git a/test/spawn.jl b/test/spawn.jl index 6afb2c2367e58..77abf4b3f5907 100644 --- a/test/spawn.jl +++ b/test/spawn.jl @@ -1,39 +1,43 @@ -################################## -# Cross Plaform tests for spawn. # -################################## - -# Assumes the following are available in the -# - GNU coreutils (or equivalent) -# - perl - -#TODO: -# - Windows: -# - Add a test whether coreutils are available and skip tests if not - -#### Examples used in the manual #### - -show(readall(`echo hello | sort`)) -@test readall(`echo hello | sort`) == "hello | sort\n" -@test readall(`echo hello`|`sort`) == "hello\n" -out = readall(`echo hello` & `echo world`) -@test search(out,"world") != (0,0) -@test search(out,"hello") != (0,0) -@test readall((`echo hello` & `echo world`)|`sort`)=="hello\nworld\n" - -## THIS requires visual inspection -@test run(`echo stdio passthrough OK`) - -prefixer(prefix, sleep) = `perl -nle '$|=1; print "'$prefix' ", $_; sleep '$sleep';'` -@test run(`perl -le '$|=1; for(0..2){ print; sleep 1 }'` | prefixer("A",2) & prefixer("B",2)) - -@test run(`perl -le '$|=1; for(0..2){ print; sleep 1 }'` | - prefixer("X",3) & prefixer("Y",3) & prefixer("Z",3) | - prefixer("A",2) & prefixer("B",2)) - -@test_fails run(`false`) -@test run(ignorestatus(`false`)) -@test run(ignorestatus(`false`)|`true`) -@test_fails run(ignorestatus(`false`)|`false`) -@test_fails run(ignorestatus(`false`)&`false`) -@test run(ignorestatus(`false`|`false`)) -@test run(ignorestatus(`false`&`false`)) +################################## +# Cross Plaform tests for spawn. # +################################## + +# Assumes the following are available in the +# - GNU coreutils (or equivalent) +# - perl + +#TODO: +# - Windows: +# - Add a test whether coreutils are available and skip tests if not + +#### Examples used in the manual #### + +@test readall(`echo hello | sort`) == "hello | sort\n" +@test readall(`echo hello`|`sort`) == "hello\n" + +out = readall(`echo hello` & `echo world`) +@test search(out,"world") != (0,0) +@test search(out,"hello") != (0,0) +@test readall((`echo hello` & `echo world`)|`sort`)=="hello\nworld\n" + +if false + @test (run(`echo hello`); true) + + prefixer(prefix, sleep) = `perl -nle '$|=1; print "'$prefix' ", $_; sleep '$sleep';'` + @test success(`perl -le '$|=1; for(0..2){ print; sleep 1 }'` | + prefixer("A",2) & prefixer("B",2)) + @test success(`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`) +if false + @test success(ignorestatus(`false`)) + @test success(ignorestatus(`false`) | `true`) + @test !success(ignorestatus(`false`) | `false`) + @test !success(ignorestatus(`false`) & `false`) + @test success(ignorestatus(`false` | `false`)) + @test success(ignorestatus(`false` & `false`)) +end