diff --git a/Cargo.lock b/Cargo.lock index 47af3bb..0e2ca2e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,6 +14,7 @@ dependencies = [ "crates_io_api", "dirs", "handlebars", + "insta", "octocrab", "reqwest", "serde", @@ -318,6 +319,18 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" +[[package]] +name = "console" +version = "0.15.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e1f83fc076bd6dd27517eacdf25fef6c4dfe5f1d7448bafaaf3a26f13b5e4eb" +dependencies = [ + "encode_unicode", + "lazy_static", + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "core-foundation" version = "0.9.4" @@ -416,6 +429,12 @@ version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" +[[package]] +name = "encode_unicode" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" + [[package]] name = "encoding_rs" version = "0.8.34" @@ -840,6 +859,19 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "insta" +version = "1.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "810ae6042d48e2c9e9215043563a58a80b877bc863228a74cf10c49d4620a6f5" +dependencies = [ + "console", + "lazy_static", + "linked-hash-map", + "serde", + "similar", +] + [[package]] name = "ipnet" version = "2.9.0" @@ -892,6 +924,12 @@ dependencies = [ "simple_asn1", ] +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + [[package]] name = "libc" version = "0.2.155" @@ -908,6 +946,12 @@ dependencies = [ "libc", ] +[[package]] +name = "linked-hash-map" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" + [[package]] name = "linux-raw-sys" version = "0.4.14" @@ -1602,6 +1646,12 @@ dependencies = [ "digest", ] +[[package]] +name = "similar" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa42c91313f1d05da9b26f267f931cf178d4aba455b4c4622dd7355eb80c6640" + [[package]] name = "simple_asn1" version = "0.6.2" diff --git a/Cargo.toml b/Cargo.toml index 0b27989..96c51a5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,3 +39,11 @@ cacache = { version = "13.0.0", default-features = false, features = [ "mmap", ] } chrono = { version = "0.4.38", default-features = false, features = ["now"] } + +[dev-dependencies] +insta = { version = "1.39.0", features = ["yaml"] } + + +[profile.dev.package] +insta.opt-level = 3 +similar.opt-level = 3 diff --git a/tests/dep-and-names.rs b/tests/dep-and-names.rs new file mode 100644 index 0000000..9c80c1c --- /dev/null +++ b/tests/dep-and-names.rs @@ -0,0 +1,21 @@ +use std::path::PathBuf; +use std::process::Command; + +#[test] +fn generate_with_dep_and_names() { + let dot = std::env::var("CARGO_MANIFEST_DIR").unwrap(); + let mut path = PathBuf::from(&dot); + let mut out = path.clone(); + path.push("target/debug/acknowledge"); + out.push("ACKNOWLEDGEMENTS-DepAndNames.md"); + let output = Command::new(path) + .arg(format!("-p={dot}")) + .arg("--format=DepAndNames") + .arg(format!("--output={}", out.to_str().unwrap())) + .output() + .expect("Failed to run"); + + println!("output: {output:#?}"); + + assert!(output.stderr.is_empty()); +} diff --git a/tests/help.rs b/tests/help.rs new file mode 100644 index 0000000..f309b8a --- /dev/null +++ b/tests/help.rs @@ -0,0 +1,16 @@ +use std::path::PathBuf; +use std::process::Command; + +#[test] +fn print_help() { + let dot = std::env::var("CARGO_MANIFEST_DIR").unwrap(); + let mut path = PathBuf::from(&dot); + path.push("target/debug/acknowledge"); + let output = Command::new(path) + .arg(format!("--help")) + .output() + .expect("Failed to run"); + let printed = String::from_utf8(output.stdout).expect("Failed to parse"); + + insta::assert_snapshot!(printed); +} diff --git a/tests/name-and-count.rs b/tests/name-and-count.rs new file mode 100644 index 0000000..ab087d9 --- /dev/null +++ b/tests/name-and-count.rs @@ -0,0 +1,17 @@ +use std::path::PathBuf; +use std::process::Command; + +#[test] +fn generate_with_name_and_count() { + let dot = std::env::var("CARGO_MANIFEST_DIR").unwrap(); + let mut path = PathBuf::from(&dot); + path.push("target/debug/acknowledge"); + let output = Command::new(path) + .arg(format!("-p={dot}")) + .output() + .expect("Failed to run"); + + println!("output: {output:#?}"); + + assert!(output.stderr.is_empty()); +} diff --git a/tests/name-and-deps.rs b/tests/name-and-deps.rs new file mode 100644 index 0000000..3eb3a15 --- /dev/null +++ b/tests/name-and-deps.rs @@ -0,0 +1,21 @@ +use std::path::PathBuf; +use std::process::Command; + +#[test] +fn generate_with_name_and_deps() { + let dot = std::env::var("CARGO_MANIFEST_DIR").unwrap(); + let mut path = PathBuf::from(&dot); + let mut out = path.clone(); + path.push("target/debug/acknowledge"); + out.push("ACKNOWLEDGEMENTS-NameAndDeps.md"); + let output = Command::new(path) + .arg(format!("-p={dot}")) + .arg("--format=NameAndDeps") + .arg(format!("--output={}", out.to_str().unwrap())) + .output() + .expect("Failed to run"); + + println!("output: {output:#?}"); + + assert!(output.stderr.is_empty()); +} diff --git a/tests/snapshots/help__print_help.snap b/tests/snapshots/help__print_help.snap new file mode 100644 index 0000000..a922bc9 --- /dev/null +++ b/tests/snapshots/help__print_help.snap @@ -0,0 +1,35 @@ +--- +source: tests/help.rs +expression: printed +--- +acknowledge is a simple CLI tool to analyze dependencies of a Cargo (rust) project and produce an ACKNOWLEDMENTS.md file listing (major) contributors of your dependencies + +Usage: acknowledge [OPTIONS] --path [COMMAND] + +Commands: + clear-cache Clears cache + help Print this message or the help of the given subcommand(s) + +Options: + -p, --path + Path to Cargo project for analysis + -g, --gh-token + Running Acknowledgements on any project of reasonable size you're likely to face rate limits. Please provide a personal access token + -o, --output + Output file path, defaults to project path if not provided + -m, --mention + Whether to include @ (at) symbol in front of a github user's name + -f, --format + Format of the output file [default: NameAndCount] + -d, --depth + Depth of scan, whether to include minor and optional depes contributors [default: Major] + -c, --contributions-threshold + Min number of contributions to be included in the list, doesn't apply to sole contributors [default: 2] + -s, --sources + List other sources, not specified in Cargo.toml + -t, --template