emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ert buffer isolation


From: Michael Albinus
Subject: Re: ert buffer isolation
Date: Mon, 27 Jan 2025 11:00:31 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Daniil Iaitskov <dyaitskov@gmail.com> writes:

Hi Daniil,

> Emacs predates unit tests practices, but the system should follow
> trends in the industry. 
>
> I anticipate that tests in Emacs might interfere other ways, but I did
> have a chance and I don't have the context to write shim covering
> these cases.
>
> I found an article by Kent Beck
> (https://en.wikipedia.org/wiki/Kent_Beck), who wrote a few popular
> books about testing software.
>
> https://tidyfirst.substack.com/p/desirable-unit-tests
>
> First 2 bullets on the list:
>
>     * Isolated — Unit tests are completely isolated from each other,
>           creating their own test fixtures from scratch each time.
>           (Note that I’m not saying these are the only useful tests,
>           just that if tests aren’t isolated you’re going to have a
>           hard time making the case that they are “unit tests”.)
>
>         * Composable — Follows from isolation.

I agree with the statements. However, ert-deftest does not handle all
the cleanup cases. Instead it is designed to add helper macros (in
ert-x.el), or force the test originator to apply a manual cleanup.

> I published ert-scope (https://github.com/yaitskov/ert-scope) package
> with a shim to handle scope issue for buffers and files in sync and
> async tests.
>
>     (require 'ert)
>         (require 'ert-scope)
>
>         (ert-deftest sync-test ()
>           (ert-scope-with-temp-dir
>             (ert-scope-buffers
>               (should-not (get-buffer "foo.txt"))
>               (find-file "foo.txt")
>               (should (= 1 (point-max)))
>               (insert "foo")
>               (save-buffer))))

Nice. However, have you checked it against ert-x.el? I have the feeling
that there are overlapping functionalities. Something like
ert-with-temp-directory or ert-with-test-buffer. ert-with-temp-file
handles the case of temporary files.

However, ert-x.el is kind of a hidden treasure. We need better
documentation in the manual, and we need to add missing functionality
(like handling of temporary processes).

Best regards, Michael.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]