From 8873a6ded234cfd24a14bb5608837a04580d1488 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 6 Jan 2025 20:03:48 +0100 Subject: [PATCH] New test for finding C header files 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 | 21 +++++++++++---------- test/lisp/man-tests.el | 9 +++++++++ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/lisp/man.el b/lisp/man.el index b8c08d34068..c0dea4f276d 100644 --- a/lisp/man.el +++ b/lisp/man.el @@ -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 diff --git a/test/lisp/man-tests.el b/test/lisp/man-tests.el index 5557c423a7a..f076439e802 100644 --- a/test/lisp/man-tests.el +++ b/test/lisp/man-tests.el @@ -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 -- 2.39.5