summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2025-03-09 03:27:52 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2025-03-31 04:39:52 -0600
commite5907d69a9d1263e056a214e93e326dbe8243e15 (patch)
tree84b60da8786eae0cf95032d9aad907d192f60432
parentee5abed3cda095115d5afb72c860819d9369fc45 (diff)
measurestack: Allow output groups to be empty
-rw-r--r--build-aux/measurestack/app_output.py6
-rw-r--r--build-aux/measurestack/test_app_output.py52
2 files changed, 56 insertions, 2 deletions
diff --git a/build-aux/measurestack/app_output.py b/build-aux/measurestack/app_output.py
index b220101..5336b85 100644
--- a/build-aux/measurestack/app_output.py
+++ b/build-aux/measurestack/app_output.py
@@ -20,6 +20,9 @@ def print_group(
grp_name: str,
) -> None:
grp = result.groups[grp_name]
+ if not grp.rows:
+ print(f"= {grp_name} (empty) =")
+ return
nsum = sum(v.nstatic * v.cnt for v in grp.rows.values())
nmax = max(v.nstatic for v in grp.rows.values())
@@ -130,8 +133,7 @@ def print_c(
print("*/")
print("")
print("/*")
- if result.groups["Extra"].rows:
- print_group(result, location_xform, "Extra")
+ print_group(result, location_xform, "Extra")
for funcname in sorted(result.included_funcs):
print(f"included: {location_xform(funcname)}")
print("*/")
diff --git a/build-aux/measurestack/test_app_output.py b/build-aux/measurestack/test_app_output.py
new file mode 100644
index 0000000..4653d4e
--- /dev/null
+++ b/build-aux/measurestack/test_app_output.py
@@ -0,0 +1,52 @@
+# build-aux/measurestack/test_app_output.py - Tests for app_output.py
+#
+# Copyright (C) 2025 Luke T. Shumaker <lukeshu@lukeshu.com>
+# SPDX-License-Identifier: AGPL-3.0-or-later
+
+# pylint: disable=unused-variable
+
+import contextlib
+import io
+
+from . import analyze, app_output
+
+
+def test_print_group() -> None:
+ result = analyze.AnalyzeResult(
+ groups={
+ "A": analyze.AnalyzeResultGroup(
+ rows={
+ analyze.QName("short"): analyze.AnalyzeResultVal(nstatic=8, cnt=1),
+ analyze.QName(
+ "anamethatisnttoolongbutisnttooshort"
+ ): analyze.AnalyzeResultVal(nstatic=9, cnt=2),
+ }
+ ),
+ "B": analyze.AnalyzeResultGroup(rows={}),
+ },
+ missing=set(),
+ dynamic=set(),
+ included_funcs=set(),
+ )
+
+ def location_xform(loc: analyze.QName) -> str:
+ return str(loc)
+
+ stdout = io.StringIO()
+ with contextlib.redirect_stdout(stdout):
+ print()
+ app_output.print_group(result, location_xform, "A")
+ app_output.print_group(result, location_xform, "B")
+ assert (
+ stdout.getvalue()
+ == """
+= A =============================== ==
+anamethatisnttoolongbutisnttooshort 9 * 2
+short 8
+----------------------------------- --
+Total 26
+Maximum 9
+=================================== ==
+= B (empty) =
+"""
+ )