Repository: JuliaLang/julia
File: stdlib/Test/src/Test.jl (Julia)

Code before:
    source::LineNumberNode
end

struct Threw <: ExecutionResult
    exception
    current_exceptions::Base.ExceptionStack
    source::LineNumberNode
end

function eval_test_comparison(comparison::Expr, quoted::Expr, source::LineNumberNode, negate::Bool=false)
    comparison.head === :comparison || throw(ArgumentError("$comparison is not a comparison expression"))
    comparison_args = comparison.args
    quoted_args = quoted.args
    n = length(comparison_args)
    kw_suffix = ""

    res = true
    i = 1
    while i < n
        a, op, b = comparison_args[i], comparison_args[i+1], comparison_args[i+2]
        if res
            res = op(a, b)
        end
        quoted_args[i] = a
        quoted_args[i+2] = b
        i += 2
    end

    if negate
        res = !res
        quoted = Expr(:call, :!, quoted)
    end

    Returned(res,
             # stringify arguments in case of failure, for easy remote printing
             res === true ? quoted : sprint(print, quoted, context=(:limit => true)) * kw_suffix,
             source)
end

function eval_test_function(func, args, kwargs, quoted_func::Union{Expr,Symbol}, source::LineNumberNode, negate::Bool=false)
    res = func(args...; kwargs...)

    # Create "Evaluated" expression which looks like the original call but has all of
    # the arguments evaluated
    kw_suffix = ""
    if quoted_func === :≈ && !res
        kw_suffix = " ($(join(["$k=$v" for (k, v) in kwargs], ", ")))"
        quoted_args = args
    elseif isempty(kwargs)
        quoted_args = args
    else

Review comment (bug):
I think https://github.com/JuliaLang/julia/pull/61149 was right that `quoted` is the wrong predicate here in that it may have insufficiently many levels of quoting for correct printing.

Code after:
    source::LineNumberNode
end

struct Threw <: ExecutionResult
    exception
    current_exceptions::Base.ExceptionStack
    source::LineNumberNode
end

function eval_test_comparison(comparison::Expr, ops::Vector{Any}, source::LineNumberNode, negate::Bool=false)
    comparison.head === :comparison || throw(ArgumentError("$comparison is not a comparison expression"))
    comparison_args = comparison.args
    n = length(comparison_args)
    kw_suffix = ""

    res = true
    for i = 1:2:n - 2
        a, op, b = comparison_args[i], comparison_args[i+1], comparison_args[i+2]
        if res
            # chained comparisons stop running at the first `false`
            res = op(a, b)
        end
    end

    for i = 1:2:n
        comparison_args[i] = quoted(comparison_args[i])
    end
    for i = 2:2:n
        comparison_args[i] = ops[i]
    end
    if negate
        res = !res
        comparison = Expr(:call, :!, comparison)
    end

    Returned(res,
             # stringify arguments in case of failure, for easy remote printing
             res === true ? comparison : sprint(print, comparison, context=(:limit => true)) * kw_suffix,
             source)
end

function eval_test_function(func, args, kwargs, quoted_func::Union{Expr,Symbol}, source::LineNumberNode, negate::Bool=false)
    res = func(args...; kwargs...)

    # Create "Evaluated" expression which looks like the original call but has all of
    # the arguments evaluated
    kw_suffix = ""
    quoted_args = mapany(quoted, args)
    if quoted_func === :≈ && !res
        kw_suffix = " ($(join(["$k=$v" for (k, v) in kwargs], ", ")))"
    elseif !isempty(kwargs)