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)
(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
"\"-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