-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
e1e43f4
ae0363c
b9d09f0
64b9b0d
95d9be2
9ebdd49
1ba0169
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
candidates | ||
.into_iter() | ||
.map(|candidate| { | ||
let compl = candidate.get_value().to_str().unwrap(); | ||
if let Some(help) = candidate.get_help() { | ||
format!("{compl}\t{help}") | ||
} else { | ||
compl.to_owned() | ||
} | ||
}) | ||
.collect::<Vec<_>>() | ||
.join("\n") | ||
} |
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"} |
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 being
pub
doesn't make a difference as this only exists in thebin