diff --git a/Cargo.lock b/Cargo.lock index 473d48d..89bec8d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -100,6 +100,22 @@ dependencies = [ "derive_arbitrary", ] +[[package]] +name = "assert_cmd" +version = "2.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bd389a4b2970a01282ee455294913c0a43724daedcd1a24c3eb0ec1c1320b66" +dependencies = [ + "anstyle", + "bstr", + "doc-comment", + "libc", + "predicates", + "predicates-core", + "predicates-tree", + "wait-timeout", +] + [[package]] name = "async-trait" version = "0.1.89" @@ -153,6 +169,17 @@ dependencies = [ "generic-array", ] +[[package]] +name = "bstr" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "234113d19d0d7d613b40e86fb654acf958910802bcceab913a4f9e7cda03b1a4" +dependencies = [ + "memchr", + "regex-automata", + "serde", +] + [[package]] name = "bumpalo" version = "3.19.0" @@ -314,6 +341,12 @@ dependencies = [ "syn", ] +[[package]] +name = "difflib" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" + [[package]] name = "digest" version = "0.10.7" @@ -342,7 +375,7 @@ dependencies = [ "libc", "option-ext", "redox_users", - "windows-sys 0.60.2", + "windows-sys 0.61.1", ] [[package]] @@ -356,6 +389,12 @@ dependencies = [ "syn", ] +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + [[package]] name = "encode_unicode" version = "1.0.0" @@ -395,6 +434,15 @@ dependencies = [ "miniz_oxide", ] +[[package]] +name = "float-cmp" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b09cf3155332e944990140d967ff5eceb70df778b34f77d8075db46e4704e6d8" +dependencies = [ + "num-traits", +] + [[package]] name = "fnv" version = "1.0.7" @@ -971,6 +1019,12 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "normalize-line-endings" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" + [[package]] name = "nu-ansi-term" version = "0.50.1" @@ -1082,6 +1136,36 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "predicates" +version = "3.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5d19ee57562043d37e82899fade9a22ebab7be9cef5026b07fda9cdd4293573" +dependencies = [ + "anstyle", + "difflib", + "float-cmp", + "normalize-line-endings", + "predicates-core", + "regex", +] + +[[package]] +name = "predicates-core" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "727e462b119fe9c93fd0eb1429a5f7647394014cf3c04ab2c0350eeb09095ffa" + +[[package]] +name = "predicates-tree" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72dd2d6d381dfb73a193c7fca536518d7caee39fc8503f74e7dc0be0531b425c" +dependencies = [ + "predicates-core", + "termtree", +] + [[package]] name = "proc-macro2" version = "1.0.95" @@ -1157,6 +1241,7 @@ name = "pysentry" version = "0.3.12" dependencies = [ "anyhow", + "assert_cmd", "async-trait", "chrono", "clap", @@ -1166,6 +1251,7 @@ dependencies = [ "indicatif", "owo-colors", "pep440_rs", + "predicates", "pyo3", "regex", "reqwest", @@ -1708,9 +1794,15 @@ dependencies = [ "getrandom 0.3.3", "once_cell", "rustix", - "windows-sys 0.60.2", + "windows-sys 0.61.1", ] +[[package]] +name = "termtree" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f50febec83f5ee1df3015341d8bd429f2d1cc62bcba7ea2076759d315084683" + [[package]] name = "thiserror" version = "2.0.17" @@ -2052,6 +2144,15 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "wait-timeout" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ac3b126d3914f9849036f826e054cbabdc8519970b8998ddaf3b5bd3c65f11" +dependencies = [ + "libc", +] + [[package]] name = "want" version = "0.3.1" diff --git a/Cargo.toml b/Cargo.toml index 77f7cea..6a47456 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,3 +46,7 @@ toml = "0.9.7" tracing = "0.1.41" tracing-subscriber = { version = "0.3.20", features = ["env-filter"] } zip = { version = "5.1.1", default-features = false, features = ["deflate"] } + +[dev-dependencies] +assert_cmd = "2.0.17" +predicates = "3.1.3" diff --git a/src/cli.rs b/src/cli.rs index 55708f7..1cdf3d5 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -741,11 +741,11 @@ pub async fn audit( if audit_args.verbose { eprintln!( - "Configuration: format={:?}, severity={:?}, fail_on={:?}, source={:?}, scope='{}', direct_only={}", + "Configuration: format={:?}, severity={:?}, fail_on={:?}, sources=[{}], scope='{}', direct_only={}", audit_args.format, audit_args.severity, audit_args.fail_on, - audit_args.source, + audit_args.sources.join(", "), audit_args.scope_description(), audit_args.direct_only ); diff --git a/src/config.rs b/src/config.rs index 788f9d2..8a93fe2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -668,6 +668,8 @@ mod tests { use super::*; use std::fs; use tempfile::TempDir; + use assert_cmd::Command; + use predicates::prelude::*; #[test] fn test_config_load_from_file() { @@ -747,4 +749,50 @@ enabled = false assert!(loader.config_path.is_none()); assert_eq!(loader.config.defaults.format, "human"); } + + #[test] + fn test_display_sources_verbose_output() { + let temp_dir = TempDir::new().unwrap(); + let config_path = temp_dir.path().join(".pysentry.toml"); + + // Default config without sources specified + let config_content = r#" +version = 1 + +[cache] +enabled = false + +[output] +quiet = false +verbose = true +"#; + fs::write(&config_path, config_content).unwrap(); + + // Call the pysentry binary with the config file + // Only the default source "pypa" should be displayed + let mut cmd = Command::cargo_bin("pysentry").unwrap(); + cmd.arg("--config").arg(config_path.to_str().unwrap()); + cmd.assert() + .success() + .stderr(predicate::str::contains(", sources=[pypa],")); + + // Add multiple sources to config and save file + let config_content = format!("{}\n{}", + config_content, + r#" + +[sources] +enabled = ["pypa", "pypi", "osv"] +"#); + + fs::write(&config_path, config_content).unwrap(); + + // Call the pysentry binary again with the updated config file + // Now all specified sources should be displayed + let mut cmd = Command::cargo_bin("pysentry").unwrap(); + cmd.arg("--config").arg(config_path.to_str().unwrap()); + cmd.assert() + .success() + .stderr(predicate::str::contains(", sources=[pypa, pypi, osv],")); + } }