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

test: Add test codebase for shell completions #14681

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

shannmu
Copy link
Contributor

@shannmu shannmu commented Oct 13, 2024

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
Copy link
Collaborator

rustbot commented Oct 13, 2024

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
@@ -45,7 +45,7 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
Ok(())
}

fn get_installed_crates() -> Vec<clap_complete::CompletionCandidate> {
pub fn get_installed_crates() -> Vec<clap_complete::CompletionCandidate> {
Copy link
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
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
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.

@@ -1104,14 +1105,15 @@ pub fn get_registry_candidates(
{
Ok(registries
.keys()
.sorted()
Copy link
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

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-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants