Crystal: spec --location to work on any line in indvidual spec

Created on 20 Jul 2016  路  3Comments  路  Source: crystal-lang/crystal

Right now crystal spec file:line only works if the line number is the same line as the it, but it'd be nice if any line number inside the do鈥nd worked, especially with editor integration. Not as important, but related if inside a describe do鈥nd but not in a spec, ran all specs in that group.

I did a little digging into command and spec, but it seems only the first line is stored for matches?. Maybe it could be a range, but coming up with the end of the range has me a bit stumped.

feature stdlib

Most helpful comment

I added macro methods to get a node's location, both the beginning and the end. I then tried making describe and it be macros, so they can get where the block ends, and it worked. But of course this is only possible with the next compiler, so this feature will have to wait a couple of releases, but it'll be possible :-)

All 3 comments

Yes, it would be nice. It's not implemented because of what you say: there's currently no way to know when a spec ends. We know the first line with __FILE__ and __LINE__. We'd need those values for where the block ends. Maybe it and describe could be macros, and then we'd need to add macro methods to nodes to get their location at compile time.

I added macro methods to get a node's location, both the beginning and the end. I then tried making describe and it be macros, so they can get where the block ends, and it worked. But of course this is only possible with the next compiler, so this feature will have to wait a couple of releases, but it'll be possible :-)

This is actually already working in master 馃帀 . The actual solution involved adding the magic constant __END_LINE__ (similar to __LINE__)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lbguilherme picture lbguilherme  路  3Comments

RX14 picture RX14  路  3Comments

oprypin picture oprypin  路  3Comments

Sija picture Sija  路  3Comments

asterite picture asterite  路  3Comments