From a107a2d9646675441e4e7c8d5f3be14d8bae86ad Mon Sep 17 00:00:00 2001 From: Mike J Innes Date: Fri, 2 Mar 2018 17:46:48 +0000 Subject: [PATCH] tests --- test/runtests.jl | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 28289b3..eb4e8c3 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,38 @@ -using Traceur +using Traceur: warnings using Base.Test -# write your own tests here -@test 1 == 2 +warns_for(ws, x) = any(w -> contains(w.message, x), ws) +warns_for(ws, x, xs...) = warns_for(ws, x) && warns_for(ws, xs...) + +y = 1 + +@testset "Traceur" begin + +naive_relu(x) = x < 0 ? 0 : x + +ws = warnings(() -> naive_relu(1)) +@test isempty(ws) + +ws = warnings(() -> naive_relu(1.0)) +@test warns_for(ws, "returns") + +function naive_sum(xs) + s = 0 + for x in xs + s += x + end + return s +end + +ws = warnings(() -> naive_sum(1)) +@test isempty(ws) + +ws = warnings(() -> naive_sum(1.0)) +@test warns_for(ws, "assigned", "dispatch", "returns") + +f(x) = x+y + +ws = warnings(() -> f(1)) +@test warns_for(ws, "global", "dispatch", "returns") + +end