2022 Developer Survey is open! Take survey.

Hot answers tagged

7 votes
Accepted

How do I temporarily mock a function for testing?

Both macros are lexically scoped, that's why they have no effect on the "distant" call. Either use the deprecated older flet or cl-letf. (cl-letf (((symbol-function 'return-number) (...
user avatar
  • 3,276
6 votes
Accepted

How can I test an idle timer with ERT?

Idle timers won't be touched until the call stack has been cleared, so sitting won't actually help, it is only once all execution has stopped with the timer be run, so in your case, the idle timer won'...
user avatar
5 votes

Debug pytests in emacs

I think that there are only the following solutions: Run tests outside of Emacs from your terminal emulator Run tests from realgud Run tests inside Emacs via eshell. But shell output may be corrupted,...
user avatar
4 votes

Pending test in Ert

It's not specifically for "pending", but marking the test as expected to fail seems like it would be what you want: http://www.gnu.org/software/emacs/manual/html_node/ert/Expected-Failures.html add ...
user avatar
  • 8,783
3 votes
Accepted

How to get current file name when running under ERT?

A wild guess: put the file name in a defvar or a defconst, and use it in the function: (defconst my-test-location (file-name-directory (or load-file-name buffer-file-name))) (ert-deftest closing-...
user avatar
  • 5,786
3 votes

How to automate user-testing with elisp?

I don't think there's a very satisfactory answer, but here's what I used today for testing the new undo-redo command I installed into master: (defun simple-tests--exec (cmds) (dolist (cmd cmds) ...
user avatar
  • 25.2k
3 votes
Accepted

How can I quickly switch between source namespace and test namespace?

Projectile provides a projectile-toggle-between-implementation-and-test function with exactly this behavior. As stated in the docs, you can use C-c p t to "Toggle between an implementation file and ...
user avatar
  • 429
3 votes

How can I quickly switch between source namespace and test namespace?

Outside of Cider, there is toggle-test, which can switch between source and test buffers in a language agnostic way.
user avatar
3 votes

projectile-rails: run the current test

Assuming rspec: Install rspec-mode, which will activate itself automatically in ruby-mode or enh-ruby-mode then you can use C-c,s to run rspec-verify-single which will run the test at point.
user avatar
2 votes
Accepted

Accessing resource files in ERT tests

When a file is loaded, load-file-name is set. When a form is evaluated interactively from a file, buffer-file-name is set. So you can use (or load-file-name buffer-file-name) as the value of a global ...
user avatar
2 votes

Running all tests in a leiningen project?

there is an option to run all the tests in all the projects namespaces M-x cider-test-run-project-tests or C-c C-t C-p Here is the link to additional options for running tests http://cider....
user avatar
2 votes

How can I skip a test if another test failed?

I have used something like this in vc-tests.el: (ert-deftest vc-test-git00-create-repo () "Check `vc-create-repo' for the git backend." ...) (ert-deftest vc-test-git01-register () "Check `vc-...
user avatar
2 votes
Accepted

Find corresponding test file

I recommend Projectile for this, and much more, project-related functionality. Projectile has a binding C-c p t (projectile-toggle-between-implementation-and-test) that offers exactly what you're ...
user avatar
2 votes

How to get current file name when running under ERT?

I've used the following construct: (defvar objc-font-lock-test-setup-directory (if load-file-name (file-name-directory load-file-name) default-directory)) It works both when the file is ...
user avatar
  • 5,735
2 votes
Accepted

Pending test in Ert

Placing a call to ert-skip at the beginning of your test would be the solution I believe. If you'd like, you can pass the string "pending" to the function to better show why it was skipped. (ert-...
user avatar
2 votes
Accepted

Why does running my tests with ert-run-tests-batch-and-exit fail

(void-function loop) loop is not available, which comes from cl.el. In your code/tests, you should load this library before using loop. When you launch Emacs interactively with your own init.el, it ...
user avatar
  • 13.5k
2 votes
Accepted

Org-babel: Notify if the result of execution differs from the previous recorded result

One idea might be to save a copy of the current buffer, run the tests, and then run a diff command on them. (defun run-tests () (interactive) (copy-to-buffer "*my-test*" (point-min) (...
user avatar
  • 10.9k
1 vote

unread-command-events and batch mode

This is expected behavior, but you can circumvent this problem by let-binding executing-kbd-macro to t, which will convince the minibuffer commands to read from unread-command-events rather than from ...
user avatar
  • 25.2k
1 vote

Enforce order of ERT tests?

As far as I could tell, it is not possible to cause the selectors t (universe) or :new to run tests in the order of definition. The (member TEST1 TEST2 ...) selector however executes tests in the ...
user avatar
  • 1,481
1 vote
Accepted

Testing Emacs Lisp Code Involving Org Mode

One way is by string comparisons, e.g. (require 'ert) (ert-deftest test-1 () (should (string= (with-temp-buffer (org-mode) (insert " * test heading ") (goto-char (point-...
user avatar
  • 10.9k
1 vote

Compile-run-navigate traceback without term mode

Traceback highlighting is provided by the compile package. You can use M-x compile to run a script and get traceback highlighting. If you have an existing buffer with a traceback, you can use M-x ...
user avatar
1 vote

How can I skip a test if another test failed?

Maybe something like this: (defun func-one () (message "running: func-one") nil) (defun func-two () (message "running: func-two") (and (func-one) t)) (defun func-thr () (message "running: ...
user avatar
  • 13.6k
1 vote
Accepted

projectile-rails: run the current test

This way it works: (defun get-current-test-name () (save-excursion (let ((pos) (test-name)) (re-search-backward "test \"\\([^\"]+\\)\" do") (setq test-name (buffer-...
user avatar
  • 447
1 vote
Accepted

Running all tests in a leiningen project?

Unfortunately there is not a way to do this currently in cider. One would have to write a custom command to evaluate clojure.tests/run-all-tests (or clojure.tests/run-tests with a list of namespaces ...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible