Skip to content

test: Add test codebase for shell completions#14681

Closed
shannmu wants to merge 7 commits into
rust-lang:masterfrom
shannmu:test_codebase
Closed

test: Add test codebase for shell completions#14681
shannmu wants to merge 7 commits into
rust-lang:masterfrom
shannmu:test_codebase

Conversation

@shannmu

@shannmu shannmu commented Oct 13, 2024

Copy link
Copy Markdown
Contributor

What does this PR try to resolve?

Tracking issue #14520

  • Refactor candidates generators to make them testable
  • Add a test codebase and template project used for building test cases
  • Add test code for get_registry_candidates, get_example_candidates, get_test_candidates, get_bench_candidates, get_bin_candidates

…pletions`

Passing `cwd` to custom completion functions makes that we could generate completions in the template project.
- Add an empty template project, which is used for building test cases
- Add a format function used for completions result
- Sort the order of example candidates by the way
@rustbot

rustbot commented Oct 13, 2024

Copy link
Copy Markdown
Collaborator

r? @epage

rustbot has assigned @epage.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-cli Area: Command-line interface, option parsing, etc. Command-add Command-uninstall Command-update S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 13, 2024
}

fn get_installed_crates() -> Vec<clap_complete::CompletionCandidate> {
pub fn get_installed_crates() -> Vec<clap_complete::CompletionCandidate> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This being pub doesn't make a difference as this only exists in the bin

@@ -0,0 +1,15 @@
#![allow(unused)]
fn print_candidates(candidates: Vec<clap_complete::CompletionCandidate>) -> String {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

render_candidates since this doesn't print to stdout/stderr

Comment on lines +8 to +10
let current_dir = std::env::current_dir().expect("Failed to get current directory");
let cwd = PathBuf::from(file!()).parent().unwrap().join("template");
let cwd = current_dir.join(cwd);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A temp directory is created for each test. I'd recommend going ahead and writing to that and using that as the "cwd" for the test case. We have ProjectBuilder to help in creating these. You can also publish packages to a dev registry.

{
Ok(registries
.keys()
.sorted()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • This appears to be unrelated to the current commit
  • This should likely be a fix commit on its own

@rustbot

rustbot commented Mar 20, 2025

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (possibly 307cbfd) made this pull request unmergeable. Please resolve the merge conflicts.

@weihanglo

Copy link
Copy Markdown
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 11, 2025
@rustbot

rustbot commented Apr 11, 2025

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@motorailgun

Copy link
Copy Markdown
Contributor

I'm interested in working on this. Would you mind if I took over this PR? @shannmu

@epage

epage commented Jan 28, 2026

Copy link
Copy Markdown
Contributor

As this has been in draft for over a year, I'm going to go ahead and close this.

@epage epage closed this Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area: Command-line interface, option parsing, etc. Command-add Command-uninstall Command-update S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants