aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/external/metalang99/scripts
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2026-02-23 20:36:05 +0100
committerlemon <lsof@mailbox.org>2026-02-23 20:36:05 +0100
commit052144cabb126efe925a96f8a0597a0f2005d206 (patch)
tree4fd87244b9eef018b30e90fdff24c5b1a145a85e /test/external/metalang99/scripts
parent4e9020dfb847d80475415f9f5914efaa50238767 (diff)
add metalang99 testsuite (preprocessor stress testing)
Diffstat (limited to 'test/external/metalang99/scripts')
-rwxr-xr-xtest/external/metalang99/scripts/bench.sh16
-rw-r--r--test/external/metalang99/scripts/check-arities.py61
-rwxr-xr-xtest/external/metalang99/scripts/check-fmt.sh6
-rwxr-xr-xtest/external/metalang99/scripts/docs.sh3
-rwxr-xr-xtest/external/metalang99/scripts/fmt.sh5
-rwxr-xr-xtest/external/metalang99/scripts/open-docs.sh3
-rwxr-xr-xtest/external/metalang99/scripts/open-spec.sh3
-rwxr-xr-xtest/external/metalang99/scripts/spec.sh12
-rwxr-xr-xtest/external/metalang99/scripts/test-all.sh6
-rwxr-xr-xtest/external/metalang99/scripts/test-examples.sh8
-rwxr-xr-xtest/external/metalang99/scripts/test.sh16
11 files changed, 139 insertions, 0 deletions
diff --git a/test/external/metalang99/scripts/bench.sh b/test/external/metalang99/scripts/bench.sh
new file mode 100755
index 0000000..4b26aba
--- /dev/null
+++ b/test/external/metalang99/scripts/bench.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+set -e
+
+bench() {
+ echo $1
+ time gcc bench/$1 -ftrack-macro-expansion=0 -Iinclude -E -P >/dev/null
+ echo ""
+}
+
+bench "compare_25_items.c"
+bench "list_of_63_items.c"
+bench "100_v.c"
+bench "100_call.c"
+bench "many_call_in_arg_pos.c"
+bench "filter_map.c"
diff --git a/test/external/metalang99/scripts/check-arities.py b/test/external/metalang99/scripts/check-arities.py
new file mode 100644
index 0000000..c745a0b
--- /dev/null
+++ b/test/external/metalang99/scripts/check-arities.py
@@ -0,0 +1,61 @@
+#!/usr/bin/env python3
+
+# Make sure that arity specifiers of public metafunctions are consistent with their signatures.
+
+import os
+import re
+import xml.etree.ElementTree as ET
+import subprocess
+
+subprocess.call("doxygen > /dev/null 2> /dev/null", shell=True)
+
+
+def check_module(module):
+ print(f"Checking {module}.h ...")
+
+ tree = ET.parse(f"xml/{module}_8h.xml")
+ root = tree.getroot()
+
+ arity_specifiers = gather_arity_specifiers(root)
+
+ for metafunction_name, arity in gather_metafunctions(root).items():
+ expected_arity = int(arity)
+ actual_arity = int(arity_specifiers[metafunction_name])
+ assert expected_arity == actual_arity
+
+
+def gather_metafunctions(root):
+ metafunctions = {}
+
+ for definition in root.findall("./compounddef/sectiondef/memberdef"):
+ macro_name = definition.find("name").text
+ is_metalang99_compliant = re.search("ML99_[a-z]", macro_name)
+
+ exceptions = {
+ "ML99_call", "ML99_callUneval", "ML99_fatal", "ML99_abort", "ML99_tupleGet", "ML99_variadicsGet", "ML99_seqGet"}
+ is_exceptional = macro_name in exceptions
+
+ if (is_metalang99_compliant and not is_exceptional):
+ arity = len(list(definition.findall("param")))
+ metafunctions[macro_name] = arity
+
+ return metafunctions
+
+
+def gather_arity_specifiers(root):
+ arity_specifiers = {}
+
+ for definition in root.findall("./compounddef/programlisting/codeline/highlight[@class='preprocessor']"):
+ m = re.match(r"#define(\w+)_ARITY(\d)", "".join(definition.itertext()))
+ if m is not None:
+ metafunction_name = m.groups()[0]
+ arity = m.groups()[1]
+ arity_specifiers[metafunction_name] = arity
+
+ return arity_specifiers
+
+
+for path in os.listdir("include/metalang99"):
+ if path.endswith(".h"):
+ module = path.replace(".h", "")
+ check_module(module)
diff --git a/test/external/metalang99/scripts/check-fmt.sh b/test/external/metalang99/scripts/check-fmt.sh
new file mode 100755
index 0000000..a3342c6
--- /dev/null
+++ b/test/external/metalang99/scripts/check-fmt.sh
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+./run-clang-format/run-clang-format.py \
+ --exclude examples/build \
+ --exclude tests/build \
+ -r include tests examples bench
diff --git a/test/external/metalang99/scripts/docs.sh b/test/external/metalang99/scripts/docs.sh
new file mode 100755
index 0000000..957faa2
--- /dev/null
+++ b/test/external/metalang99/scripts/docs.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+sphinx-build -b html docs _build/html
diff --git a/test/external/metalang99/scripts/fmt.sh b/test/external/metalang99/scripts/fmt.sh
new file mode 100755
index 0000000..5f550b6
--- /dev/null
+++ b/test/external/metalang99/scripts/fmt.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+find include tests examples bench \
+ \( -path examples/build -o -path tests/build \) -prune -false -o \
+ \( -iname "*.h" \) -or \( -iname "*.c" \) | xargs clang-format -i
diff --git a/test/external/metalang99/scripts/open-docs.sh b/test/external/metalang99/scripts/open-docs.sh
new file mode 100755
index 0000000..ae3e4b5
--- /dev/null
+++ b/test/external/metalang99/scripts/open-docs.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+xdg-open _build/html/index.html
diff --git a/test/external/metalang99/scripts/open-spec.sh b/test/external/metalang99/scripts/open-spec.sh
new file mode 100755
index 0000000..921e122
--- /dev/null
+++ b/test/external/metalang99/scripts/open-spec.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+xdg-open spec/spec.pdf
diff --git a/test/external/metalang99/scripts/spec.sh b/test/external/metalang99/scripts/spec.sh
new file mode 100755
index 0000000..8da58e4
--- /dev/null
+++ b/test/external/metalang99/scripts/spec.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+set -e
+
+cd spec
+
+pdflatex -shell-escape spec.tex
+biber spec
+pdflatex -shell-escape spec.tex
+pdflatex -shell-escape spec.tex
+
+cd ..
diff --git a/test/external/metalang99/scripts/test-all.sh b/test/external/metalang99/scripts/test-all.sh
new file mode 100755
index 0000000..c4adc73
--- /dev/null
+++ b/test/external/metalang99/scripts/test-all.sh
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+set -e
+
+./scripts/test.sh
+./scripts/test-examples.sh
diff --git a/test/external/metalang99/scripts/test-examples.sh b/test/external/metalang99/scripts/test-examples.sh
new file mode 100755
index 0000000..fb0db8a
--- /dev/null
+++ b/test/external/metalang99/scripts/test-examples.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+set -e
+
+mkdir -p examples/build
+cd examples/build
+cmake ..
+cmake --build .
diff --git a/test/external/metalang99/scripts/test.sh b/test/external/metalang99/scripts/test.sh
new file mode 100755
index 0000000..ced5f53
--- /dev/null
+++ b/test/external/metalang99/scripts/test.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+set -e
+
+mkdir -p tests/build
+cd tests/build
+cmake ..
+cmake --build .
+
+if [[ "$OSTYPE" == "linux-gnu" ]]; then
+ echo "Testing ./gen ..."
+ ./gen
+
+ echo "Testing ./stmt ..."
+ ./stmt
+fi