summaryrefslogtreecommitdiff
path: root/tests/plugins/repository/test.lua
blob: 07d11eb37e4de9dc6ca1c8e21c3d215dda3b2ab3 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
function main()
    -- backup existing env vars
    local prev_globaldir = os.getenv("XMAKE_GLOBALDIR")
    local prev_main_repo = os.getenv("XMAKE_MAIN_REPO")

    local gd = os.tmpfile() .. ".gd"
    io.writefile(gd .. "/.xmake/repositories/xmake-repo/plugins/hello-world/xmake.lua", [[
task("hello-world")
    set_category("plugin")
    on_run("main")
    set_menu {usage = "xmake hello-world"}
]])
    io.writefile(gd .. "/.xmake/repositories/xmake-repo/plugins/hello-world/main.lua", [[
function main() print("repo-ok") end
]])

    os.setenv("XMAKE_GLOBALDIR", gd)
    os.exec("xmake hello-world")

    os.exec("xmake plugin --install hello-world")

    local md = os.tmpfile() .. ".md"
    io.writefile(md .. "/.xmake/plugins/manual-plugin/xmake.lua", [[
task("manual-plugin")
    set_category("plugin")
    on_run("main")
    set_menu {usage = "xmake manual-plugin"}
]])
    io.writefile(md .. "/.xmake/plugins/manual-plugin/main.lua", [[
function main() print("manual") end
]])

    os.setenv("XMAKE_GLOBALDIR", md)
    os.exec("xmake plugin --list")
    os.exec("xmake plugin --remove manual-plugin")

    local ld = os.tmpfile() .. ".ld"
    io.writefile(ld .. "/plugins/hello-world/xmake.lua", [[
task("hello-world")
    set_category("plugin")
    on_run("main")
    set_menu {usage = "xmake hello-world"}
]])
    io.writefile(ld .. "/plugins/hello-world/main.lua", [[
function main() print("local-ok") end
]])

    os.setenv("XMAKE_GLOBALDIR", gd)
    os.setenv("XMAKE_MAIN_REPO", ld)
    os.exec("xmake hello-world")

    os.setenv("XMAKE_MAIN_REPO", "")
    os.exec("xmake hello-world")

    -- restore env vars
    if prev_globaldir then
        os.setenv("XMAKE_GLOBALDIR", prev_globaldir)
    else
        os.setenv("XMAKE_GLOBALDIR", "")
    end
    if prev_main_repo then
        os.setenv("XMAKE_MAIN_REPO", prev_main_repo)
    else
        os.setenv("XMAKE_MAIN_REPO", "")
    end

    os.tryrm(gd)
    os.tryrm(md)
    os.tryrm(ld)
end