Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instructions to run tests from the command line #758

Merged
merged 2 commits into from
Nov 1, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
glennj marked this conversation as resolved.
Show resolved Hide resolved
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
glennj marked this conversation as resolved.
Show resolved Hide resolved

```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.
~~~~