-
Notifications
You must be signed in to change notification settings - Fork 67
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
Add api to run specific test #2
Conversation
Signed-off-by: Nicolas Lamirault <nicolas.lamirault@gmail.com>
Hey, thanks for the PR. I'll take a look at it once I'm home. |
Cargo: Run the tests." | ||
(interactive) | ||
(let ((name (cargo-process--get-current-test))) | ||
(cargo-process--start "Test" (s-concat "cargo test " name)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use concat
instead of s-concat
? Would be nice to not be dependent on 's library.
Signed-off-by: Nicolas Lamirault <nicolas.lamirault@gmail.com>
A few things:
is failing because there are no spaces between the pipes, but this will still not work. Taken from So let's say your file name is lib.rs, testing only that file should be Maybe you could try that instead? |
(unless (and | ||
(search-backward-regexp | ||
(s-concat "^[[:space:]]*fn[[:space:]]*") nil t) | ||
(save-excursion (go-end-of-defun) (< start (point)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(go-end-of-defun) is undefined, where did this come from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A Mistake. It must be rust-end-of-defun
. Defined in rust-mode [1].
[1] : https://github.com/rust-lang/rust-mode/blob/master/rust-mode.el
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fine, then we should add rust-mode as a dependency (which isn't the case right now)
Great ! I will try that |
These are some really cool additions btw, maybe give them keybindings? e.g. Or something else. |
(save-excursion (go-end-of-defun) (< start (point)))) | ||
(error "Unable to find test")) | ||
(save-excursion | ||
(search-forward "fn ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not search-forward-regexp like the previous one? If you're going to use that regex again you should create a defconst to hold that value (instead of repeating it)
Signed-off-by: Nicolas Lamirault <nicolas.lamirault@gmail.com>
Signed-off-by: Nicolas Lamirault <nicolas.lamirault@gmail.com>
Any chance this can be merged? I'd really appreciate this functionality. (As an aside, please crib from rspec-mode :-) That mode has been very useful for ruby development.) |
There are still a few things that need to be fixed, removal of the 's lib, stray comments, usage of the |
Thanks! I downloaded a copy of your changes and played around with it. One thing I ran into is some projects use macros to define their tests, e.g. Cargo uses I think it'd be great if we could add arbitrary args to ;;;###autoload
(defun cargo-process-test-args (extra)
"Run the Cargo test command with arguments.
Cargo: Run the tests with args."
(interactive "sargs: ")
(cargo-process--start "Test" (s-concat "cargo test " extra))) |
That snippet looks fine (except should use
Possibly adding auto completion for these flags in the future would be a great addition. But for now, if it benefits you, feel free to create a PR with your change. Or I can quickly add it myself since it's not too much work. |
I'm in no hurry since I was able to make these changes locally to unblock myself. The one thing that bothers me about this strategy is having to do it for each of the cargo commands. For example, The one way to deal with this is to play keep-up. You can make or accept pull requests for changes that allow argument plumbing per cargo command. This falls flat in the face of custom cargo commands which may be public (https://github.com/kbknapp/cargo-extras) or private. Thus, I think a better route would be to allow the top-level function Does that make sense? |
(For my own education; I just hacked my snippet on top of this PR. I don't really know elisp.)
I did a bit of reading and it looks like these functions are identical? Is it just defined for convenience/consistency in magnars/s.el or is there some other benefit to that definition? |
This could be done, we can simply add a &rest argument and concatenate the command. Would be a clean solution I think (if that's what you meant)
The reason is that they're identical. If we add s-concat we'll have to add 's as a dependency. This isn't a bad thing per se, but I'd like avoid unnecessary dependencies. |
👍 |
Signed-off-by: Nicolas Lamirault <nicolas.lamirault@gmail.com>
Like that: M-x cargo-process-current-test -*- mode: cargo-process; default-directory: "~/Perso/cargo.el/var/hello_world/tests/" -*- Cargo-Process started at Tue Jan 5 10:22:12 cargo test it_works_another Running /home/nlamirault/Perso/cargo.el/var/hello_world/target/debug/hello_world-9f660b2810b4c89b running 1 test test it_works_another ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured Running /home/nlamirault/Perso/cargo.el/var/hello_world/target/debug/lib-dff9d964ea838ea8 running 1 test test it_works_another ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured Doc-tests hello_world running 0 tests test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured M-x cargo-process-current-file-tests -*- mode: cargo-process; default-directory: "~/Perso/cargo.el/var/hello_world/tests/" -*- Cargo-Process started at Tue Jan 5 10:19:53 cargo test --test lib Running /home/nlamirault/Perso/cargo.el/var/hello_world/target/debug/lib-dff9d964ea838ea8 running 3 tests test it_works_another ... ok test it_works ... ok test just_a_test ... ok test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured Signed-off-by: Nicolas Lamirault <nicolas.lamirault@gmail.com>
name)) | ||
|
||
|
||
;; (defun cargo-process--get-current-file-tests () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be removed now, right? :)
Looks great, thank you! Just fix those last 2 comments and I'll gladly merge :) |
I'll just merge this and add my own extra changes, had some extra time on my hands :) thanks for this! 👍 |
Just for clarification, here are my changes. a6e367e |
Great |
With this file :
When pointer is in
it_works_another
, with M-x cargo-process-current-test, cargo is called to run specific test :There is also another method to run all test from current file, but actually it doesn't work :
Another command which fails (only 2 tests are executed) :
I don't really know if it is possible to launch all tests from one file with Cargo.
Signed-off-by: Nicolas Lamirault nicolas.lamirault@gmail.com