3

I'm looking for an emacs package that can continuously run my unit tests. As I make changes, I'd like to be alerted as soon as a test fails. Preferably, a package that is language agnostic would be great (this is a C++ project). In my case, running the tests is all command-line driven.

Does such a package exist?

3
  • Why do you want to run it in Emacs? (As opposed to running Jenkins / Travis etc and using some notification mechanism).
    – wvxvw
    Apr 13 '15 at 18:48
  • I'll update my question with more explanation. I'd like to have a buffer with the results so I don't have to leave emacs. Also, hooking into when emacs saves a file to trigger a rebuild is useful.
    – David
    Apr 13 '15 at 19:24
  • I'm asking because Jenkins has tolerable interface, if you want to use it from eww. At least for browsing, it's OK. You could probably set SCM in Jenkins to look for changes in a directory so it would start up after you build and then just refresh the eww buffer to see the results (well, in a few minutes).
    – wvxvw
    Apr 13 '15 at 19:34
5

You can with the package auto-recompile. I took it from here and fixed a bug to make it compatible with latest Emacs. To use it:

  • First load the package in your Emacs (I assume you know how to do this).
  • Then, M-x auto-recompile. After that, it displays a message Auto-recompile mode is on.
  • Next, M-x compile and run your test command.
  • Now, everytime you save, the compile command (which is the test command you've just executed) runs automatically and display in *compilation* buffer.

You should bind a key to auto-recompile to toggle it on/off when needed, since it's annoying when enabled globally because the recompile is triggered in unrelated modes.

You can combine it with auto-save-mode to achieve what you want: periodically see test results by periodically save your current buffer and in turn, invoke auto-recompile (the function is taken from here):

(defun save-buffer-if-visiting-file (&optional args)
  "Save the current buffer only if it is visiting a file"
  (interactive)
  (if (and (buffer-file-name) (buffer-modified-p))
      (save-buffer args)))

(add-hook 'prog-mode-hook 'auto-save-mode)
(add-hook 'auto-save-hook 'save-buffer-if-visiting-file)
(setq auto-save-timeout 10)             ; auto save every 10 seconds
(setq auto-save-interval 100)           ; auto save every 100 input events
2

I happen to have written a generic package for doing things on save, such as running (shell) commands not too long ago.

It supports shell commands, interactive commands and generic Emacs Lisp code. When using shell commands, you get a reporting buffer containing output of the entire history and can configure on which condition it should pop up (like for example, only when the command failed with a non-zero status code). Finally, it supports format codes in the commands which are tremendously useful for calls that need to know the current file it's running upon or parts of it. Since it uses a customizable buffer-local variable to determine how to do its job, you can customize it globally, per mode, per directory, per file or even just interactively, unlike things like M-x compile where you start with a default and need to change it for every "project" for each new Emacs session.

I believe it to be the simplest solution for a workflow approximating full CI solutions. If there's anything obvious missing from it, feel free to open an issue on its bug tracker.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.