These packages have a standard way of implementing a test corpus that
can be invoked by "tree-sitter test" from dev-util/tree-sitter-cli.
Some have additional platform-specific tests that are invoked in a
custom manner, but these are on top of the basic test corpus.

See: https://tree-sitter.github.io/tree-sitter/creating-parsers#command-test
Bug: https://bugs.gentoo.org/844223
Closes: https://github.com/gentoo/gentoo/pull/28529
Signed-off-by: Matoro Mahri <mat...@users.noreply.github.com>
---
 eclass/tree-sitter-grammar.eclass | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/eclass/tree-sitter-grammar.eclass b/eclass/tree-sitter-grammar.eclass
index acdb8a7ad73..958b2ce21c7 100644
--- a/eclass/tree-sitter-grammar.eclass
+++ b/eclass/tree-sitter-grammar.eclass
@@ -29,7 +29,10 @@ S="${WORKDIR}"/${PN}-${TS_PV:-${PV}}/src
 # Needed for tree_sitter/parser.h
 DEPEND="dev-libs/tree-sitter"

-EXPORT_FUNCTIONS src_compile src_install
+BDEPEND+=" test? ( dev-util/tree-sitter-cli )"
+IUSE+=" test"
+
+EXPORT_FUNCTIONS src_compile src_test src_install

 # @ECLASS_VARIABLE: TS_PV
 # @PRE_INHERIT
@@ -89,6 +92,16 @@ tree-sitter-grammar_src_compile() {
                        -o "${WORKDIR}"/${soname}
 }

+# @FUNCTION: tree-sitter-grammar_src_test
+# @DESCRIPTION:
+# Runs the Tree Sitter parser's test suite.
+# See: https://tree-sitter.github.io/tree-sitter/creating-parsers#command-test
+tree-sitter-grammar_src_test() {
+       debug-print-function ${FUNCNAME} "${@}"
+
+       (cd .. && tree-sitter test) || die "Test suite failed"
+}
+
 # @FUNCTION: tree-sitter-grammar_src_install
 # @DESCRIPTION:
 # Installs the Tree Sitter parser library.
--
2.38.1

Reply via email to