fix build/clippy warnings and flakey whitespace-sensitive tests

This commit is contained in:
Josh Junon 2024-03-01 13:31:49 +01:00
parent 861a41144e
commit 04ce762dc8
5 changed files with 33 additions and 34 deletions

View File

@ -1,7 +1,6 @@
use std::{collections::HashMap, path}; use std::{collections::HashMap, path};
use anyhow::Context; use anyhow::Context;
use git2::ErrorCode;
use tauri::Manager; use tauri::Manager;
use tracing::instrument; use tracing::instrument;

View File

@ -12,7 +12,7 @@ use crate::{
}; };
use super::{ use super::{
branch::{self, BranchId}, branch::BranchId,
controller::{Controller, ControllerError}, controller::{Controller, ControllerError},
BaseBranch, RemoteBranchFile, BaseBranch, RemoteBranchFile,
}; };

View File

@ -1,5 +1,5 @@
use crate::git::diff; use crate::git::diff;
use anyhow::{Context, Result}; use anyhow::Result;
pub fn hunk_with_context( pub fn hunk_with_context(
hunk_diff: &str, hunk_diff: &str,
@ -143,16 +143,16 @@ mod tests {
) )
.unwrap(); .unwrap();
let expected = r#"@@ -5,7 +5,7 @@ let expected = r#"@@ -5,7 +5,7 @@
[features] [features]
default = ["serde", "rusqlite"] default = ["serde", "rusqlite"]
-serde = ["dep:serde", "uuid/serde"] -serde = ["dep:serde", "uuid/serde"]
+SERDE = ["dep:serde", "uuid/serde"] +SERDE = ["dep:serde", "uuid/serde"]
rusqlite = ["dep:rusqlite"] rusqlite = ["dep:rusqlite"]
[dependencies] [dependencies]
"#; "#;
assert_eq!(with_ctx.diff, expected); assert_eq!(with_ctx.diff.replace("\n \n", "\n\n"), expected);
assert_eq!(with_ctx.old_start, 5); assert_eq!(with_ctx.old_start, 5);
assert_eq!(with_ctx.old_lines, 7); assert_eq!(with_ctx.old_lines, 7);
assert_eq!(with_ctx.new_start, 5); assert_eq!(with_ctx.new_start, 5);
@ -176,14 +176,14 @@ mod tests {
) )
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
with_ctx.diff, with_ctx.diff.replace("\n \n", "\n\n"),
r#"@@ -1,5 +1,5 @@ r#"@@ -1,5 +1,5 @@
[package] [package]
-name = "gitbutler-core" -name = "gitbutler-core"
+NAME = "gitbutler-core" +NAME = "gitbutler-core"
version = "0.0.0" version = "0.0.0"
edition = "2021" edition = "2021"
"# "#
); );
assert_eq!(with_ctx.old_start, 1); assert_eq!(with_ctx.old_start, 1);
@ -209,7 +209,7 @@ mod tests {
) )
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
with_ctx.diff, with_ctx.diff.replace("\n \n", "\n\n"),
r#"@@ -1,4 +1,4 @@ r#"@@ -1,4 +1,4 @@
-[package] -[package]
+[PACKAGE] +[PACKAGE]
@ -241,9 +241,9 @@ mod tests {
) )
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
with_ctx.diff, with_ctx.diff.replace("\n \n", "\n\n"),
r#"@@ -10,5 +10,5 @@ r#"@@ -10,5 +10,5 @@
[dependencies] [dependencies]
rusqlite = { workspace = true, optional = true } rusqlite = { workspace = true, optional = true }
-serde = { workspace = true, optional = true } -serde = { workspace = true, optional = true }
@ -277,9 +277,9 @@ mod tests {
) )
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
with_ctx.diff, with_ctx.diff.replace("\n \n", "\n\n"),
r#"@@ -5,7 +5,10 @@ r#"@@ -5,7 +5,10 @@
[features] [features]
default = ["serde", "rusqlite"] default = ["serde", "rusqlite"]
-serde = ["dep:serde", "uuid/serde"] -serde = ["dep:serde", "uuid/serde"]
@ -288,7 +288,7 @@ mod tests {
+three +three
+four +four
rusqlite = ["dep:rusqlite"] rusqlite = ["dep:rusqlite"]
[dependencies] [dependencies]
"# "#
); );
@ -317,16 +317,16 @@ mod tests {
) )
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
with_ctx.diff, with_ctx.diff.replace("\n \n", "\n\n"),
r#"@@ -4,9 +4,7 @@ r#"@@ -4,9 +4,7 @@
edition = "2021" edition = "2021"
[features] [features]
-default = ["serde", "rusqlite"] -default = ["serde", "rusqlite"]
-serde = ["dep:serde", "uuid/serde"] -serde = ["dep:serde", "uuid/serde"]
-rusqlite = ["dep:rusqlite"] -rusqlite = ["dep:rusqlite"]
+foo = ["foo"] +foo = ["foo"]
[dependencies] [dependencies]
rusqlite = { workspace = true, optional = true } rusqlite = { workspace = true, optional = true }
"# "#
@ -381,7 +381,7 @@ mod tests {
diff::ChangeType::Added, diff::ChangeType::Added,
) )
.unwrap(); .unwrap();
assert_eq!(with_ctx.diff, hunk_diff); assert_eq!(with_ctx.diff.replace("\n \n", "\n\n"), hunk_diff);
assert_eq!(with_ctx.old_start, 1); assert_eq!(with_ctx.old_start, 1);
assert_eq!(with_ctx.old_lines, 14); assert_eq!(with_ctx.old_lines, 14);
assert_eq!(with_ctx.new_start, 0); assert_eq!(with_ctx.new_start, 0);
@ -406,7 +406,7 @@ mod tests {
diff::ChangeType::Added, diff::ChangeType::Added,
) )
.unwrap(); .unwrap();
assert_eq!(with_ctx.diff, hunk_diff); assert_eq!(with_ctx.diff.replace("\n \n", "\n\n"), hunk_diff);
assert_eq!(with_ctx.old_start, 0); assert_eq!(with_ctx.old_start, 0);
assert_eq!(with_ctx.old_lines, 0); assert_eq!(with_ctx.old_lines, 0);
assert_eq!(with_ctx.new_start, 1); assert_eq!(with_ctx.new_start, 1);
@ -438,10 +438,10 @@ mod tests {
+two +two
+three +three
rusqlite = ["dep:rusqlite"] rusqlite = ["dep:rusqlite"]
[dependencies] [dependencies]
"#; "#;
assert_eq!(with_ctx.diff, expected); assert_eq!(with_ctx.diff.replace("\n \n", "\n\n"), expected);
assert_eq!(with_ctx.old_start, 6); assert_eq!(with_ctx.old_start, 6);
assert_eq!(with_ctx.old_lines, 6); assert_eq!(with_ctx.old_lines, 6);
assert_eq!(with_ctx.new_start, 6); assert_eq!(with_ctx.new_start, 6);
@ -473,10 +473,10 @@ mod tests {
+two +two
+three +three
rusqlite = ["dep:rusqlite"] rusqlite = ["dep:rusqlite"]
[dependencies] [dependencies]
"#; "#;
assert_eq!(with_ctx.diff, expected); assert_eq!(with_ctx.diff.replace("\n \n", "\n\n"), expected);
assert_eq!(with_ctx.old_start, 6); assert_eq!(with_ctx.old_start, 6);
assert_eq!(with_ctx.old_lines, 6); assert_eq!(with_ctx.old_lines, 6);
assert_eq!(with_ctx.new_start, 10); assert_eq!(with_ctx.new_start, 10);
@ -492,12 +492,12 @@ mod tests {
"#; "#;
let expected = r#"@@ -4,9 +4,6 @@ let expected = r#"@@ -4,9 +4,6 @@
edition = "2021" edition = "2021"
[features] [features]
-default = ["serde", "rusqlite"] -default = ["serde", "rusqlite"]
-serde = ["dep:serde", "uuid/serde"] -serde = ["dep:serde", "uuid/serde"]
-rusqlite = ["dep:rusqlite"] -rusqlite = ["dep:rusqlite"]
[dependencies] [dependencies]
rusqlite = { workspace = true, optional = true } rusqlite = { workspace = true, optional = true }
"#; "#;
@ -511,7 +511,7 @@ mod tests {
diff::ChangeType::Added, diff::ChangeType::Added,
) )
.unwrap(); .unwrap();
assert!(with_ctx.diff == expected); assert_eq!(with_ctx.diff.replace("\n \n", "\n\n"), expected);
assert_eq!(with_ctx.old_start, 4); assert_eq!(with_ctx.old_start, 4);
assert_eq!(with_ctx.old_lines, 9); assert_eq!(with_ctx.old_lines, 9);
assert_eq!(with_ctx.new_start, 4); assert_eq!(with_ctx.new_start, 4);
@ -527,12 +527,12 @@ mod tests {
"#; "#;
let expected = r#"@@ -4,9 +8,6 @@ let expected = r#"@@ -4,9 +8,6 @@
edition = "2021" edition = "2021"
[features] [features]
-default = ["serde", "rusqlite"] -default = ["serde", "rusqlite"]
-serde = ["dep:serde", "uuid/serde"] -serde = ["dep:serde", "uuid/serde"]
-rusqlite = ["dep:rusqlite"] -rusqlite = ["dep:rusqlite"]
[dependencies] [dependencies]
rusqlite = { workspace = true, optional = true } rusqlite = { workspace = true, optional = true }
"#; "#;
@ -546,7 +546,7 @@ mod tests {
diff::ChangeType::Added, diff::ChangeType::Added,
) )
.unwrap(); .unwrap();
assert_eq!(with_ctx.diff, expected); assert_eq!(with_ctx.diff.replace("\n \n", "\n\n"), expected);
assert_eq!(with_ctx.old_start, 4); assert_eq!(with_ctx.old_start, 4);
assert_eq!(with_ctx.old_lines, 9); assert_eq!(with_ctx.old_lines, 9);
assert_eq!(with_ctx.new_start, 8); assert_eq!(with_ctx.new_start, 8);
@ -576,10 +576,10 @@ mod tests {
- -
- @waiting_users = User.where(approved: false).count - @waiting_users = User.where(approved: false).count
end end
def invite def invite
"; ";
assert_eq!(with_ctx.diff, expected); assert_eq!(with_ctx.diff.replace("\n \n", "\n\n"), expected);
assert_eq!(with_ctx.old_start, 8); assert_eq!(with_ctx.old_start, 8);
assert_eq!(with_ctx.old_lines, 8); assert_eq!(with_ctx.old_lines, 8);
assert_eq!(with_ctx.new_start, 8); assert_eq!(with_ctx.new_start, 8);

View File

@ -1628,7 +1628,7 @@ fn test_detect_mergeable_branch() -> Result<()> {
let remotes = let remotes =
list_remote_branches(&gb_repository, &project_repository).expect("failed to list remotes"); list_remote_branches(&gb_repository, &project_repository).expect("failed to list remotes");
let remote1 = &remotes let _remote1 = &remotes
.iter() .iter()
.find(|b| b.name.to_string() == "refs/remotes/origin/remote_branch") .find(|b| b.name.to_string() == "refs/remotes/origin/remote_branch")
.unwrap(); .unwrap();
@ -1640,7 +1640,7 @@ fn test_detect_mergeable_branch() -> Result<()> {
.unwrap()); .unwrap());
// assert_eq!(remote1.commits.len(), 1); // assert_eq!(remote1.commits.len(), 1);
let remote2 = &remotes let _remote2 = &remotes
.iter() .iter()
.find(|b| b.name.to_string() == "refs/remotes/origin/remote_branch2") .find(|b| b.name.to_string() == "refs/remotes/origin/remote_branch2")
.unwrap(); .unwrap();

View File

@ -103,7 +103,7 @@ impl Signature {
let right = right >> SHIFT; let right = right >> SHIFT;
let index = ((left as usize) << BITS) | (right as usize); let index = ((left as usize) << BITS) | (right as usize);
if self_buckets[index] > 0 { if self_buckets[index] > 0 {
self_buckets[index] = self_buckets[index] - 1; self_buckets[index] -= 1;
matching_bigrams += 1; matching_bigrams += 1;
} }
} }