diff --git a/base/client.jl b/base/client.jl index 664c7b65323da..d66abfb7a7399 100644 --- a/base/client.jl +++ b/base/client.jl @@ -383,7 +383,7 @@ function init_parallel() global PGRP global LPROC LPROC.id = 1 - assert(length(PGRP.workers) == 0) + @assert length(PGRP.workers) == 0 register_worker(LPROC) end diff --git a/base/deprecated.jl b/base/deprecated.jl index 8d5b220ef0f82..7d5d888f5054a 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -374,6 +374,10 @@ end @deprecate ntuple(n::Integer, f::Function) ntuple(f, n) +# 8856 + +@deprecate assert(x) @assert x + # 0.4 discontinued functions @noinline function subtypetree(x::DataType, level=-1) diff --git a/base/docs/helpdb.jl b/base/docs/helpdb.jl index ae7b8116a2a56..47a0864237089 100644 --- a/base/docs/helpdb.jl +++ b/base/docs/helpdb.jl @@ -2248,16 +2248,6 @@ Applies a function to the preceding argument. This allows for easy function chai """ Base.(:(|>)) -doc""" -```rst -:: - assert(cond) - -Throw an ``AssertionError`` if ``cond`` is false. Also available as the macro ``@assert expr``. -``` -""" -assert - doc""" ```rst :: @@ -12099,7 +12089,7 @@ doc""" :: @assert cond [text] -Throw an ``AssertionError`` if ``cond`` is false. Preferred syntax for writing assertions. +Throw an ``AssertionError`` if ``cond`` is false. ``` """ :@assert diff --git a/base/error.jl b/base/error.jl index ae382a78bdd14..d5e3efc12a75f 100644 --- a/base/error.jl +++ b/base/error.jl @@ -33,9 +33,8 @@ kwerr(kw) = error("unrecognized keyword argument \"", kw, "\"") systemerror(p, b::Bool) = b ? throw(Main.Base.SystemError(string(p))) : nothing -## assertion functions and macros ## +## assertion macro ## -assert(x) = x ? nothing : throw(Main.Base.AssertionError()) macro assert(ex, msgs...) msg = isempty(msgs) ? ex : msgs[1] if !isempty(msgs) && isa(msg, Expr) diff --git a/base/exports.jl b/base/exports.jl index 33170d1038916..eeade1c0e4225 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -1048,7 +1048,6 @@ export now, # errors - assert, backtrace, catch_backtrace, error, diff --git a/base/inference.jl b/base/inference.jl index e141dccc5c2c6..2093120f8b49b 100644 --- a/base/inference.jl +++ b/base/inference.jl @@ -763,7 +763,7 @@ end # arrays of types, or `nothing`. function precise_container_types(args, types, vtypes, sv) n = length(args) - assert(n == length(types)) + @assert n == length(types) result = cell(n) for i = 1:n ai = args[i]; ti = types[i] @@ -1432,7 +1432,7 @@ function typeinf_uncached(linfo::LambdaStaticData, atypes::ANY, sparams::SimpleV args = f_argnames(ast) la = length(args) - assert(is(ast.head,:lambda)) + @assert is(ast.head,:lambda) vinflist = ast.args[2][1]::Array{Any,1} vars = map(vi->vi[1], vinflist) body = (ast.args[3].args)::Array{Any,1} @@ -2408,7 +2408,7 @@ function inlineable(f::ANY, e::Expr, atype::ANY, sv::StaticVarInfo, enclosing_as if isvarargtype(methitype) methitype = methitype.parameters[1] else - @assert i==nm + @assert i == nm end end end diff --git a/base/multi.jl b/base/multi.jl index 7a24852aa8d66..3ecdd0265543a 100644 --- a/base/multi.jl +++ b/base/multi.jl @@ -279,7 +279,7 @@ end const PGRP = ProcessGroup([]) function topology(t) - assert(t in [:all_to_all, :master_slave, :custom]) + @assert (t in [:all_to_all, :master_slave, :custom]) if (PGRP.topology==t) || ((myid()==1) && (nprocs()==1)) || (myid() > 1) PGRP.topology = t else @@ -1059,9 +1059,9 @@ function init_worker(manager::ClusterManager=DefaultClusterManager()) disable_threaded_libs() # Since our pid has yet to be set, ensure no RemoteRefs have been created or addprocs() called. - assert(nprocs() <= 1) - assert(isempty(PGRP.refs)) - assert(isempty(client_refs)) + @assert nprocs() <= 1 + @assert isempty(PGRP.refs) + @assert isempty(client_refs) # System is started in head node mode, cleanup entries related to the same empty!(PGRP.workers) @@ -1191,7 +1191,7 @@ end function create_worker(manager, wconfig) # only node 1 can add new nodes, since nobody else has the full list of address:port - assert(LPROC.id == 1) + @assert LPROC.id == 1 # initiate a connect. Does not wait for connection completion in case of TCP. w = Worker() @@ -1591,7 +1591,7 @@ function timedwait(testcb::Function, secs::Float64; pollint::Float64=0.1) end function interrupt(pid::Integer) - assert(myid() == 1) + @assert myid() == 1 w = map_pid_wrkr[pid] if isa(w, Worker) manage(w.manager, w.id, w.config, :interrupt) @@ -1600,7 +1600,7 @@ end interrupt(pids::Integer...) = interrupt([pids...]) function interrupt(pids::AbstractVector=workers()) - assert(myid() == 1) + @assert myid() == 1 @sync begin for pid in pids @async interrupt(pid) diff --git a/base/process.jl b/base/process.jl index 2034a3c5971e7..28ca2ee8daef6 100644 --- a/base/process.jl +++ b/base/process.jl @@ -495,7 +495,7 @@ end const SIGPIPE = 13 function test_success(proc::Process) - assert(process_exited(proc)) + @assert process_exited(proc) if proc.exitcode < 0 #TODO: this codepath is not currently tested throw(UVError("could not start process $(string(proc.cmd))", proc.exitcode)) diff --git a/base/sparse/cholmod.jl b/base/sparse/cholmod.jl index cc47734a91137..6db5204d025c0 100644 --- a/base/sparse/cholmod.jl +++ b/base/sparse/cholmod.jl @@ -1322,7 +1322,7 @@ function diag{Tv}(F::Factor{Tv}) xv = f.x for j in 1:f.n jj = unsafe_load(c0, j) + 1 - assert(unsafe_load(r0, jj) == j - 1) + @assert unsafe_load(r0, jj) == j - 1 res[j] = unsafe_load(xv, jj) end end diff --git a/base/sysimg.jl b/base/sysimg.jl index 4e3590518c9e0..3c29187c70a96 100644 --- a/base/sysimg.jl +++ b/base/sysimg.jl @@ -115,9 +115,9 @@ include("intfuncs.jl") include("nullable.jl") # I/O +include("show.jl") include("task.jl") include("lock.jl") -include("show.jl") include("stream.jl") include("socket.jl") include("stat.jl") diff --git a/base/task.jl b/base/task.jl index bec12a1f7be0b..d1527fc5362a6 100644 --- a/base/task.jl +++ b/base/task.jl @@ -374,7 +374,7 @@ function wait() return result end end - assert(false) + @assert false end function pause() diff --git a/examples/clustermanager/0mq/ZMQCM.jl b/examples/clustermanager/0mq/ZMQCM.jl index d74b31cbd85eb..aa0355229b37d 100644 --- a/examples/clustermanager/0mq/ZMQCM.jl +++ b/examples/clustermanager/0mq/ZMQCM.jl @@ -135,7 +135,7 @@ function recv_data() try #println("On $(manager.zid_self) waiting to recv message") zid = parse(Int,bytestring(ZMQ.recv(manager.sub))) - assert(zid == manager.zid_self) + @assert zid == manager.zid_self from_zid = parse(Int,bytestring(ZMQ.recv(manager.sub))) mtype = bytestring(ZMQ.recv(manager.sub)) diff --git a/examples/clustermanager/simple/test_simple.jl b/examples/clustermanager/simple/test_simple.jl index 42268d58514af..9184d590be81b 100644 --- a/examples/clustermanager/simple/test_simple.jl +++ b/examples/clustermanager/simple/test_simple.jl @@ -4,9 +4,9 @@ cmanpath = joinpath(dirname(@__FILE__), "UnixDomainCM.jl") include(cmanpath) npids = addprocs(UnixDomainCM(2)) -assert(length(npids) == 2) +@assert length(npids) == 2 test_pids = [remotecall_fetch(x, myid) for x in npids] -assert(npids == test_pids) +@assert npids == test_pids rmprocs(npids; waitfor=1.0) exit(0) diff --git a/examples/juliatypes.jl b/examples/juliatypes.jl index 2b49a75f8596e..b1f36929d8d1d 100644 --- a/examples/juliatypes.jl +++ b/examples/juliatypes.jl @@ -141,7 +141,7 @@ extend(d::Dict, k, v) = (x = copy(d); x[k]=v; x) subst(t::TagT, env) = t===AnyT ? t : TagT(t.name, map(x->subst(x,env), t.params), t.vararg) subst(t::UnionT, env) = UnionT(subst(t.a,env), subst(t.b,env)) subst(t::Var, env) = get(env, t, t) -subst(t::UnionAllT, env) = (assert(!haskey(env, t.var)); +subst(t::UnionAllT, env) = (@assert !haskey(env, t.var); newVar = Var(t.var.name, subst(t.var.lb, env), subst(t.var.ub, env)); UnionAllT(newVar, subst(t.T, extend(env, t.var, newVar)))) subst(t, env) = t diff --git a/test/misc.jl b/test/misc.jl index 1384318cf50c1..f29c6de0e918a 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -28,19 +28,6 @@ let bt = backtrace() end end -# test assert() method -@test_throws AssertionError assert(false) -let res = assert(true) - @test res === nothing -end -let - ex = @test_throws AssertionError begin - assert(false) - error("unexpected") - end - @test isempty(ex.msg) -end - # test @assert macro @test_throws AssertionError (@assert 1 == 2) @test_throws AssertionError (@assert false) diff --git a/test/parallel.jl b/test/parallel.jl index 97ce7256f3d6a..f59684216b43d 100644 --- a/test/parallel.jl +++ b/test/parallel.jl @@ -60,7 +60,7 @@ for p in procs(d) idxf = first(idxes_in_p) idxl = last(idxes_in_p) d[idxf] = Float64(idxf) - rv = remotecall_fetch(p, (D,idxf,idxl) -> begin assert(D[idxf] == Float64(idxf)); D[idxl] = Float64(idxl); D[idxl]; end, d,idxf,idxl) + rv = remotecall_fetch(p, (D,idxf,idxl) -> begin @assert D[idxf] == Float64(idxf); D[idxl] = Float64(idxl); D[idxl]; end, d,idxf,idxl) @test d[idxl] == rv end