Skip to content

Commit 93eeea1

Browse files
authored
Merge pull request #101 from alexandre3920/feat/display-sources-in-verbose
Fix sources displayed in verbose output
2 parents 1da8964 + ca25815 commit 93eeea1

File tree

4 files changed

+157
-4
lines changed

4 files changed

+157
-4
lines changed

Cargo.lock

Lines changed: 103 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,7 @@ toml = "0.9.7"
4646
tracing = "0.1.41"
4747
tracing-subscriber = { version = "0.3.20", features = ["env-filter"] }
4848
zip = { version = "5.1.1", default-features = false, features = ["deflate"] }
49+
50+
[dev-dependencies]
51+
assert_cmd = "2.0.17"
52+
predicates = "3.1.3"

src/cli.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,11 +741,11 @@ pub async fn audit(
741741

742742
if audit_args.verbose {
743743
eprintln!(
744-
"Configuration: format={:?}, severity={:?}, fail_on={:?}, source={:?}, scope='{}', direct_only={}",
744+
"Configuration: format={:?}, severity={:?}, fail_on={:?}, sources=[{}], scope='{}', direct_only={}",
745745
audit_args.format,
746746
audit_args.severity,
747747
audit_args.fail_on,
748-
audit_args.source,
748+
audit_args.sources.join(", "),
749749
audit_args.scope_description(),
750750
audit_args.direct_only
751751
);

src/config.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,8 @@ mod tests {
668668
use super::*;
669669
use std::fs;
670670
use tempfile::TempDir;
671+
use assert_cmd::Command;
672+
use predicates::prelude::*;
671673

672674
#[test]
673675
fn test_config_load_from_file() {
@@ -747,4 +749,50 @@ enabled = false
747749
assert!(loader.config_path.is_none());
748750
assert_eq!(loader.config.defaults.format, "human");
749751
}
752+
753+
#[test]
754+
fn test_display_sources_verbose_output() {
755+
let temp_dir = TempDir::new().unwrap();
756+
let config_path = temp_dir.path().join(".pysentry.toml");
757+
758+
// Default config without sources specified
759+
let config_content = r#"
760+
version = 1
761+
762+
[cache]
763+
enabled = false
764+
765+
[output]
766+
quiet = false
767+
verbose = true
768+
"#;
769+
fs::write(&config_path, config_content).unwrap();
770+
771+
// Call the pysentry binary with the config file
772+
// Only the default source "pypa" should be displayed
773+
let mut cmd = Command::cargo_bin("pysentry").unwrap();
774+
cmd.arg("--config").arg(config_path.to_str().unwrap());
775+
cmd.assert()
776+
.success()
777+
.stderr(predicate::str::contains(", sources=[pypa],"));
778+
779+
// Add multiple sources to config and save file
780+
let config_content = format!("{}\n{}",
781+
config_content,
782+
r#"
783+
784+
[sources]
785+
enabled = ["pypa", "pypi", "osv"]
786+
"#);
787+
788+
fs::write(&config_path, config_content).unwrap();
789+
790+
// Call the pysentry binary again with the updated config file
791+
// Now all specified sources should be displayed
792+
let mut cmd = Command::cargo_bin("pysentry").unwrap();
793+
cmd.arg("--config").arg(config_path.to_str().unwrap());
794+
cmd.assert()
795+
.success()
796+
.stderr(predicate::str::contains(", sources=[pypa, pypi, osv],"));
797+
}
750798
}

0 commit comments

Comments
 (0)