Skip to content

Commit

Permalink
Use tuple instead of raw data
Browse files Browse the repository at this point in the history
  • Loading branch information
ROCKTAKEY committed Jul 9, 2023
1 parent d12f9ef commit 2adb5e7
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions keg-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ REGEXP defaults to \"[ \\t\\n\\r]+\"."
string)))
(if i (substring string 0 i) string)))

(defun shell-command-return-tuple (command)
"Run COMMAND and return (EXITCODE STDOUT STDERR)."
(with-temp-buffer
(let ((stdout (current-buffer)))
(with-temp-buffer
(let ((stderr (current-buffer)))
(list (shell-command command stdout stderr)
(with-current-buffer stdout (buffer-substring-no-properties (point-min) (point-max)))
(with-current-buffer stderr (buffer-substring-no-properties (point-min) (point-max)))))))))

(cl-defmacro cort-deftest-with-shell-command (name form &key working-directory)
"Return `cort-deftest' compare with `string=' for NAME, FORM.
If WORKING-DIRECTORY is non-nil, it should be string which specifies directory,
Expand Down Expand Up @@ -64,12 +74,7 @@ where the shell command will run.
`(:string-match-p
,regexp
(keg-tests--string-trim-right
(let ((default-directory
,(if working-directory
(expand-file-name working-directory
(file-name-directory load-file-name))
(file-name-directory load-file-name))))
(shell-command-to-string ,(car elm))))))
(nth 1 (shell-command-return-tuple ,(car elm))))))
(cdr elm)))
(cadr form)))))

Expand All @@ -88,16 +93,12 @@ where the shell command will run.
'((:car-equal
(let ((command (expand-file-name "bin/keg"))
(default-directory (expand-file-name "./test-data")))
(with-temp-buffer
(list
(shell-command
(mapconcat #'shell-quote-argument
(list command
"version")
" ")
nil (current-buffer))
(buffer-substring-no-properties (point-min) (point-max)))))
'(0 ""))))
(shell-command-return-tuple
(mapconcat #'shell-quote-argument
(list command
"version")
" ")))
'(0 "" ""))))


;;; "keg help"
Expand Down

0 comments on commit 2adb5e7

Please sign in to comment.