I got caught out by
elm-format changing the
exposing list in my test module. It changed
exposing (..) to
exposing (suite), so when I added another suite,
suite2 : Test, with a failing test, and forgot to update the
exposing list manually,
elm-test still reported that the tests passed – incorrectly – because the new failing test wasn’t included in the test run.
In this situation, code formatting is potentially affecting reliability of the code, and it seems that
exposing (..) would be a more reliable option. I’m not sure if there is even a use case for non-exposed
Test values given that
only for running subsets of tests.
To work around this, I could either put all the tests into a single
Test value, nesting liberally with
describe, or I could have a rule to define one
Test value per file, splitting tests across multiple files.
I’m interested to know whether other people have run into this issue, and if you did, how do you manage the tests? Is it really unusual to define multiple
Test values in a single file?
I think ultimately the solution here is for the compiler to warn about unused definitions. A top-level definition would be unused if it is not referenced within the module and also not exported. That would have caught your problem.
The exellent elm-analyse performed this check, but is unfortunately not yet updated for 0.19.
Unfortunately neither of these gives you any help now.
I think the answer, for now, is just “you need to remember to manually add tests to the
exposing list”. Maybe elm-format shouldn’t overwrite
Like @allanderek said, I’d love to see an “unused variable” warning. I’ve found that would catch a large percentage of the errors I see these days (considering the type system does such a great job!). Since Elm is a pure language, defining and not using a variable can’t do anything except eat up a bit of processing power so I’d venture to say an unused variable is always a mistake or oversight. (Side note: the special underscore variable
_ would not be considered unused).
Another possible solution would be for
elm-format to only override the
exposing list in packages, which I’ve seen somebody suggest. (I guess even in packages, it would still be necessary to exclude test modules somehow).
I just don’t see the use case for not exporting
Test values, and hence for maintaining a long
exposing list in every test module.
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.