]> git.eshelyaron.com Git - emacs.git/commitdiff
New test for finding C header files
authorStefan Kangas <stefankangas@gmail.com>
Mon, 6 Jan 2025 19:03:48 +0000 (20:03 +0100)
committerEshel Yaron <me@eshelyaron.com>
Wed, 8 Jan 2025 08:52:35 +0000 (09:52 +0100)
The assumption here is that if there is a C compiler, there is also a
math.h header somewhere.  The test should fail if we can't find that
file, and hopefully that will provoke users to create bug reports.

Let's see how far we can take this idea; we might have to give up and
disable the test in some configurations.  But doing that now seems
premature, even if we had a list of affected systems (which we don't).

* lisp/man.el (man--find-header-file): Factor out new function...
(Man-view-header-file): ...from here.
* test/lisp/man-tests.el (man-tests-find-header-file): New test.

(cherry picked from commit 15d940ad1fc3ca3a72c23d9873a32a1a68d0cb05)

lisp/man.el
test/lisp/man-tests.el

index b8c08d340689e4b6b1ef4c9c7431314bb79a205e..c0dea4f276df5e9bd554db0fc8cc93bc95a375ed 100644 (file)
@@ -2017,18 +2017,19 @@ Specify which REFERENCE to use; default is based on word at point."
       (error "You're looking at the first manpage in the buffer"))))
 
 ;; Header file support
+(defun man--find-header-files (file)
+  (delq nil
+        (mapcar (lambda (path)
+                  (let ((complete-path (expand-file-name file path)))
+                    (and (file-readable-p complete-path)
+                         complete-path)))
+                (Man-header-file-path))))
+
 (defun Man-view-header-file (file)
   "View a header file specified by FILE from `Man-header-file-path'."
-  (let ((path (Man-header-file-path))
-        complete-path)
-    (while path
-      (setq complete-path (expand-file-name file (car path))
-            path (cdr path))
-      (if (file-readable-p complete-path)
-          (progn (view-file complete-path)
-                 (setq path nil))
-        (setq complete-path nil)))
-    complete-path))
+  (when-let ((match (man--find-header-files file)))
+    (view-file (car match))
+    (car match)))
 
 ;;; Bookmark Man Support
 (declare-function bookmark-make-record-default
index 5557c423a7aa6bae36ec31fb2bb8ac1a06bd4ada..f076439e802eeef37fcb7ff264c89393d9cb69ce 100644 (file)
@@ -179,6 +179,15 @@ DESCRIPTION
                      "\"-k\" \"basename\""
                    "-k basename"))))
 
+(ert-deftest man-tests-find-header-file ()
+  ;; We should be able to find header files on any system with a C
+  ;; compiler, I think.
+  (skip-unless (or (executable-find "cc")
+                   (executable-find "gcc")
+                   (executable-find "clang")))
+  (should (file-exists-p (car (man--find-header-files "math.h"))))
+  (should-not (man--find-header-files "nonexistent-header-does-not-exist.h")))
+
 (provide 'man-tests)
 
 ;;; man-tests.el ends here