[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 15d940ad1fc 3/3: New test for finding C header files
From: |
Stefan Kangas |
Subject: |
master 15d940ad1fc 3/3: New test for finding C header files |
Date: |
Mon, 6 Jan 2025 14:04:40 -0500 (EST) |
branch: master
commit 15d940ad1fc3ca3a72c23d9873a32a1a68d0cb05
Author: Stefan Kangas <stefankangas@gmail.com>
Commit: Stefan Kangas <stefankangas@gmail.com>
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.
---
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 103131fbb34..9bfd9307bc7 100644
--- a/lisp/man.el
+++ b/lisp/man.el
@@ -2028,18 +2028,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