:type '(repeat (cons (string :tag "Bogus Section")
(string :tag "Real Section"))))
-(defcustom Man-header-file-path
- (let ((arch (with-temp-buffer
- (when (eq 0 (ignore-errors
- (call-process "gcc" nil '(t nil) nil
- "-print-multiarch")))
- (goto-char (point-min))
- (buffer-substring (point) (line-end-position)))))
- (base '("/usr/include" "/usr/local/include")))
- (if (zerop (length arch))
- base
- (append base (list (expand-file-name arch "/usr/include")))))
+(defcustom Man-header-file-path (internal--c-header-file-path)
"C Header file search path used in Man."
:version "24.1" ; add multiarch
:type '(repeat string))
(defun evenp (integer) "Return t if INTEGER is even." (eq (logand integer 1) 0))
+(defun internal--c-header-file-path ()
+ "Return search path for C header files (a list of strings)."
+ (let ((arch (with-temp-buffer
+ (when (eq 0 (ignore-errors
+ (call-process "gcc" nil '(t nil) nil
+ "-print-multiarch")))
+ (goto-char (point-min))
+ (buffer-substring (point) (line-end-position)))))
+ (base '("/usr/include" "/usr/local/include")))
+ (if (seq-empty-p arch) base
+ (append base (list (expand-file-name arch "/usr/include"))))))
+
;;; subr.el ends here
;;; Code:
(require 'ert)
+(require 'ert-x)
(eval-when-compile (require 'cl-lib))
(ert-deftest let-when-compile ()
(props-out (object-intervals out)))
(should (equal props-out props-in))))))))
+(ert-deftest subr-tests-internal--c-header-file-path ()
+ (should (seq-every-p #'stringp (internal--c-header-file-path)))
+ (should (member "/usr/include" (internal--c-header-file-path)))
+ (should (equal (internal--c-header-file-path)
+ (delete-dups (internal--c-header-file-path))))
+ ;; Return a meaningful result even if calling some compiler fails.
+ (cl-letf (((symbol-function 'call-process)
+ (lambda (_program &optional _infile _destination _display &rest _args) 1)))
+ (should (seq-every-p #'stringp (internal--c-header-file-path)))
+ (should (member "/usr/include" (internal--c-header-file-path)))
+ (should (equal (internal--c-header-file-path)
+ (delete-dups (internal--c-header-file-path))))))
+
+(ert-deftest subr-tests-internal--c-header-file-path/gcc-mocked ()
+ ;; Handle empty values of "gcc -print-multiarch".
+ (cl-letf (((symbol-function 'call-process)
+ (lambda (_program &optional _infile _destination _display &rest args)
+ (when (equal (car args) "-print-multiarch")
+ (insert "\n") 0))))
+ (should (member "/usr/include" (internal--c-header-file-path))))
+ ;; Handle single values of "gcc -print-multiarch".
+ (cl-letf (((symbol-function 'call-process)
+ (lambda (_program &optional _infile _destination _display &rest args)
+ (when (equal (car args) "-print-multiarch")
+ (insert "x86_64-linux-gnu\n") 0))))
+ (should (member "/usr/include/x86_64-linux-gnu" (internal--c-header-file-path)))))
+
(provide 'subr-tests)
;;; subr-tests.el ends here