Hello all,
I got a lot of functions like these in a hobby project of mine:
@spec optional_alphanum(pos_integer) :: %StreamData{}
def optional_alphanum(size) when size > 0 do
gen all str <- string([?A..?Z, ?0..?9], min_length: 0, max_length: size) do
String.pad_trailing(str, size, " ")
end
end
To which Dialyzer (through dialyxir) always complains: Function optional_alphanum/1 has no local return. I also tried appending | no_return() to the return type, and it did not help.
Any clues? I am aware that ExUnitProperties.gen is a macro but cannot decipher what I have to do to make Dialyzer happy in this case.
If you don’t like opinions that say to change your libraries you can skip now.
Take a look into using PropCheck for the generators instead of StreamData. They have more control and are better at shrinking. It might also solve your dialyzer issue.
Well, I invested a lot in this personal project and I have like 800+ lines of code using ExUnitProperties and StreamData. But your idea is interesting and I can try it on a much smaller scale.
A bit offtopic but it happens from time to time that dialyzer catches problems that are external to my application (like wrong specs in a dependency), in these cases there is a way to silence specific warnings (s. Erlang -- dialyzer ).
As a temporary measure you can add something like that to your module so that this function does not trigger warnings:
Fair point. But since this is a personal project, I won’t insist on 100% @spec coverage or put Dialyzer as a pre-commit hook. For the time being it’s fine if my generators aren’t specced in a way that Dialyzer likes.
I was trying to dig back through old code and find an example where I had issues with shrinking, but it looks like @kethley already put in an issue with one of the problems. https://github.com/whatyouhide/stream_data/issues/107
The other features of type generation that I have wanted, and found readily in PropCheck and or Proper, are targeted properties and controlled shrinking.
The other, IMO, significant gap in StreamData is stateful property-based testing. I hope to one day see that in StreamData, but for right now I put my eggs into PropCheck due to the years of work and effort that it is leveraging in Proper.