gengen
gengen copied to clipboard
flag to skip test files?
Penny for your thoughts?
I wrote a generic package for use with gengen, and what came most naturally was to write tests alongside the main code that worked with the un-processed version (so directly using the generic.T
and generic.U
aliases for interface{}
). Things are great, I have nice coverage of the generic code.
But as soon as I produced a concrete package with a //go:generate gengen
directive, I got tests brought along for the ride which no longer passed given the new concrete types.
I'm of 2 minds about what I did wrong:
- Maybe the generic package's test suite should be prepared for any possible substitutions. Or alternatively, only included in a concrete sub-package that is generated from the primary generic package (myhost/lru is the generic package, myhost/lru/intstring is generated from it and also holds the tests).
- Maybe bringing the tests along at all was a mistake? Perhaps it's good enough from the generic package's perspective that the generic algorithm is validated, and its tests shouldn't have to worry about catering to every possible concrete type substitution.
I'm leaning towards the latter: a user's type-specific generated code is their own code, and they assume responsibility for it. The generic package needn't be responsible for testing/demonstrating the correctness of anything more than the interface{}
case.
I'd be happy to implement a flag to omit *_test.go
(or include -- skipping could be the default), but I thought I'd lob this question over to you first.
Another option might be to use Go's build tags and skip over any file that had something like // +build !gengen
. Or possibly only process files that have // +build gengen
in them. I'm not sure that's definitely the way to go, but it's a possibility.
Let me think about this a little bit. In the meantime, is the package you were using up on github? I'd like to play around with it.