I've noticed that ERT tests (ert-run-tests-batch-and-exit) in Emacs are executed by name (I mean order).
Can I somehow execute tests in the order I define them?
For example:
(ert-deftest test-2 ...
(ert-deftest test-1 ...
will execute first "test-2", then "test-1".
PS: I know that tests should not rely on the order but still want it.
As far as I know you can't tell ERT to execute tests in the order in which they are defined. You can, however, specify the order in which you would like your tests to be executed manually, by passing an appropriate SELECTOR argument to ERT's functions for running tests. You can try this out interactively by doing:
M-x ert RET (member test-2 test-1) RET
You might want to make test-2 and test-1 fail temporarily so you can verify that ERT runs them in the order you specified.
Now, based on the fact that you mentioned ert-run-tests-batch-and-exit in your question I am assuming you want to run tests from the command line. The following command will do what you want (where <test-file> is the name of the file containing your tests):
emacs -batch -l ert -l <test-file> --eval "(ert-run-tests-batch-and-exit '(member test-2 test-1))"
Bonus
If you want to avoid having to specify the order in which you want your tests to run every time you execute this command, you can add the following to your <test-file>:
(defvar test-order '(member test-2 test-1))
With this in place you can run your tests from the command line via:
emacs -batch -l ert -l <test-file> --eval "(ert-run-tests-batch-and-exit test-order)"
Related
The shell command
emacsclient -n -e '(make-remember-frame)'
works.
But the applescript
do shell script "emacsclient -n -e '(make-remember-frame)'"
just returns
emacsclient: can't find socket; have you started the server?
To start the server in Emacs, type \"M-x server-start\".
emacsclient: No socket or alternate editor. Please use:
--socket-name
--server-file (or environment variable EMACS_SERVER_FILE)
--alternate-editor (or environment variable ALTERNATE_EDITOR)
I rarely use this, but it has worked successfully in the past for various purposes. Perhaps you can modify it to suit your needs. The init.el or .emacs file must have (server-start) inside in order to make everything work. I have lots of stuff that loads when Emacs is activated for the first time, so I need a 5 second delay before emacsclient is called -- you can adjust the delay downward if your Emacs loads faster. If Emacs is already running, there is no need for a delay. You can comment out the verbal messages generated by say -- I used them this morning to test the conditions and make a minor adjustment to the script. The script contains a command-line example on line 4, which calls two Emacs functions. Of course, the path to your Emacs and emacsclient will need to be adjusted to wherever you have installed them on your computer.
# `(server-start)` must be inside `init.el` or `.emacs` file.
# This script can be used in the terimal: osascript path-to-script arguments
# Terminal Example:
# osascript /Users/HOME/.0.data/.0.emacs/.emacsclient.applescript "-e '(progn (dired \"/Applications\") (message \"Hello-World\!\"))'"
on run argv
set arg to item 1 of argv
set emacs to application "Emacs"
set appIsRunning to emacs is running
if appIsRunning then
say "Emacs is already running."
do shell script "/Users/HOME/.0.data/.0.emacs/Emacs_06_01_2014.app/Contents/MacOS/bin/emacsclient " & arg
else
tell application "/Users/HOME/.0.data/.0.emacs/Emacs_06_01_2014.app/Contents/MacOS/Emacs" to activate
say "Please wait five seconds for Emacs to load."
delay 5
do shell script "/Users/HOME/.0.data/.0.emacs/Emacs_06_01_2014.app/Contents/MacOS/bin/emacsclient " & arg
end if
end run
I have a project that uses a bash script to invoke cmake and make. I have successfully used this script from Emacs by using M-x compile, followed by typing:
cd ../..; ./build.sh
in the minibuffer. (The project organization is top/src/various_source_folders and build.sh is in top/.)
I am trying to define a directory variable to specify the default command to use for compile. I have tried the following (both with single or double quotes around the compile command) in .dir-locals.el:
((c++-mode
(compile-command 'cd ../..\; ./build.sh')))
Which gives no errors, but M-x compile still defaults to make -k.
((c++-mode
(set-variable 'compile-command' "cd ../../\; ./build.sh")))
Which gives a warning about unsafe variables. Even if I choose apply, compile still defaults to make -k
Simply using M-x eval-buffer with the second line ((set variable...) in *scratch* correctly sets the compile command.
Is there a different way I can/should be doing this?
Found an answer here.
Two periods and some parenthesis were missing from the syntax:
((c++-mode
. ((compile-command . "cd ../../\; ./build.sh"))))
I've seen this question but it doesn't seem to apply here.
Using SBCL, this works fine:
(run-program "/bin/ls" () :output *standard-output*)
So does this:
(run-program "/Applications/Safari.app/Contents/MacOS/Safari" ())
It launches a Safari window.
I can create a bash script in my bin directory that just has this in it:
/Applications/Safari.app/Contents/MacOS/Safari
When I run this bash script from the Terminal, Safari opens.
But I cannot run this script from inside SBCL:
(run-program "/Users/myhome/bin/safariscript" ())
REPL reports:
Couldn't execute "/Users/myhome/bin/safariscript": Exec format error
[Condition of type SIMPLE-ERROR]
The script certainly works fine on its own. I've searched ad nauseum for the meaning of this error without any help that would apply to a lisp environment, so I wonder if there is a broader issue at play here?
Shell scripts need a shell-bang line in it in order to be run via execve or anything that uses it, such as run-program. So you should use this as your file's content:
#!/bin/sh
exec /Applications/Safari.app/Contents/MacOS/Safari
Is it possible to integrate Cppcheck with Emacs in a more sophisticated way than simply calling the shell command on the current buffer? I would like Emacs to be able to parse Cppcheck's messages and treat them as messages from a compiler (similar to how compile works), such as using C-x ` to visit the targets of Cppcheck's messages.
Here is some example output Cppcheck:
$ cppcheck --enable=all test.cpp
Checking test.cpp...
[test.cpp:4]: (error) Possible null pointer dereference: p - otherwise it is redundant to check if p is null at line 5
[test.cpp:38]: (style) The scope of the variable 'i' can be reduced
[test.cpp:38]: (style) Variable 'i' is assigned a value that is never used
[test.cpp:23]: (error) Possible null pointer dereference: p
[test.cpp:33]: (error) Possible null pointer dereference: p
Checking usage of global functions..
[test.cpp:36]: (style) The function 'f' is never used
[test.cpp:1]: (style) The function 'f1' is never used
[test.cpp:9]: (style) The function 'f2' is never used
[test.cpp:26]: (style) The function 'f3' is never used
Hmmm... I think this is really simple actually. Just use 'compile', as in M-x compile, and type as the compile command:
cppcheck --template='{file}:{line}:{severity}:{message}' --quiet <filename>
Where the filename is the name of the file on which you wish to run cppcheck. That puts the output of cppcheck into a form that the compilation buffer can parse and gives you the full functionality you get with, for instance, a g++ compile.
The --quiet is probably not necessary but since all I care about are the errors that's what I use.
You can use flymake which ships with Emacs.
The basic idea is to write a flymake command that runs cppcheck and then massages the output into a format the flymake can use. If you then enable flymake in your c++ mode buffers, you'll get on the fly error highlighting.
This is an example of flymake working with my Python buffers using pyflakes.
flymake in general expects output in this form
filename:line_number: class: message
Where filename is the name of the file, number is the line number, class is a string like error or warning indicating the type of message and message is a string indicating the actual error. cppcheck output looks close to this. You should probably write a little wrapper to convert the output of cppcheck to this format and then add a hook to turn on flymake for c++ mode.
With C, adding something like gcc -Wall -o nul -S ${CHK_SOURCES} to your Makefile with under a target check-syntax and running flymake-mode does what's necessary. I think it'll be similar for c++ mode.
For the gory details, you should check out http://flymake.sourceforge.net/
Is it possible to integrate Cppcheck with Emacs in a more sophisticated way
Yes, it is possible. Use flymake. I'm surprised no one has done this yet for cppcheck.
No problem, you can do it yourself. Add cppcheck as a new flavor of flymake tool. To do that, follow an existing example. It's not too complicated to do, but coming in cold, it's hard to know what to do. (I've never seen a guide document that describes how to integrate new tools into flymake). Following an existing working example solves that.
Here's a 7k file that adds PHP CodeSniffer as a flymake tool. http://www.emacswiki.org/emacs/flyphpcs.el
Most of that 7k is comments...
You should be able to modify that to add any arbitrary tool to flymake. The key steps are:
Associate your target file extension (example: .cpp) with a pair of functions (init and cleanup) that do your flymake stuff.
define a function to generate the command line, each time flymake scans your buffer. Ths fn gets the name of the file backing the buffer, and produces a command line. In your case it would run cppcheck with all the appropriate command line parameters. The fn that generates the command line is called by the init fn referenced in #1.
define a regex that matches error messages generated by your tool, and add that regex to the flymake list. This allows flymake to extract error messages from the output of the tool you run. By parsing the output, flymake can get the line numbers and highlight broken lines in your buffer.
based on the answers, flymake sounds good.
you can write a cppcheck parser but it sounds easier to use cppcheck --template option.
cppcheck --template="{file}:{line}:{severity}:{message}" foo.cpp
might match flymake pattern. It is just an idea.
The quickest way is probably to use flymake and add an extra target to your makefile.
This setup is working for me:
check-syntax: cppcheck
g++ -o nul -S ${CHK_SOURCES} $(CFLAGS)
cppcheck:
cppcheck --enable=all --quiet --template={file}:{line}:{severity}:{message} ${CHK_SOURCES}
I tried the following:
$ cat args.sh
\#! /Applications/ccl/dx86cl64
(format t "~&~S~&" *args*)
$ ./args.sh
Couldn't load lisp heap image from ./args.sh
I can run lisp fine directly:
$ /Applications/ccl/dx86cl64
Welcome to Clozure Common Lisp Version 1.5-r13651 (DarwinX8664)!
?
Is it possible to write a shell script to run lisp code with Clozure CL? I am sure I am doing something silly.
I installed it from: http://openmcl.clozure.com/
Just following up on Charlie Martin's answer and on your subsequent question. The dx86cl64 --eval <code> will fire up a REPL, so if you want to fire up a given script then quit, just add this to the end of your script: (ccl::quit). In the example you provided, this would do the trick:
#! /bin/bash
exec /Applications/ccl/dx86cl64 --eval '(progn (format t "hello script") (ccl::quit))'
A nicer script would be the following:
#! /bin/bash
exec /Applications/ccl/dx86cl64 -b -e '(progn (load "'$1'") (ccl::quit))'
Put that into a file, load-ccl-script.sh (or other name of your choice). Then the following interaction works:
$ echo '(format t "weeee!")' > a.lisp
$ sh load-ccl-script.sh a.lisp
weeee!
$ _
The issue is in your shebang line:
\#! /Applications/ccl/dx86cl64
In a UNIX file, the first 16 bits is called the "magic number". It happens that the magic number for an executable script is the same bit configuration as the characters "#!". The first 16 bits of your file have the same configuration as "\#", and UNIX won't buy that.
It is possible to add magic numbers, but it isn't easy or portable, so what you need is a way to invoke the script. I'd suggest
#! /bin/bash
exec /Applications/ccl/dx86cl64
with appropriate arguments etc for your script. (The exec builtin causes the current process to be loaded with the named executable without forking, so you don't have a spare process lying about.)
Update
In your particular case, you'll want something like
#! /bin/bash
exec /Applications/ccl/dx86cl64 --eval '(format t "~&~S~&" *args*)'
See the command line args for Clozure for why.
You have to make sure, that the kernel can load a Lisp memory image. The default behaviour is for the kernel to look for a file, which is named like the kernel binary with ".image" appended, i.e., if you start CCL using dx86cl64, then the image loaded is dx86cl64.image from the same directory. You can modify this behaviour by supplying the image explictely using the --image option. Try dx86cl64 --help for more information.
See the scripts subdirectory of your ccl directory. It should have some scripts you can adapt and use.
You cannot call the script like this from the command line:
/Applications/ccl/dx86cl64 myscript
can you?
I think that you need to call it like this (I don't have Clozure CL here, so I can't test):
/Applications/ccl/dx86cl64 -b -l myscript
So, your script should start like this:
#!/Applications/ccl/dx86cl64 -b -l
...