julia> using Test
julia> "Return exact same expression."
@assert ex.head != :(=) "oops we don't support head of :="
julia> macro test_macro_throws(err_type, ex)
@test_macro_throws (macro with 2 methods)
julia> @testset "identity" begin
new = @flawed_identity 2 + 1
@test new == 3
@test_macro_throws AssertionError @flawed_identity ex2 = 2 + 1
err = LoadError("REPL", 4, AssertionError("oops we don't support head of :="))
Test Summary: | Pass Total
identity | 2 2
Test.DefaultTestSet("identity", Any, 2, false, false)
there might be a better way. We haven’t tried anything else recently.
Bit late to the party, but it can sometimes also be very useful to move as much of the logic as possible into a function. The function can be tested quite easily. See also InteractiveUtils.gen_call_with_extracted_types_and_kwargs and it’s usage in, for example, Revise.jl