Update tests to fix failures from formatter definition changes

This commit is contained in:
Mohsin Kaleem 2023-03-12 10:45:14 +00:00
parent ceaddebf39
commit e2062d612d
9 changed files with 53 additions and 76 deletions

View file

@ -226,8 +226,12 @@ environment variable, defaulting to all formatters."
(let ((load-suffixes '(".el"))) (let ((load-suffixes '(".el")))
(locate-library "apheleia")))))) (locate-library "apheleia"))))))
exec-path))) exec-path)))
;; Some formatters use the current file-name or buffer-name to interpret the
;; type of file that is being formatted. Some may not be able to determine
;; this from the contents of the file so we set this to force it.
(rename-buffer in-file)
(setq stdout-buffer (get-buffer-create (setq stdout-buffer (get-buffer-create
(format "*apheleia-ft-stdout-%S" formatter))) (format "*apheleia-ft-stdout-%S%s" formatter extension)))
(with-current-buffer stdout-buffer (with-current-buffer stdout-buffer
(erase-buffer)) (erase-buffer))
(if (functionp command) (if (functionp command)
@ -243,41 +247,14 @@ environment variable, defaulting to all formatters."
(copy-to-buffer stdout-buffer (point-min) (point-max)))) (copy-to-buffer stdout-buffer (point-min) (point-max))))
(progn (progn
(let ((result (apheleia--format-command command nil nil)))
(setq command (nthcdr 3 result)
in-temp-real-file (nth 0 result)
out-temp-file (nth 1 result)))
(with-current-buffer stdout-buffer (with-current-buffer stdout-buffer
(erase-buffer)) (erase-buffer))
(mapc
(lambda (arg)
(when (memq arg '(file filepath input output inplace))
(cl-pushnew arg syms)))
command)
(when (or (memq 'file syms) (memq 'filepath syms))
(setq in-temp-real-file (apheleia-ft--write-temp-file
in-text extension)))
(when (or (memq 'input syms) (memq 'inplace syms))
(setq in-temp-file (apheleia-ft--write-temp-file
in-text extension))
(when (memq 'inplace syms)
(setq out-temp-file in-temp-file)))
(when (memq 'output syms)
(setq out-temp-file (apheleia-ft--write-temp-file
"" extension)))
(setq command (delq 'npx command))
(setq command
(mapcar
(lambda (arg)
(pcase arg
((or `file `filepath)
in-temp-real-file)
((or `input `inplace)
in-temp-file)
(`output
out-temp-file)
((guard (stringp arg))
arg)
(_ (eval arg))))
command))
(setq stdout-buffer (get-buffer-create
(format "*apheleia-ft-stdout-%S" formatter)))
(setq exit-status (setq exit-status
(apply (apply
#'call-process #'call-process