Skip to content

Commit

Permalink
Instructions to run tests from the command line
Browse files Browse the repository at this point in the history
  • Loading branch information
glennj committed Oct 27, 2023
1 parent 12fd37c commit b103107
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions docs/TESTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,49 @@ As you make changes to the solution you are writing use your editor's functional

Remember to evaluate `(exercise-name-test:run-tests)` to re-run the tests after loading your updated solution.

## Testing from the command line

Executing the tests from the command line is possible, but it depends on which CL implementation you have chosen.
For example, with SBCL you could execute this in the directory for exercise "foo"

```sh
sbcl --noinform \
--load foo-test \
--eval '(exit :code (if (foo-test:run-tests) 0 1))'
```

Other CL implementations will have similar but slightly different command-line options and exit commands.

This assumes you have already installed SBCL and Quicklisp.
See [Installing Common Lisp locally](https://exercism.org/docs/tracks/common-lisp/installation)

~~~~exercism/note
That command can be made more convenient. The `exercism` CLI has been updated so that the command
```sh
exercism test
```
does "The Right Thing"™ to invoke the test suite for _most tracks_.
Unfortunately CL does not benefit because there is no single prescribed way to run the tests.
However, there are ways to wrap the exercism CLI to provide additional functionality, or override existing functionality.
If you use the bash shell, you can add the following to your `~/.bashrc` file.
It looks complicated but it just checks that you are in a directory for a CL exercise and invokes SBCL:
```sh
function exercism {
if [[ $1 == "test" && $PWD =~ "$(command exercism workspace)/common-lisp/"([^/]+) ]]
then
local exercise=${BASH_REMATCH[1]}
sbcl --noinform \
--load "${exercise}-test" \
--eval "(exit :code (if (${exercise}-test:run-tests) 0 1))"
else
command exercism "$@"
fi
}
```
With that, you can run `exercism test` to run the tests for your CL exercises.
~~~~

0 comments on commit b103107

Please sign in to comment.