diff options
| author | Akaps316 <[email protected]> | 2026-04-11 21:45:14 +0530 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-04-20 09:35:36 +0800 |
| commit | 0c36a9b4acb9150c607b3d70291ad50148785038 (patch) | |
| tree | d2fc2fbadbabb7281d585d3d1adfe9b15f066710 | |
| parent | f2179c9ccf0d199af1ea2c3320945f20a2f12f6e (diff) | |
Refactor to use test project fixture and ordered dependencies
| -rw-r--r-- | tests/plugins/show/test.lua | 75 | ||||
| -rw-r--r-- | tests/projects/plugins/show/depgraph/src/core.c | 1 | ||||
| -rw-r--r-- | tests/projects/plugins/show/depgraph/src/main.c | 1 | ||||
| -rw-r--r-- | tests/projects/plugins/show/depgraph/src/ui.c | 1 | ||||
| -rw-r--r-- | tests/projects/plugins/show/depgraph/test.lua | 32 | ||||
| -rw-r--r-- | tests/projects/plugins/show/depgraph/xmake.lua | 15 | ||||
| -rw-r--r-- | xmake/plugins/show/info/depgraph.lua | 11 |
7 files changed, 52 insertions, 84 deletions
diff --git a/tests/plugins/show/test.lua b/tests/plugins/show/test.lua deleted file mode 100644 index 4bffa5bff..000000000 --- a/tests/plugins/show/test.lua +++ /dev/null @@ -1,75 +0,0 @@ -import("core.base.json") - -local function _create_project(tempdir) - io.writefile(path.join(tempdir, "xmake.lua"), [[ -add_rules("mode.debug", "mode.release") - -target("core") - set_kind("static") - add_files("src/core.c") - -target("ui") - set_kind("static") - add_deps("core") - add_files("src/ui.c") - -target("app") - set_kind("binary") - add_deps("core", "ui") - add_files("src/main.c") -]]) - os.mkdir(path.join(tempdir, "src")) - io.writefile(path.join(tempdir, "src", "core.c"), "int core(void) { return 0; }\n") - io.writefile(path.join(tempdir, "src", "ui.c"), "int ui(void) { return 0; }\n") - io.writefile(path.join(tempdir, "src", "main.c"), "int main(void) { return 0; }\n") -end - -function test_target_graph_json(t) - local tempdir = os.tmpfile() - os.mkdir(tempdir) - _create_project(tempdir) - - local homedir = path.join(tempdir, "home") - os.setenv("HOME", homedir) - os.mkdir(homedir) - os.mkdir(path.join(homedir, ".xmake")) - - local outdata = os.iorunv("xmake", {"show", "-P", tempdir, "--info=depgraph", "--json"}) - local graph = json.decode(outdata) - - t:are_equal(graph.root_targets, {"app"}) - t:require(#graph.targets == 3) - - local entries = {} - for _, target in ipairs(graph.targets) do - entries[target.name] = target - end - t:are_equal(entries.core.deps, {}) - t:are_equal(entries.ui.deps, {"core"}) - t:are_equal(entries.app.deps, {"core", "ui"}) - t:are_equal(entries.app.orderdeps, {"core", "ui"}) - t:are_equal(entries.app.kind, "binary") -end - -function test_target_graph_json_for_single_target(t) - local tempdir = os.tmpfile() - os.mkdir(tempdir) - _create_project(tempdir) - - local homedir = path.join(tempdir, "home") - os.setenv("HOME", homedir) - os.mkdir(homedir) - os.mkdir(path.join(homedir, ".xmake")) - - local outdata = os.iorunv("xmake", {"show", "-P", tempdir, "--info=depgraph", "--target=app", "--json"}) - local graph = json.decode(outdata) - - t:are_equal(graph.root_targets, {"app"}) - t:require(#graph.targets == 3) - - local names = {} - for _, target in ipairs(graph.targets) do - table.insert(names, target.name) - end - t:are_equal(names, {"core", "ui", "app"}) -end diff --git a/tests/projects/plugins/show/depgraph/src/core.c b/tests/projects/plugins/show/depgraph/src/core.c new file mode 100644 index 000000000..87a413095 --- /dev/null +++ b/tests/projects/plugins/show/depgraph/src/core.c @@ -0,0 +1 @@ +int core(void) { return 0; } diff --git a/tests/projects/plugins/show/depgraph/src/main.c b/tests/projects/plugins/show/depgraph/src/main.c new file mode 100644 index 000000000..78f2de106 --- /dev/null +++ b/tests/projects/plugins/show/depgraph/src/main.c @@ -0,0 +1 @@ +int main(void) { return 0; } diff --git a/tests/projects/plugins/show/depgraph/src/ui.c b/tests/projects/plugins/show/depgraph/src/ui.c new file mode 100644 index 000000000..c15794f4d --- /dev/null +++ b/tests/projects/plugins/show/depgraph/src/ui.c @@ -0,0 +1 @@ +int ui(void) { return 0; } diff --git a/tests/projects/plugins/show/depgraph/test.lua b/tests/projects/plugins/show/depgraph/test.lua new file mode 100644 index 000000000..28ae7c188 --- /dev/null +++ b/tests/projects/plugins/show/depgraph/test.lua @@ -0,0 +1,32 @@ +import("core.base.json") + +function test_depgraph_json(t) + local outdata = os.iorunv("xmake", {"show", "--info=depgraph", "--json"}) + local graph = json.decode(outdata) + + t:are_equal(graph.root_targets, {"app"}) + t:require(#graph.targets == 3) + + local entries = {} + for _, target in ipairs(graph.targets) do + entries[target.name] = target + end + t:are_equal(entries.core.deps, {}) + t:are_equal(entries.ui.deps, {"core"}) + t:are_equal(entries.app.deps, {"core", "ui"}) + t:are_equal(entries.app.kind, "binary") +end + +function test_depgraph_json_for_single_target(t) + local outdata = os.iorunv("xmake", {"show", "--info=depgraph", "--target=app", "--json"}) + local graph = json.decode(outdata) + + t:are_equal(graph.root_targets, {"app"}) + t:require(#graph.targets == 3) + + local names = {} + for _, target in ipairs(graph.targets) do + table.insert(names, target.name) + end + t:are_equal(names, {"core", "ui", "app"}) +end diff --git a/tests/projects/plugins/show/depgraph/xmake.lua b/tests/projects/plugins/show/depgraph/xmake.lua new file mode 100644 index 000000000..7077424f3 --- /dev/null +++ b/tests/projects/plugins/show/depgraph/xmake.lua @@ -0,0 +1,15 @@ +add_rules("mode.debug", "mode.release") + +target("core") + set_kind("static") + add_files("src/core.c") + +target("ui") + set_kind("static") + add_deps("core") + add_files("src/ui.c") + +target("app") + set_kind("binary") + add_deps("core", "ui") + add_files("src/main.c") diff --git a/xmake/plugins/show/info/depgraph.lua b/xmake/plugins/show/info/depgraph.lua index cd5f3ad69..1f3142309 100644 --- a/xmake/plugins/show/info/depgraph.lua +++ b/xmake/plugins/show/info/depgraph.lua @@ -27,14 +27,8 @@ import("private.detect.check_targetname") function _collect_target_entry(target) local deps = {} - for _, dep in pairs(target:deps() or {}) do - table.insert(deps, dep:name()) - end - table.sort(deps) - - local orderdeps = {} for _, dep in ipairs(target:orderdeps() or {}) do - table.insert(orderdeps, dep:name()) + table.insert(deps, dep:name()) end return { @@ -42,8 +36,7 @@ function _collect_target_entry(target) kind = target:kind(), group = target:get("group"), default = target:is_default(), - deps = deps, - orderdeps = orderdeps + deps = deps } end |
