guru/app-misc/onefetch/files/onefetch-2.17.1-fix-missing-git-repo.patch
Lucio Sauer 5500a7cab3
app-misc/onefetch: add 2.17.1
Signed-off-by: Lucio Sauer <watermanpaint@posteo.net>
2023-05-01 17:09:24 +02:00

171 lines
5.3 KiB
Diff

Deduplicate the git repository setup function across integration
tests, unit tests and benchmarking and fix unit tests
test_info_style_info and test_info_style_subtitle which depend
on it.
Enable the corresponding feature "test-utils" by default when
running tests.
https://github.com/o2sh/onefetch/pull/1034
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2481,6 +2481,7 @@ dependencies = [
"insta",
"lazy_static",
"num-format",
+ "onefetch",
"onefetch-ascii",
"onefetch-image",
"onefetch-manifest",
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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"
@@ -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"
@@ -75,3 +81,4 @@ enable-ansi-support = "0.2.1"
[features]
fail-on-deprecated = []
+test-utils = ["gix-testtools"]
--- a/benches/repo.rs
+++ b/benches/repo.rs
@@ -1,11 +1,9 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
-use gix::{open, ThreadSafeRepository};
use onefetch::{cli::CliOptions, info::Info};
+use onefetch::utils::repo;
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()
--- a/src/info/mod.rs
+++ b/src/info/mod.rs
@@ -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;
@@ -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()
@@ -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,
--- a/src/info/title.rs
+++ b/src/info/title.rs
@@ -84,19 +84,13 @@ impl std::fmt::Display for Title {
}
}
#[cfg(test)]
+#[cfg(feature = "test-utils")]
mod tests {
- use super::*;
use anyhow::Result;
- use gix::{open, Repository, ThreadSafeRepository};
+ use crate::utils::repo;
+ use super::*;
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")?;
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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;
--- /dev/null
+++ b/src/utils.rs
@@ -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())
+}
--- a/tests/repo.rs
+++ b/tests/repo.rs
@@ -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<()> {