-
Notifications
You must be signed in to change notification settings - Fork 17
Avoid nesting testsets in test_rule #158
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,62 @@ | ||||||
| # Test.get_test_result generates code that uses the following so we must import them | ||||||
| using Test: Returned, Threw, eval_test | ||||||
|
|
||||||
| "A cunning hack to carry extra message along with the original expression in a test" | ||||||
| struct ExprAndMsg | ||||||
| ex | ||||||
| msg | ||||||
| end | ||||||
|
|
||||||
| """ | ||||||
| @test_msg msg condion kws... | ||||||
|
|
||||||
| This is per `Test.@test condion kws...` except that if it fails it also prints the `msg`. | ||||||
| If `msg==""` then this is just like `@test`, nothing is printed | ||||||
|
|
||||||
| ### Examles | ||||||
| ```julia | ||||||
| julia> @test_msg "It is required that the total is under 10" sum(1:1000) < 10; | ||||||
| Test Failed at REPL[1]:1 | ||||||
| Expression: sum(1:1000) < 10 | ||||||
| Problem: It is required that the total is under 10 | ||||||
| Evaluated: 500500 < 10 | ||||||
| ERROR: There was an error during testing | ||||||
|
|
||||||
|
|
||||||
| julia> @test_msg "It is required that the total is under 10" error("not working at all"); | ||||||
| Error During Test at REPL[2]:1 | ||||||
| Test threw exception | ||||||
| Expression: error("not working at all") | ||||||
| Problem: It is required that the total is under 10 | ||||||
| "not working at all" | ||||||
| Stacktrace: | ||||||
|
|
||||||
| julia> a = ""; | ||||||
|
|
||||||
| julia> @test_msg a sum(1:1000) < 10; | ||||||
| Test Failed at REPL[153]:1 | ||||||
| Expression: sum(1:1000) < 10 | ||||||
| Evaluated: 500500 < 10 | ||||||
| ERROR: There was an error during testing | ||||||
| ``` | ||||||
| """ | ||||||
| macro test_msg(msg, ex, kws...) | ||||||
oxinabox marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| # This code is basically a evil hack that accesses the internals of the Test stdlib. | ||||||
| # Code below is based on the `@test` macro definition as it was in Julia 1.6. | ||||||
| # https://github.com/JuliaLang/julia/blob/v1.6.1/stdlib/Test/src/Test.jl#L371-L376 | ||||||
| Test.test_expr!("@test_msg msg", ex, kws...) | ||||||
|
|
||||||
| result = Test.get_test_result(ex, __source__) | ||||||
| return :(Test.do_test($result, $ExprAndMsg($(string(ex)), $(esc(msg))))) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is using undocumented functions a code smell of some sort? I think it indicates that either:
I am leaning towards 1) from other experience with
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAIK it is 1) I will add a comment. I don't really understand what they do either, just that this is the thing that is needed.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment added
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, fair enough. LGTM just needs a version bump |
||||||
| end | ||||||
|
|
||||||
| function Base.print(io::IO, x::ExprAndMsg) | ||||||
| print(io, x.ex) | ||||||
| !isempty(x.msg) && print(io, "\n Problem: ", x.msg) | ||||||
| end | ||||||
|
|
||||||
|
|
||||||
| ### helpers for printing in log messages etc | ||||||
| _string_typeof(x) = string(typeof(x)) | ||||||
| _string_typeof(xs::Tuple) = join(_string_typeof.(xs), ",") | ||||||
| _string_typeof(x::PrimalAndTangent) = _string_typeof(primal(x)) # only show primal | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Are we ever interested in the tangent type? Probably not?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah i considered that. Note that that would display things like I think we can leave it as is (displaying just primals) for now, and consider adding that later. |
||||||
Uh oh!
There was an error while loading. Please reload this page.