commit:     6a060f3c58890e4b34c0fe73d560785af5b64487
Author:     Matoro Mahri <matoro <AT> users <DOT> noreply <DOT> github <DOT> 
com>
AuthorDate: Fri Dec  2 15:34:24 2022 +0000
Commit:     Matthew Smith <matthew <AT> gentoo <DOT> org>
CommitDate: Mon Dec  5 20:00:52 2022 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=6a060f3c

tree-sitter-grammar.eclass: Add src_test implementation

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
Signed-off-by: Matoro Mahri <matoro <AT> users.noreply.github.com>
Signed-off-by: Matthew Smith <matthew <AT> gentoo.org>

 eclass/tree-sitter-grammar.eclass | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/eclass/tree-sitter-grammar.eclass 
b/eclass/tree-sitter-grammar.eclass
index acdb8a7ad73b..c607ea9ddfb7 100644
--- a/eclass/tree-sitter-grammar.eclass
+++ b/eclass/tree-sitter-grammar.eclass
@@ -29,7 +29,11 @@ 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"
+RESTRICT+=" !test? ( test )"
+
+EXPORT_FUNCTIONS src_compile src_test src_install
 
 # @ECLASS_VARIABLE: TS_PV
 # @PRE_INHERIT
@@ -89,6 +93,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.

Reply via email to