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
1 change: 1 addition & 0 deletions Cargo.lock

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

9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ gix-features-for-configuration-only = { package = "gix-features", version = "0.2
gix = { version = "0.44.1", default-features = false, features = [
"max-performance-safe",
] }
gix-testtools = { version = "0.11.0", optional = true }
git2 = { version = "0.17.1", default-features = false }
human-panic = "1.1.4"
image = "0.24.6"
Expand All @@ -52,13 +53,18 @@ yaml-rust = "0.4.5"

[dev-dependencies]
criterion = "0.4.0"
gix-testtools = "0.11.0"
insta = { version = "1.29.0", features = ["json", "redactions"] }
onefetch = { path = ".", features = ["test-utils"] }
pretty_assertions = "1.3.0"

[[bench]]
name = "repo"
harness = false
required-features = ["test-utils"]

[[test]]
name = "repo"
required-features = ["test-utils"]

[build-dependencies]
lazy_static = "1"
Expand All @@ -75,3 +81,4 @@ enable-ansi-support = "0.2.1"

[features]
fail-on-deprecated = []
test-utils = ["gix-testtools"]
6 changes: 2 additions & 4 deletions benches/repo.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use gix::{open, ThreadSafeRepository};
use onefetch::utils::repo;
use onefetch::{cli::CliOptions, info::Info};

fn bench_repo_info(c: &mut Criterion) {
let name = "repo.sh".to_string();
let repo_path = gix_testtools::scripted_fixture_read_only(name).unwrap();
let repo = ThreadSafeRepository::open_opts(repo_path, open::Options::isolated()).unwrap();
let repo = repo("repo.sh").unwrap();
let config: CliOptions = CliOptions {
input: repo.path().to_path_buf(),
..Default::default()
Expand Down
9 changes: 9 additions & 0 deletions src/info/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,10 @@ fn get_style(is_bold: bool, color: DynColors) -> Style {

#[cfg(test)]
mod tests {
#[cfg(feature = "test-utils")]
use crate::cli::TextForamttingCliOptions;
#[cfg(feature = "test-utils")]
use crate::utils::repo;

use super::*;
use owo_colors::AnsiColors;
Expand Down Expand Up @@ -349,8 +352,11 @@ mod tests {
}

#[test]
#[cfg(feature = "test-utils")]
fn test_info_style_info() -> Result<()> {
let repo = repo("basic_repo.sh")?;
let config: CliOptions = CliOptions {
input: repo.path().to_path_buf(),
text_formatting: TextForamttingCliOptions {
text_colors: vec![0, 0, 0, 0, 0, 0],
..Default::default()
Expand All @@ -370,8 +376,11 @@ mod tests {
}

#[test]
#[cfg(feature = "test-utils")]
fn test_info_style_subtitle() -> Result<()> {
let repo = repo("basic_repo.sh")?;
let config: CliOptions = CliOptions {
input: repo.path().to_path_buf(),
text_formatting: TextForamttingCliOptions {
text_colors: vec![0, 0, 0, 0, 15, 0],
no_bold: false,
Expand Down
10 changes: 2 additions & 8 deletions src/info/title.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,13 @@ impl std::fmt::Display for Title {
}
}
#[cfg(test)]
#[cfg(feature = "test-utils")]
mod tests {
use super::*;
use crate::utils::repo;
use anyhow::Result;
use gix::{open, Repository, ThreadSafeRepository};
use owo_colors::AnsiColors;

fn repo(name: &str) -> Result<Repository> {
let name = name.to_string();
let repo_path = gix_testtools::scripted_fixture_read_only(name).unwrap();
let safe_repo = ThreadSafeRepository::open_opts(repo_path, open::Options::isolated())?;
Ok(safe_repo.to_thread_local())
}

#[test]
fn test_get_git_username() -> Result<()> {
let repo = repo("basic_repo.sh")?;
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
pub mod cli;
pub mod info;
pub mod ui;
// Provide the git repo setup function for benchmarks, integration tests and
// some unit tests via a library module to avoid code duplication.
#[cfg(feature = "test-utils")]
pub mod utils;
9 changes: 9 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use anyhow::Result;
use gix::{open, Repository, ThreadSafeRepository};

pub fn repo(name: &str) -> Result<Repository> {
let name = name.to_string();
let repo_path = gix_testtools::scripted_fixture_read_only(name).unwrap();
let safe_repo = ThreadSafeRepository::open_opts(repo_path, open::Options::isolated())?;
Ok(safe_repo.to_thread_local())
}
9 changes: 1 addition & 8 deletions tests/repo.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
use anyhow::Result;
use gix::{open, Repository, ThreadSafeRepository};
use onefetch::cli::{CliOptions, TextForamttingCliOptions};
use onefetch::info::{get_work_dir, Info};

fn repo(name: &str) -> Result<Repository> {
let name = name.to_string();
let repo_path = gix_testtools::scripted_fixture_read_only(name).unwrap();
let safe_repo = ThreadSafeRepository::open_opts(repo_path, open::Options::isolated())?;
Ok(safe_repo.to_thread_local())
}
use onefetch::utils::repo;

#[test]
fn test_bare_repo() -> Result<()> {
Expand Down