[Codenarc-developer] Inline violations idea
Brought to you by:
chrismair
From: Artur G. <art...@gm...> - 2013-05-05 19:44:33
|
Hi! I think I've got an idea for a significant improvement of the (already great) CodeNarc's test framework and would like to consult it before making a pull request ;) The thing that is (for me) the most cumbersome when writing tests is passing the line number and line text to the assert*Violation[s] methods. I think I understand the rationale behind having to pass both of them, which seems to be a kind of a double check / 'checksum'. I'd like to propose an API in which we only have to write the violation message - and the API reliably finds the sourceLineText and lineNumber for us. I've made a POC implementation in inlineViolations<https://github.com/ArturGajowy/CodeNarc/tree/inlineViolations> branch of my fork. The result is best depicted here<https://github.com/ArturGajowy/CodeNarc/commit/9cb0777e9f1c14d4b532bbd43d0e84bea6ecf494#commitcomment-3147447> . As you can see, the whole idea is based on violation markers placed in the test sources - just in the line the violation takes place. This way, when we add a line to the source before the violation (e.g. an import we've missed or a class header, or another violating line) - we don't have to edit any preexisting violation assertions. There's also no copy'n'paste and line counting invlolved in the initial process of writing tests :) The violation markers are removed before the analysis takes place, so that the assertion errors do not become illegible and the markers don't interfere with analysis made by rule under test. As I've said - this is a POC. It lacks: support for multiple violations per line, standalone tests, a bit of defensive programming and first of all - your approval of the API :) Let me know what do you think of the idea: do you like it, would you like this in CodeNarc, are there any issues to address before you'd like a pull request with that. And of course - I'll be more than happy to implement the final version :) Best regards, Artur Gajowy |