jakemcc / test-refresh

Refreshes and reruns clojure.tests in your project.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it possible to place test files and source files under a single root directory?

cloojure opened this issue · comments

Use the template below when reporting bugs. Please make sure the
problem is still a problem with the latest version of
lein-test-refresh before submitting.

What version of lein-test-refresh?
0.25.0

What version of Leiningen?
n/a: running deps/cli

Can you recreate the issue with a minimal project?
Please see: https://github.com/io-tupelo/clj-template-deps-dbg

I like to name my testing namespaces like tst.demo.core instead of demo.core-test. It avoids whole hyphen vs. underscore debacle, and it keeps the filename like **/demo/core.clj for both the source file and the test file. There are other stylistic benefits as well IMHO.

Given this, there is little rational for keeping separate ./src and ./test directories in a project root. I would like to experiment keeping both types of source files under a single ./src root such as:

-rw------- 1 alan alan  357 Mar  8  2022 src/clj/demo/core.clj
-rw------- 1 alan alan  144 Jan 19 23:32 src/clj/tst/demo/core.clj
-rw------- 1 alan alan   86 Jan 21 15:34 src/clj/tst/demo/other.clj

I got this to work with the Cognitect test runner:

~/io-tupelo/clj-template-deps-dbg > ct
time (clojure -X:test)

Running tests in #{"src/clj"}

Testing tst.demo.core

Testing tst.demo.other

Ran 2 tests containing 2 assertions.
0 failures, 0 errors.
  29.28s user 0.64s system 396% cpu 7.536 total

However, I cannot figure out a way to make it work with test-refresh:

~/io-tupelo/clj-template-deps-dbg > ctr
time (clojure -M:test-refresh)
*********************************************
*************** Running tests ***************
:reloading (_bootstrap tst.demo.other demo.core tst.demo.core)

Testing user

Ran 0 tests containing 0 assertions.
0 failures, 0 errors.

Passed all tests
Finished at 16:02:07.171 (run time: 5.431s)
^C  28.28s user 0.58s system 301% cpu 9.572 total

However, it works great if I keep the testing code under the ./test root. See https://github.com/io-tupelo/clj-template-deps for example:

~/io-tupelo/clj-template-deps > ctr
time (clojure -M:test-refresh)
*********************************************
*************** Running tests ***************
:reloading (_bootstrap tst.demo.other demo.core tst.demo.core)

Testing _bootstrap

-------------------------------
   Clojure 1.11.1    Java 17
-------------------------------

Testing tst.demo.core

Testing tst.demo.other

Ran 3 tests containing 2 assertions.
0 failures, 0 errors.

Passed all tests
Finished at 16:03:48.481 (run time: 5.486s)

Am I missing something? Or, does test-refresh have a hard assumption about separate source & testing roots?

Thanks,
Alan

Nice to hear from you! Hope you're doing well.

It looks like test-refresh defaults to looking for a test directory. This default can be overridden at the command line. clojure -M:test-refresh --dir src in the sample project executes tests.

I had to dig through the code to find that as it looks like it isn't documented (or I can't find it now). The only documentation on it was also in the code and would print to the console with a --help flag. And that also wasn't documented 🤦 .

$ clojure -M:test-refresh --help
Below are the arguments supported by test-refresh:
  -d, --dir DIRNAME      Name of the directory containing tests. Specify flag multiple times for specifying multiple test directories. Defaults to "test".
      --no-config        Run and ignore all .test-refresh.edn files
  -c, --config FILENAME  Use specified file as a configuration file. Specify flag multiple times to specify multiple files. Later files override values found in earlier files. Defaults to ["~/.test-refresh.edn", ".test-refresh.edn"]
  -h, --help             Display this help message