aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/luatests/luatests/qtctest.lua
blob: 3914979d554759caa9012d076205d08618b6e888 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
-- Copyright (C) 2024 The Qt Company Ltd.
-- SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
local inspect = require('inspect')

local function traceback()
    local result = ""
    local level = 1
    while true do
        local info = debug.getinfo(level, "Sl")
        if not info then break end
        if info.what ~= "C" then
            ---Get the last part of the path in info.source
            local fileName = info.source:match("^.+/(.+)$")
            result = result .. (string.format("  %s:%d\n", fileName, info.currentline))
        end
        level = level + 1
    end
    return result
end

local function compare(actual, expected)
    if (actual == expected) then
        return true
    end

    error("Compared values were not the same.\n  Actual: " ..
        inspect(actual) .. "\n  Expected: " .. inspect(expected) .. "\nTrace:\n" .. traceback())
end

return {
    compare = compare,
}