Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

break/continue in a @testset for loop is broken #17462

Closed
KristofferC opened this issue Jul 17, 2016 · 9 comments
Closed

break/continue in a @testset for loop is broken #17462

KristofferC opened this issue Jul 17, 2016 · 9 comments
Labels
regression Regression in behavior compared to a previous version testsystem The unit testing framework and Test stdlib
Milestone

Comments

@KristofferC
Copy link
Member

KristofferC commented Jul 17, 2016

As @tkelman reported here: KristofferC/NearestNeighbors.jl#25 (and kindly bisected to cd35df536bd) Julia master now does not support break or continue in a @testset for loop

using Base.Test

@testset for x in [1,2,3]
    if x == 1
        continue
    end
end

ERROR: syntax: break or continue outside loop
 in eval(::Module, ::Any) at ./boot.jl:234
 in macro expansion at ./REPL.jl:92 [inlined]
 in (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:46

cc @JeffBezanson since it got bisected to commit that was authored by you

@KristofferC KristofferC changed the title break/continue in a @testset for loop got broken break/continue in a @testset for loop is broken Jul 17, 2016
@tkelman tkelman added regression Regression in behavior compared to a previous version testsystem The unit testing framework and Test stdlib labels Jul 17, 2016
@tkelman
Copy link
Contributor

tkelman commented Jul 23, 2016

Jeff, did you see this one?

@tkelman tkelman added this to the 0.5.x milestone Jul 26, 2016
@JeffBezanson
Copy link
Member

Ah, it looks like testset generates a comprehension expecting to be able to drop a break or continue into it. What did it do in that case --- return an array with undefined elements? Is that needed behavior?

@tkelman
Copy link
Contributor

tkelman commented Jul 28, 2016

cc @IainNZ if you know the answer - BaseTestNext may have a still-working implementation on 0.4?

@JeffBezanson
Copy link
Member

Here's a patch to try, that just collects results for all iterations that finish:

--- a/base/test.jl
+++ b/base/test.jl
@@ -732,7 +732,12 @@ function testset_forloop(args, testloop)
         pop_testset()
         finish(ts)
     end
-    Expr(:comprehension, blk, [esc(v) for v in loopvars]...)
+    quote
+        arr = Array{Any,1}(0)
+        $(Expr(:for, Expr(:block, [esc(v) for v in loopvars]...),
+               :(push!(arr, $blk))))
+        arr
+    end
 end

@KristofferC
Copy link
Member Author

The syntax looks just like a loop so being able to break is expected. It is also nifty if you want to skip tests based on some condition. Of course not an essential feature but it used to work so...

@JeffBezanson
Copy link
Member

Nobody is arguing with that as far as I can tell...

@KristofferC
Copy link
Member Author

I misunderstood your comment about "Is that needed behaviour" as asking about being able to break in a test loop at all. I see now what you meant, my apologies.

@wildart
Copy link
Member

wildart commented Jul 28, 2016

for and @testset for are not the same constructs. @testset for is just syntactic sugar for repetitive tests. So no continue or break. This must be stated in the unit test documentation.

@tkelman
Copy link
Contributor

tkelman commented Jul 28, 2016

why not? it's useful, I think jeff's patch and the minimal test here make sense.

tkelman added a commit that referenced this issue Jul 29, 2016
Add some counters to make sure things actually execute
tkelman added a commit that referenced this issue Jul 30, 2016
Fix #17462, break/continue in an at-testset for loop
mfasi pushed a commit to mfasi/julia that referenced this issue Sep 5, 2016
make the macro return a :for instead of a :comprehension
mfasi pushed a commit to mfasi/julia that referenced this issue Sep 5, 2016
Add some counters to make sure things actually execute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression Regression in behavior compared to a previous version testsystem The unit testing framework and Test stdlib
Projects
None yet
Development

No branches or pull requests

4 participants