Repository: JuliaLang/julia
File: test/buildkitetestjson.jl (Julia)

Code before:
            data["failure_expanded"] = [Dict{String,Any}("expanded" => split(err, '\n'), "backtrace" => split(trace, '\n'))]
        else
            data["failure_expanded"] = [Dict{String,Any}("expanded" => split(result_show, '\n'), "backtrace" => [])]
        end
    end

    rid = get_rid(data)
    duplicate = haskey(result_counts, rid)

    if duplicate
        result_counts[rid] += 1
        return nothing
    else
        result_counts[rid] = 1
        return data
    end
end

function collect_results!(results::Vector{Dict{String,Any}}, result::Test.Result, common_data::Dict{String,Any}, result_counts::ResultCountDict)
    rdata = result_dict(result, result_counts)
    if rdata !== nothing # nothing if it's a duplicate that's been counted
        push!(results, merge(common_data, rdata))
    end
end

function collect_results!(results::Vector{Dict{String,Any}}, result::Test.DefaultTestSet, common_data::Dict{String,Any}, result_counts::ResultCountDict)
    collect_results!(results, result, common_data["scope"])
end

function collect_results!(results::Vector{Dict{String,Any}}, testset::Test.DefaultTestSet, prefix::String="")
    common_data = result_dict(testset, prefix)
    # testset duration is not relevant for individual test results
    common_data["history"]["duration"] = 0.0 # required field
    delete!(common_data["history"], "end_at")
    result_offset = length(results) + 1
    result_counts = ResultCountDict()

    for result in testset.results
        collect_results!(results, result, common_data, result_counts)
    end
    # Add a tag for count of each result
    for result in results[result_offset:end]
        rid = get_rid(result)
        result["tags"]["count"] = string(get(result_counts, rid, 1))
    end
    return results
end

function serialize_testset_result_file(dir::String, testset::Test.DefaultTestSet)
    data = Dict{String,Any}[]
    t = @elapsed collect_results!(data, testset)

Review comment (suggestion):
```suggestion
function collect_results!(results::Vector{Dict{String,Any}}, result::Test.DefaultTestSet, common_data::Dict{String,Any}, result_counts::ResultCountDict)
    collect_results!(results, result, common_data["scope"])
end

function collect_results!(results::Vector{Dict{String,Any}}, result, common_data::Dict{String,Any}, result_counts::ResultCountDict)
    return nothing
```


Code after:
            data["failure_expanded"] = [Dict{String,Any}("expanded" => split(err, '\n'), "backtrace" => split(trace, '\n'))]
        else
            data["failure_expanded"] = [Dict{String,Any}("expanded" => split(result_show, '\n'), "backtrace" => [])]
        end
    end

    rid = get_rid(data)
    duplicate = haskey(result_counts, rid)

    if duplicate
        result_counts[rid] += 1
        return nothing
    else
        result_counts[rid] = 1
        return data
    end
end

function collect_results!(results::Vector{Dict{String,Any}}, result::Test.Result, common_data::Dict{String,Any}, result_counts::ResultCountDict)
    rdata = result_dict(result, result_counts)
    if rdata !== nothing # nothing if it's a duplicate that's been counted
        push!(results, merge(common_data, rdata))
    end
end
function collect_results!(results::Vector{Dict{String,Any}}, result::Test.DefaultTestSet, common_data::Dict{String,Any}, result_counts::ResultCountDict)
    collect_results!(results, result, common_data["scope"])
end
function collect_results!(results::Vector{Dict{String,Any}}, result, common_data::Dict{String,Any}, result_counts::ResultCountDict)
    return nothing
end

function collect_results!(results::Vector{Dict{String,Any}}, testset::Test.DefaultTestSet, prefix::String="")
    common_data = result_dict(testset, prefix)
    # testset duration is not relevant for individual test results
    common_data["history"]["duration"] = 0.0 # required field
    delete!(common_data["history"], "end_at")
    result_offset = length(results) + 1
    result_counts = ResultCountDict()

    for result in testset.results
        collect_results!(results, result, common_data, result_counts)
    end
    # Add a tag for count of each result
    for result in results[result_offset:end]
        rid = get_rid(result)
        result["tags"]["count"] = string(get(result_counts, rid, 1))
    end
    return results
end

function serialize_testset_result_file(dir::String, testset::Test.DefaultTestSet)