Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow line numbers in addition to test name for focusing tests #45765

Open
thegranddesign opened this Issue Nov 4, 2017 · 4 comments

Comments

Projects
None yet
4 participants
@thegranddesign
Copy link

thegranddesign commented Nov 4, 2017

When working in an editor and scripting test runs in an automated fashion, it's much more practical to be able to specify the line number rather than trying to parse the file to determine the test name.

For example:

#[cfg(test)]
mod tests {
    #[test]
    fn it_can_add_things() {
        assert!(2 + 2, 4)
    }
}

It's quite difficult to parse backwards line by line to find the previous fn statement (which is problematic in itself) and then pull out the it_can_add_things section of the line before finally constructing the full command.

All editors have a capability to determine the current line and thus, assuming I'm on line 5 (the assert line), running something like cargo test 5 or cargo test --lines=5 is very straightforward.

Bonus points would include ranges and comma separated lists: cargo test --lines=1-10,21

This feature would effectively allow "run the test under the cursor" which is something that I do constantly during the day in other languages.

@Ixrec

This comment has been minimized.

Copy link
Contributor

Ixrec commented Nov 4, 2017

Maybe I'm missing something, but "run the test under the cursor" seems like a feature that should be implemented as a macro/plugin for the editor, while rust/cargo should just take a test name. Especially since your editor might be auto-editing the file for various reasons, including auto-formatting that might change line numbers around at (from rust/cargo's point of view) random times.

But I totally agree that "run the test under the cursor" should get implemented.

@thegranddesign

This comment has been minimized.

Copy link
Author

thegranddesign commented Nov 4, 2017

I absolutely get what you’re saying. I think the point I’m trying to make is that this is a general requirement for editors and making each editor have its own logic for doing something like this (each of which can have its own set of bugs) in each of their own plugins seems like an inelegant solution.

I agree that this would have to be determined prior to any code transforms (eg macros) happening.

@thegranddesign

This comment has been minimized.

Copy link
Author

thegranddesign commented Nov 4, 2017

As far as auto formatting in the editor, that is absolutely the user’s/editor’s job to deal with. That’s not rust’s responsibility. As long as there’s a way to run the tests on a given line, that should be all rust has to care about.

@matklad

This comment has been minimized.

Copy link
Member

matklad commented Dec 8, 2017

It is certainly possible to do this on the IDE level, IntelliJ does this, and RLS should be able to too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.