# Info.rkt: whitelisting test files for raco test

**URL:** <https://racket.discourse.group/t/info-rkt-whitelisting-test-files-for-raco-test/1059>\
**Category:** Questions & Answers\
**Created:** [June 5, 2022, 5:38am UTC](https://racket.discourse.group/t/info-rkt-whitelisting-test-files-for-raco-test/1059 "2022-06-05T05:38:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![undltd](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/undltd/32/571_2.png) [@undltd](https://racket.discourse.group/u/undltd)\
**Post date:** [June 5, 2022, 5:38am UTC](https://racket.discourse.group/t/info-rkt-whitelisting-test-files-for-raco-test/1059/1 "2022-06-05T05:38:21Z")

</div>

I'd like to have `raco test .` only test specific file(s) in my package. Listing the files in `test-include-paths` in `info.rkt` doesn't seem to have the desired effect: `raco test .` runs all `.rkt` in the current directory (including even `info.rkt`), not just the ones listed in `test-include-paths`. Adding `(define test-omit-paths 'all)` simply skips all files, including the ones listed in `test-include-paths` (i.e. it seems to have priority over `test-include-paths`).

Is there no (simple) way to do test file whitelisting?

---

<div class="post-metadata">

**Author:** ![sorawee](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@sorawee](https://racket.discourse.group/u/sorawee)\
**Post date:** [June 5, 2022, 5:56am UTC](https://racket.discourse.group/t/info-rkt-whitelisting-test-files-for-raco-test/1059/2 "2022-06-05T05:56:44Z")

</div>

[https://github.com/racket/racket/issues/4168](https://github.com/racket/racket/issues/4168) seems very relevant to your question.

My understanding based on the issue is that:

1. `test-include-paths` is really about including non-Racket files. So it has no effect when using on Racket files (which are already included).
2. There is no good way to do what you want. You can use `test-omit-paths` with ugly zero-width assertion regex, as demonstrated in the issue, to include files that you want, but that is obviously not ideal.

---

<div class="post-metadata">

**Author:** ![undltd](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/undltd/32/571_2.png) [@undltd](https://racket.discourse.group/u/undltd)\
**Post date:** [June 5, 2022, 7:06am UTC](https://racket.discourse.group/t/info-rkt-whitelisting-test-files-for-raco-test/1059/3 "2022-06-05T07:06:27Z")

</div>

Thanks, subscribed to [the issue](https://github.com/racket/racket/issues/4168).

---

<div class="post-metadata">

**Author:** ![alexh](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/alexh/32/315_2.png) [@alexh](https://racket.discourse.group/u/alexh)\
**Post date:** [June 5, 2022, 7:32am UTC](https://racket.discourse.group/t/info-rkt-whitelisting-test-files-for-raco-test/1059/4 "2022-06-05T07:32:53Z")

</div>

> [@undltd](#):
>
> Is there no (simple) way to do test file whitelisting?

You might want to try the following (no changes are required to the info.rkt file):

- run the tests using `raco test --no-run-if-absent .` This will make raco run tests only in files which have a test submodule.
- additionally, for files that you don't want to be tested, add the following line somewhere in the file `(module+ test racket/base)`. This is usually not needed, but might make the test run a bit faster.

Hope this helps,  
Alex.

---

<div class="post-metadata">

**Author:** ![greghendershott](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/greghendershott/32/98_2.png) [@greghendershott](https://racket.discourse.group/u/greghendershott)\
**Post date:** [June 5, 2022, 2:11pm UTC](https://racket.discourse.group/t/info-rkt-whitelisting-test-files-for-raco-test/1059/5 "2022-06-05T14:11:11Z")

</div>

Maybe the first paragraph of [Test Configuration by "info.rkt"](https://docs.racket-lang.org/raco/test.html#%28part._test-config-info%29) should be highlighted --- because I seem to recall overlooking it when learning about options like `test-omit-paths`:

> Submodule-based test configuration is preferred (see [Test Configuration by Submodule](https://docs.racket-lang.org/raco/test.html#%28part._test-config%29)). In particular, to prevent raco test from running a particular file, normally the file should contain a submodule that takes no action.

So I think the preferred approach is (as @alexh said) always include a `test` submodule. If you want to test nothing in some file, have it do nothing in that file.

This will work even when you don't always control running `raco test`, like when you publish a package, and the tests are run by the Racket build server.

When you _can_ directly run `raco test`, there are many interesting options.

- One is what @alexh said, `--no-run-if-absent`.
- Also, you can have it run submodules of a certain name. e.g. `test-slow` with thorough tests that take a very long time to run, as a supplement to your plain `test` submodules. Or `benchmarks`, or whatever.

* * *

After that first paragraph, the section goes on to talk about the options like `test-omit-paths`, as the "non-preferred but maybe necessary" approach:

> In some cases, however, adding a submodule is inconvenient or impossible (e.g., because the file will not always compile). Thus, raco test also consults any "info.rkt" file in the candidate test file’s directory. In the case of a file within a collection, "info.rkt" files from any enclosing collection directories are also consulted for test-omit-paths and test-include-paths. ...

That doesn't mean that a more `.gitignore` flavor of specifying includes/excludes wouldn't be better. But it might explain why there hasn't been work put into that, since it's not the recommended approach?

---

<div class="post-metadata">

**Author:** ![sorawee](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@sorawee](https://racket.discourse.group/u/sorawee)\
**Post date:** [June 5, 2022, 2:37pm UTC](https://racket.discourse.group/t/info-rkt-whitelisting-test-files-for-raco-test/1059/6 "2022-06-05T14:37:44Z")

</div>

From my understanding, one issue with `no-run-if-absent` is that environments  
like DrDr / [https://pkgs.racket-lang.org](https://pkgs.racket-lang.org) won’t use the flag, so if you want  
your tests to pass in these environments, it’s not really an option.

(edited: I have no idea why the first line was omitted.... It was there in my gmail...)

---

<div class="post-metadata">

**Author:** ![undltd](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/undltd/32/571_2.png) [@undltd](https://racket.discourse.group/u/undltd)\
**Post date:** [June 5, 2022, 4:39pm UTC](https://racket.discourse.group/t/info-rkt-whitelisting-test-files-for-raco-test/1059/7 "2022-06-05T16:39:18Z")

</div>

> [@greghendershott](#):
>
> Maybe the first paragraph of [Test Configuration by "info.rkt"](https://docs.racket-lang.org/raco/test.html#%28part._test-config-info%29) should be highlighted --- because I seem to recall overlooking it when learning about options like `test-omit-paths`:
> 
> > Submodule-based test configuration is preferred (see [Test Configuration by Submodule](https://docs.racket-lang.org/raco/test.html#%28part._test-config%29)). In particular, to prevent raco test from running a particular file, normally the file should contain a submodule that takes no action.
> 
> So I think the preferred approach is (as @alexh said) always include a `test` submodule. If you want to test nothing in some file, have it do nothing in that file.

Thanks, I overlooked that too, going to keep that in mind as an option. In general though, to be honest, I'm hesitant adding empty test modules. It feels like I'm doing something for the machines rather than the humans reading the code. I.e., adding workaround noise saying something like _"Oh and by the way, there are no tests in this file, obviously!"_

Also, at least in my environment, `raco test` reports running `info.rkt` as well, and adding a test submodule there seems especially weird. So I added `info.rkt` to `test-omit-paths`.

(Actually that behavior was what initially prompted my desire to limit what's being tested).
