diff --git a/eldev-doctor.el b/eldev-doctor.el index f1e1415..1600b4e 100644 --- a/eldev-doctor.el +++ b/eldev-doctor.el @@ -344,4 +344,24 @@ Consider installing %s by running: (eldev-message-enumerate nil not-installed) (if (cddr not-installed) "them" "it"))) '(result t))))) +(eldev-defdoctest eldev-doctest-tar-windows (_results) + :caption "Is the tar executable found compatible with Eldev on MS-Windows?" + :categories (eldev package tar) + (let ((tar-exe (eldev-tar-executable 'not-required))) + (if (not tar-exe) + '(result nil warnings "Cannot find a `tar` executable in the `PATH` env variable, `package` commands are likely to fail. Please install a tar program in `PATH`.") + (if (eq system-type 'windows-nt) + (let ((temp-file (make-temp-file "eldev-doctor-tar-win"))) + (unwind-protect + ;; in absence of any test files, try to tar the tar + ;; executable itself. + (eldev-call-process tar-exe `("-cf" ,temp-file ,(expand-file-name (eldev-tar-executable))) + (when (/= exit-code 0) + `(result nil warnings ,(eldev-format-message "\ +The tar executable found at `%s` is not compatible with Eldev, please use the one provided with MS-Windows (typically located at `c:\\Windows\\system32\\tar.exe`), by either rearranging the entries in the PATH environment variable to pick that up first, or by setting the `eldev-tar-executable' in `Eldev-local` to something like + +(setf eldev-tar-executable \"C:/Windows/system32/tar.exe\")." tar-exe)))) + (delete-file temp-file))) + '(result t))))) + (provide 'eldev-doctor) diff --git a/test/doctor.el b/test/doctor.el index 7450189..d0b4a80 100644 --- a/test/doctor.el +++ b/test/doctor.el @@ -57,5 +57,19 @@ (should-not (string-match-p "eldev-presence" stdout)) (should (= exit-code 0)))) +(ert-deftest eldev-doctor-tar-win () + (eldev--test-run "trivial-project" ("doctor" "tar-windows") + (should (= exit-code 0))) + (when (eq system-type 'windows-nt) + (let* ((file (make-temp-file "doctor-" nil ".bat")) + (eldev-tar-executable file)) + (unwind-protect + ;; use a mock .bat file that will fail when run + (with-temp-file file + (insert "@echo off\nexit 1")) + (eldev--test-run "trivial-project" ("--setup" `(setf eldev-tar-executable ,file) "doctor" "tar-windows") + (should (string-match-p "The tar executable" stdout)) + (should (= exit-code 1))) + (delete-file file))))) (provide 'test/doctor)