all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* To factorize code of test sets (or not)
@ 2025-01-08  8:45 Phil Estival
  2025-01-09 17:17 ` Ihor Radchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Phil Estival @ 2025-01-08  8:45 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Org Mode List


* [2025-01-07 19:38] Ihor Radchenko:> Phil Estival <pe@7d.nz> writes:
>
>> [...]
>> Some macros [for test suite] should probably be moved upward
>> in a file where generic functions which purposes are to help
>> writing the tests of babel source blocks should be declared.
>>
>
> I do not mind.
> But please show which _other_ tests can benefit from the simplification.

This may appear as an unnecessary effort to refactor, or worse,
normalize a code that can benefit from some diversity
yet,
the forms

   (should
    (equal "<str result>"
      (org-test-with-temp-text "<block>"
      (org-babel-next-src-block)
      (org-trim (org-babel-execute-src-block))))))

or

(org-test-with-temp-text "<block>"
     (org-babel-next-src-block)
     (should (equal '(<something>) ;; or (should (string= "<str>
        (org-babel-execute-src-block))))
;; or org-babel-execute-maybe for ruby and elisp

exist in
test-ob-[maxima,R,sqlite,sed,shell,plantuml,lua,java,julia,lob,octave,perl,python,emacs-lisp].el

Considering it at the repetitive pattern, I think a macro can shorten
those forms to :

(ob-test  "<preamble + block>"
   :expect  "<expected-result>")

and a variant to test or exclude matching regexp

(ob-test  "<preamble+block>"
   :expect-to-match  "<expected regexp to match>")

(ob-test  "<preamble+block>"
   :expect-to-not-match  "<expected-regexp to not match>")

IMHO, they would be easier to read with one additional line feed

   (ob-test  "
#+begin_src ...

#+end_src"
             :expect  "<expected-result>")

rather than

    (ob-test  "#+begin_src ...

#+end_src"
              :expect  "<expected-result>")

Similar macro/function exists in
ob-emacs-lisp/dynamic-lexical-execute
or ob-sql/command-should-contain.

my 2¢,
Phil


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: To factorize code of test sets (or not)
  2025-01-08  8:45 To factorize code of test sets (or not) Phil Estival
@ 2025-01-09 17:17 ` Ihor Radchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Ihor Radchenko @ 2025-01-09 17:17 UTC (permalink / raw)
  To: Phil Estival; +Cc: Org Mode List

Phil Estival <pe@7d.nz> writes:

> This may appear as an unnecessary effort to refactor, or worse,
> normalize a code that can benefit from some diversity
> yet,
> the forms
>
>    (should
>     (equal "<str result>"
>       (org-test-with-temp-text "<block>"
>       (org-babel-next-src-block)
>       (org-trim (org-babel-execute-src-block))))))
> ...
> exist in
> test-ob-[maxima,R,sqlite,sed,shell,plantuml,lua,java,julia,lob,octave,perl,python,emacs-lisp].el
>
> Considering it at the repetitive pattern, I think a macro can shorten
> those forms to :
>
> (ob-test  "<preamble + block>"
>    :expect  "<expected-result>")
> ...
> (ob-test  "<preamble+block>"
>    :expect-to-match  "<expected regexp to match>")

Looks reasonable.
Although, :expect/:expect-*-to-* are probably redundant.
We may instead use some kind of anamorphic form like:

(ob-with-src-block-result "...."
 (should (equal it "expected"))
 (should (string-match-p "expected-re" it))
 (should-not ...)
 ...)

-- 
Ihor Radchenko // yantar92,
Org mode maintainer,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-01-09 17:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-08  8:45 To factorize code of test sets (or not) Phil Estival
2025-01-09 17:17 ` Ihor Radchenko

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.