Skip to content

test: Add test codebase for shell completions #14681

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion tests/testsuite/shell_completions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
#![allow(unused)]
use std::path::PathBuf;

use cargo::util::command_prelude::*;
use cargo_test_support::cargo_test;

#[cargo_test]
fn test_get_registry_candidates() {
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);
Comment on lines +65 to +67
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.


let expected = snapbox::str![
"my-registry1
my-registry2"
];
let actual = print_candidates(get_registry_candidates(Some(cwd)).unwrap());
snapbox::assert_data_eq!(actual, expected);
}

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

candidates
.into_iter()
Expand Down
3 changes: 3 additions & 0 deletions tests/testsuite/shell_completions/template/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[registries]
my-registry1 = { index = "my-registry1"}
my-registry2 = { index = "my-registry2"}