all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* ERT: How to implement expensive initialization and cleanup?
@ 2023-06-04 20:04 Jens Schmidt
  2023-06-05 11:11 ` Eli Zaretskii
  0 siblings, 1 reply; 2+ messages in thread
From: Jens Schmidt @ 2023-06-04 20:04 UTC (permalink / raw)
  To: emacs-devel

Trying to write my first ERT test.  For the tests I need to set up a 
GnuPG home directory from scratch, including directory creation, key 
import, and key trust management.  Plus I need to clean up that mess 
after the tests have finished.  Takes some 2secs on my system with all 
that process communication between Emacs and GnuPG.

The cleanest solution would be to do that for every test, but that would 
get expensive if I go for many small tests, which seems to be better in 
terms of diagnosability.

So a one-time setup at the beginning of "all tests" and a one-time 
cleanup at the end of "all tests" would be what I need, independently of 
where "all tests" begin and end: It might be really all tests when I do 
a batch run or just one test when I execute `ert-run-tests-interactively'.

I thought about some `ert-setup-hook' and `ert-cleanup-hook' executed 
e.g. in `ert-run-tests', but I haven't found anything like that. 
Besides that, this works out only if you run tests from only one "test 
set" which all share the same setup and cleanup.

Lazy initialization would also work for this kind or problem, but how 
would I trigger "lazy cleanup", then?  Just leave (in my case) the 
temporary GnuPG home directory to be cleaned up by the OS?  Or at least 
clean it up at the end of the test file, which would cover the batch 
tests, but not single tests?

Anything else?

Thanks



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

* Re: ERT: How to implement expensive initialization and cleanup?
  2023-06-04 20:04 ERT: How to implement expensive initialization and cleanup? Jens Schmidt
@ 2023-06-05 11:11 ` Eli Zaretskii
  0 siblings, 0 replies; 2+ messages in thread
From: Eli Zaretskii @ 2023-06-05 11:11 UTC (permalink / raw)
  To: Jens Schmidt; +Cc: emacs-devel

> Date: Sun, 4 Jun 2023 22:04:23 +0200
> From: Jens Schmidt <jschmidt4gnu@vodafonemail.de>
> 
> Trying to write my first ERT test.  For the tests I need to set up a 
> GnuPG home directory from scratch, including directory creation, key 
> import, and key trust management.  Plus I need to clean up that mess 
> after the tests have finished.  Takes some 2secs on my system with all 
> that process communication between Emacs and GnuPG.

Are these test files constant, i.e. do you need to create the same
files time and again each time the test is run?  If so, perhaps take a
look at ert-resource-directory and its friends in ert-x.el.  You will
see in our test suite several examples of tests that use such constant
data.  Data that is the same in all tests is better made part of the
test suite, so it doesn't need to be generated as part of running the
test.

> The cleanest solution would be to do that for every test, but that would 
> get expensive if I go for many small tests, which seems to be better in 
> terms of diagnosability.

I wouldn't worry about performance too much in this case.  Don't
forget that an important feature of the test suite is to be able to
run each test in the FOO-tests.el file individually.  So you'll need
to allow per-test initialization anyway.



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

end of thread, other threads:[~2023-06-05 11:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-04 20:04 ERT: How to implement expensive initialization and cleanup? Jens Schmidt
2023-06-05 11:11 ` Eli Zaretskii

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.