summaryrefslogtreecommitdiff
path: root/tests/projects/c/filc/safety_test/test.lua
blob: 2a372b3cd0c3489cb3ab0adf73256b9705bea84c (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import("utils.ci.is_running", {alias = "ci_is_running"})

function main(t)
    -- filc only supports Linux x86_64
    if os.host() ~= "linux" or os.arch() ~= "x86_64" then
        return t:skip("filc is only supported on linux/x86_64")
    end

    local flags = ci_is_running() and "-vD" or ""

    -- configure and install the filc package; skip if unavailable
    local configured = try
    {
        function ()
            os.exec("xmake f -c -y " .. flags)
            return true
        end,
        catch { function () end }
    }
    if not configured then
        return t:skip("filc package not available or install failed")
    end

    os.exec("xmake -r " .. flags)

    -- find the compiled binary
    local binfile = path.join("build", os.host(), os.arch(), "release", "safety_test")
    assert(os.isfile(binfile), "binary not found: " .. binfile)

    -- run the binary — it MUST exit non-zero and emit a filc safety error
    -- os.iorunv raises on non-zero exit in the sandbox, so catch the failure
    local filc_output = nil
    try
    {
        function ()
            os.iorunv(binfile, {})
        end,
        catch
        {
            function (errors)
                filc_output = tostring(errors)
            end
        }
    }
    assert(filc_output, "expected safety_test to exit non-zero, but it succeeded")
    assert(filc_output:find("filc safety error", 1, true),
        "expected 'filc safety error' in output, got:\n" .. filc_output)
    assert(filc_output:find("filc panic", 1, true),
        "expected 'filc panic' in output, got:\n" .. filc_output)

    cprint("${green}filc safety check triggered as expected${reset}")
end