Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 13 additions & 9 deletions command-signatures/src/generators/apt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ const LIST_ALL_DEB_FILES_COMMAND: &str = r#"find . -maxdepth 1 -type f -name '*.
pub fn list_all_packages(output: &str) -> GeneratorResults {
let mut targets = Vec::new();
for package_name in output.lines() {
targets.push(Suggestion::with_description(
package_name.to_string(),
"package",
));
if !package_name.is_empty() {

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 bug fix changes both parser callbacks but adds no test, so a later refactor could reintroduce blank suggestions unnoticed. apt.rs has no #[cfg(test)] module today, while sibling generators such as asdf.rs test their parser callbacks directly. Add coverage that calls list_all_packages and list_all_deb_files_in_cwd with an internal empty record (e.g. "foo\n\nbar") and asserts only the non-empty suggestions remain; a lone trailing newline is not a useful case because str::lines() already excludes it.

targets.push(Suggestion::with_description(
package_name.to_string(),
"package",
));
}
}
targets.into_iter().collect_unordered_results()
}
Expand All @@ -41,11 +43,13 @@ pub fn list_available_packages(output: &str) -> GeneratorResults {
pub fn list_all_deb_files_in_cwd(output: &str) -> GeneratorResults {
let mut targets = Vec::new();
for file in output.lines() {
targets.push(
// We should prioritize .deb files over the already installed packages.
Suggestion::with_description(file.to_string(), ".deb file")
.with_priority(Priority::most_important()),
)
if !file.is_empty() {
targets.push(
// We should prioritize .deb files over the already installed packages.
Suggestion::with_description(file.to_string(), ".deb file")
.with_priority(Priority::most_important()),
);
}
}
targets.into_iter().collect_unordered_results()
}
Expand Down
38 changes: 38 additions & 0 deletions command-signatures/src/generators/apt_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_list_all_packages_filters_empty_lines() {
let output = "vim\ngit\n\n";
let results = list_all_packages(output);
let suggestions: Vec<_> = results.into_iter().collect();
assert_eq!(suggestions.len(), 2);
assert_eq!(suggestions[0].name, "vim");
assert_eq!(suggestions[1].name, "git");
}

#[test]
fn test_list_all_packages_empty_input() {
let results = list_all_packages("");
let suggestions: Vec<_> = results.into_iter().collect();
assert_eq!(suggestions.len(), 0);
}

#[test]
fn test_list_all_deb_files_filters_empty_lines() {
let output = "./foo.deb\n./bar.deb\n\n";
let results = list_all_deb_files_in_cwd(output);
let suggestions: Vec<_> = results.into_iter().collect();
assert_eq!(suggestions.len(), 2);
assert_eq!(suggestions[0].name, "./foo.deb");
assert_eq!(suggestions[1].name, "./bar.deb");
}

#[test]
fn test_list_all_deb_files_empty_input() {
let results = list_all_deb_files_in_cwd("");
let suggestions: Vec<_> = results.into_iter().collect();
assert_eq!(suggestions.len(), 0);
}
}