Skip to content

Commit

Permalink
run should return nothing or error out; ignorestatus is broken.
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski committed Jan 15, 2013
1 parent ba9eb0a commit e412c69
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 47 deletions.
10 changes: 2 additions & 8 deletions base/process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
82 changes: 43 additions & 39 deletions test/spawn.jl
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e412c69

Please sign in to comment.