Welcome! Please see the About page for a little more info on how this works.

0 votes
in Clojure by

Recently, I found a bug in a project from the company I work at.

Basically, what was happening was that inside a test's namespace we required two different namespaces, let's call them first-ns and second-ns here.

Both first-ns and second-ns had the definition of a spec with the same name, like this:

(ns first-ns)
(s/def :same/name
    int?)

(ns second-ns)
(s/def :same/name
    string?)

So my question is, is there a way to make the Clojure compiler complain about a name clash for cases like this? In large codebases with hundreds of specs, this can occasionally happen and cause a heisenbug. Is the only solution to make the specs namespaced to the same ns of the file in which they were defined?

1 Answer

0 votes
by
selected by
 
Best answer

Specs are intentionally overrideable in the registry as you do this all the time at the REPL.

It would maybe be useful to warn when that happens though or have a setting like *warn-on-spec-replace* to do so.

by
edited by
EDIT: nevermind, I noticed that there is a comment block at the end of the tests file.

Thanks, Alex!

Sorry to bother you, but I got interested in trying to implement that *warn-on-spec-replace*, but I couldn't find a way to execute the tests in clojure.spec.alpha, so that I could test my implementation.

Could you please tell me how one can run the tests in that project?
by
All of the contrib projects are built with Maven and you should be able to run the tests with `mvn clean test` or build the jar with `mvn clean package` or install a local snapshot with `mvn install`.

FYI, we probably will not release any more versions of clojure.spec.alpha as we are working on the next version of spec in clojure.spec-alpha2 repo. Probably the changes for this in either are approximately the same though.
by
Thank you for the help, Alex! I opened an issue related to it here: https://clojure.atlassian.net/projects/CLJ/issues/CLJ-2578
...