-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Change in behavior of UndefVarError(::Symbol)
constructor breaks @test_throws
in 1.11.0-beta1
#54082
Comments
I prefer #54084 |
I think this was a breaking change, and should have been on the v1.11 milestone, fwiw. Over in ReTestItems.jl i was using exactly this to test that an I'm don't think either of the PRs linked above fix the MWE. I'm not sure i see another fix than special-casing But thought it was worth bumping this again since i think this was technically breaking (and might affect others) |
hm, actually, i'm not sure i know how to fix this in the package. How can i test that an I don't want to test that any Nor do I want to test based on the printed output, e.g. advice appreciated! otherwise i think we should go fix this in |
You could fix it in a package with something like this:
And then example usage would look like this:
|
The test_throws macro returns the exception object also, so that you can do more tests on it too |
Ah, so then the example can be simplified to: function f()
return foo_bar
end
function g()
return hello_world
end
ex = (@test_throws UndefVarError f()).value
@test ex.var == :foo_bar # passes
ex = (@test_throws UndefVarError g()).value
@test ex.var == :foo_bar # fails |
thanks for the suggestion! I think @test_throws UndefVarError(:x) f() is a much nicer and more obvious public API for this than either of those (especially since fields are not usually considered public), so i think this has convinced me we should keep supporting it -- will put up a PR |
…st_throws (#56231) Fix #54082 Arguably this was a breaking change (as a consequence of #51979). But regardless, it seems like useful functionality to have a public API for testing that an `UndefVarError` was thrown for the expected variable name (regardless of scope). This is particularly useful if you don't know what the scope is (for example, in my use-case i want to test that a specific `UndefVarError` is thrown from a module with a `gensym`'d name). Pre-v1.11 the syntax for this was ```julia @test_throws UndefVarError(:x) foo() ``` but that stopped working in v1.11 when `UndefVarError` got a second field (in fact in v1.11.1 this is an error when before it would pass) This PR restores that functionality. We might want to backport it to v1.11.x so that v1.11 isn't the only version that doesn't support this.
…st_throws (#56231) Fix #54082 Arguably this was a breaking change (as a consequence of #51979). But regardless, it seems like useful functionality to have a public API for testing that an `UndefVarError` was thrown for the expected variable name (regardless of scope). This is particularly useful if you don't know what the scope is (for example, in my use-case i want to test that a specific `UndefVarError` is thrown from a module with a `gensym`'d name). Pre-v1.11 the syntax for this was ```julia @test_throws UndefVarError(:x) foo() ``` but that stopped working in v1.11 when `UndefVarError` got a second field (in fact in v1.11.1 this is an error when before it would pass) This PR restores that functionality. We might want to backport it to v1.11.x so that v1.11 isn't the only version that doesn't support this. (cherry picked from commit b0c1525)
…st_throws (#56231) Fix #54082 Arguably this was a breaking change (as a consequence of #51979). But regardless, it seems like useful functionality to have a public API for testing that an `UndefVarError` was thrown for the expected variable name (regardless of scope). This is particularly useful if you don't know what the scope is (for example, in my use-case i want to test that a specific `UndefVarError` is thrown from a module with a `gensym`'d name). Pre-v1.11 the syntax for this was ```julia @test_throws UndefVarError(:x) foo() ``` but that stopped working in v1.11 when `UndefVarError` got a second field (in fact in v1.11.1 this is an error when before it would pass) This PR restores that functionality. We might want to backport it to v1.11.x so that v1.11 isn't the only version that doesn't support this.
MWE
Here is the MWE:
On Julia 1.10.2, this MWE works fine:
On Julia 1.11.0-beta1, the MWE is broken:
Similarly, on Julia nightly (1.12.0-DEV.339 / b9aeafa), the MWE is broken in the same way: (click to expand)
The issue here is that the behavior of the
UndefVarError(::Symbol)
constructor has changed between 1.10.2 and 1.11.0-beta1.The
UndefVarError(::Symbol)
constructor is in the manual. So, some questions are:UndefVarError(::Symbol)
constructor is public API?@test_throws
to avoid this specific use case from breaking?My initial thought is that this isn't a breaking change, and that we don't need to fix it in Julia; instead, we can just tell users to fix their code, e.g.:
But I'm curious to hear what other people think.
The text was updated successfully, but these errors were encountered: