Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anvlkv committed Jun 22, 2024
1 parent 943ff2d commit 4c5da34
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 0 deletions.
50 changes: 50 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 21 additions & 0 deletions tests/dep-and-names.rs
Original file line number Diff line number Diff line change
@@ -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());
}
16 changes: 16 additions & 0 deletions tests/help.rs
Original file line number Diff line number Diff line change
@@ -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);
}
17 changes: 17 additions & 0 deletions tests/name-and-count.rs
Original file line number Diff line number Diff line change
@@ -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());
}
21 changes: 21 additions & 0 deletions tests/name-and-deps.rs
Original file line number Diff line number Diff line change
@@ -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());
}
35 changes: 35 additions & 0 deletions tests/snapshots/help__print_help.snap
Original file line number Diff line number Diff line change
@@ -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 <PATH> [COMMAND]

Commands:
clear-cache Clears cache
help Print this message or the help of the given subcommand(s)

Options:
-p, --path <PATH>
Path to Cargo project for analysis
-g, --gh-token <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>
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>
Format of the output file [default: NameAndCount]
-d, --depth <DEPTH>
Depth of scan, whether to include minor and optional depes contributors [default: Major]
-c, --contributions-threshold <CONTRIBUTIONS_THRESHOLD>
Min number of contributions to be included in the list, doesn't apply to sole contributors [default: 2]
-s, --sources <SOURCES>
List other sources, not specified in Cargo.toml
-t, --template <TEMPLATE>
Use your own template. See https://github.com/anvlkv/acknowledgements/blob/main/src/template.md?plain=1 for reference
-h, --help
Print help
-V, --version
Print version

0 comments on commit 4c5da34

Please sign in to comment.