unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#69405: [PATCH] .emacs.d/tree-sitter/ not used in tree-sitter tests
@ 2024-02-26 13:36 Mattias Engdegård
  2024-02-26 13:59 ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Mattias Engdegård @ 2024-02-26 13:36 UTC (permalink / raw)
  To: 69405; +Cc: Yuan Fu

[-- Attachment #1: Type: text/plain, Size: 454 bytes --]

The .emacs.d/tree-sitter/ directory isn't searched when running tests non-interactively. The Makefile sets HOME to /nonexistent, which is correct but has the unfortunate side-effect of not running all the tests properly even with the compiled grammars installed.

The attached patch adds an environment variable, EMACS_TREE_SITTER_DIR, and sets it in the Makefile. I didn't bother documenting it because it's only intended for use in our own tests.


[-- Attachment #2: test-treesit-dir.diff --]
[-- Type: application/octet-stream, Size: 1892 bytes --]

diff --git a/src/treesit.c b/src/treesit.c
index d86ab501187..a2eeb89c93d 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -605,6 +605,17 @@ treesit_load_language (Lisp_Object language_symbol,
     = Fexpand_file_name (concat2 (build_string ("tree-sitter/"), lib_base_name),
 			 Fsymbol_value (Quser_emacs_directory));
   treesit_load_language_push_for_each_suffix (lib_name, &path_candidates);
+
+  /* Then push the directory of EMACS_TREE_SITTER_DIR, if any.
+     It is mainly intended for testing purposes, where HOME isn't available.  */
+  const char *envdir = getenv ("EMACS_TREE_SITTER_DIR");
+  if (envdir && *envdir)
+    {
+      Lisp_Object lib_name = Fexpand_file_name (lib_base_name,
+						build_string (envdir));
+      treesit_load_language_push_for_each_suffix (lib_name, &path_candidates);
+    }
+
   /* Then push paths from treesit-extra-load-path.  */
   Lisp_Object tail;
 
diff --git a/test/Makefile.in b/test/Makefile.in
index 720f5c7ff8c..5e7f1ac444b 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -118,6 +118,9 @@ emacs =
 # startup.el must be updated too.
 TEST_HOME = /nonexistent
 
+# Allow tests using tree-sitter to access grammars installed locally.
+TESTENV = HOME=$(TEST_HOME) EMACS_TREE_SITTER_DIR=$(HOME)/.emacs.d/tree-sitter
+
 test_module_dir := src/emacs-module-resources
 
 .PHONY: all check
@@ -178,7 +181,7 @@ testloadfile =
 
 %.log: %.elc
 	$(AM_V_GEN)${MKDIR_P} $(dir $@)
-	$(AM_V_at)HOME=$(TEST_HOME) $(emacs) \
+	$(AM_V_at)$(TESTENV) $(emacs) \
 	  -l ert ${ert_opts} -l $(testloadfile) \
 	  $(TEST_RUN_ERT)
 
@@ -335,7 +338,7 @@ .PHONY:
 ## summarizing step from running when there is an error.
 check-doit:
 ifeq ($(TEST_INTERACTIVE), yes)
-	HOME=$(TEST_HOME) $(emacs) \
+	$(TESTENV) $(emacs) \
 	  -l ert ${ert_opts} \
 	  $(patsubst %,-l %,$(if $(findstring $(TEST_LOAD_EL),yes),$ELFILES,$(ELFILES:.el=))) \
 	  $(TEST_RUN_ERT)

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-02-26 21:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-26 13:36 bug#69405: [PATCH] .emacs.d/tree-sitter/ not used in tree-sitter tests Mattias Engdegård
2024-02-26 13:59 ` Eli Zaretskii
2024-02-26 16:26   ` Mattias Engdegård
2024-02-26 16:52     ` Eli Zaretskii
2024-02-26 18:07       ` Mattias Engdegård
2024-02-26 21:34         ` Yuan Fu

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).