diff options
| author | ruki <[email protected]> | 2026-04-20 17:35:48 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-04-20 17:35:48 +0800 |
| commit | 55f8d448564f7cc198edb4db506ec7c18ca8f0f6 (patch) | |
| tree | 6822b239d43091d20037a99b6ffa9fd7e449f1db /tests/plugins/show/test.lua | |
| parent | 3a1b4e1719ba50b259afa27b450f06c39548003d (diff) | |
| parent | 4e3f6b16db88b9c1afad898a7f5dfeaecdfd0f27 (diff) | |
Merge pull request #7490 from xmake-io/show
Export target dependency graph as json/dot
Diffstat (limited to 'tests/plugins/show/test.lua')
| -rw-r--r-- | tests/plugins/show/test.lua | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/plugins/show/test.lua b/tests/plugins/show/test.lua new file mode 100644 index 000000000..dea98c204 --- /dev/null +++ b/tests/plugins/show/test.lua @@ -0,0 +1,81 @@ +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 == 4) + + 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["ext::net"].deps, {"core"}) + t:are_equal(entries.app.deps, {"core", "ui", "ext::net"}) +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 == 4) + + local names = {} + for _, target in ipairs(graph.targets) do + table.insert(names, target.name) + end + t:require(table.contains(names, "core")) + t:require(table.contains(names, "ui")) + t:require(table.contains(names, "ext::net")) + t:require(table.contains(names, "app")) +end + +function test_depgraph_json_namespace(t) + local outdata = os.iorunv("xmake", {"show", "--info=depgraph", "--target=ext::net", "--json"}) + local graph = json.decode(outdata) + + t:are_equal(graph.root_targets, {"ext::net"}) + t:require(#graph.targets == 2) + + local entries = {} + for _, target in ipairs(graph.targets) do + entries[target.name] = target + end + t:require(entries["ext::net"]) + t:are_equal(entries["ext::net"].deps, {"core"}) + t:are_equal(entries.core.deps, {}) +end + +function test_depgraph_tree(t) + local outdata = os.iorunv("xmake", {"show", "--info=depgraph"}) + t:require(outdata:find("app", 1, true)) + t:require(outdata:find("core", 1, true)) + t:require(outdata:find("ui", 1, true)) + t:require(outdata:find("ext::net", 1, true)) + t:require(outdata:find("|-- ", 1, true)) + t:require(outdata:find("\\-- ", 1, true)) +end + +function test_depgraph_dot(t) + local outdata = os.iorunv("xmake", {"show", "--info=depgraph", "--format=dot"}) + t:require(outdata:find("digraph {", 1, true)) + t:require(outdata:find('"core"', 1, true)) + t:require(outdata:find('"ui" -> "core"', 1, true)) + t:require(outdata:find('"app" -> "core"', 1, true)) + t:require(outdata:find('"app" -> "ui"', 1, true)) + t:require(outdata:find('"ext::net" -> "core"', 1, true)) + t:require(outdata:find('"app" -> "ext::net"', 1, true)) + t:require(outdata:find("}", 1, true)) +end + +function test_depgraph_dot_for_single_target(t) + local outdata = os.iorunv("xmake", {"show", "--info=depgraph", "--target=ui", "--format=dot"}) + t:require(outdata:find("digraph {", 1, true)) + t:require(outdata:find('"core"', 1, true)) + t:require(outdata:find('"ui" -> "core"', 1, true)) + t:require(not outdata:find('"app"', 1, true)) +end |
