From eb17137bf2ee3d354264ea7a9c8bd820f0c551da Mon Sep 17 00:00:00 2001 From: Nikita Galaiko Date: Fri, 13 Oct 2023 14:54:44 +0200 Subject: [PATCH 1/3] make clippy check test code --- .github/workflows/push.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml index a6d56b366..4ba7632fc 100644 --- a/.github/workflows/push.yaml +++ b/.github/workflows/push.yaml @@ -79,5 +79,5 @@ jobs: - uses: ./.github/actions/init-env-rust - uses: ./.github/actions/init-env-node - run: pnpm build - - run: cargo clippy --all-features + - run: cargo clippy --all-features --tests - run: cargo test --locked From de4942c945a5b0869afd1c9fffa13b9336d81c0d Mon Sep 17 00:00:00 2001 From: Nikita Galaiko Date: Fri, 13 Oct 2023 15:33:18 +0200 Subject: [PATCH 2/3] fix clippy in tests --- packages/tauri/src/database/mod.rs | 2 +- packages/tauri/src/dedup.rs | 11 +-- packages/tauri/src/deltas/document.rs | 6 +- packages/tauri/src/reader.rs | 36 ++++--- packages/tauri/src/search/searcher_test.rs | 27 +++--- packages/tauri/src/test_utils.rs | 3 +- .../virtual_branches/branch/file_ownership.rs | 2 +- .../tauri/src/virtual_branches/branch/hunk.rs | 14 ++- .../src/virtual_branches/branch/ownership.rs | 8 +- .../src/virtual_branches/branch/reader.rs | 2 +- .../src/virtual_branches/branch/writer.rs | 4 +- .../src/virtual_branches/target/reader.rs | 2 +- packages/tauri/src/virtual_branches/tests.rs | 94 +++++++++---------- .../tauri/src/watcher/dispatchers/tick.rs | 9 +- .../watcher/handlers/fetch_gitbutler_data.rs | 10 +- .../src/watcher/handlers/tick_handler.rs | 18 ++-- packages/tauri/src/zip/mod.rs | 2 +- 17 files changed, 110 insertions(+), 140 deletions(-) diff --git a/packages/tauri/src/database/mod.rs b/packages/tauri/src/database/mod.rs index d14d4a970..83fd9bfe0 100644 --- a/packages/tauri/src/database/mod.rs +++ b/packages/tauri/src/database/mod.rs @@ -86,7 +86,7 @@ mod tests { let mut rows = stmt.query([]).unwrap(); let row = rows.next().unwrap().unwrap(); let id: i32 = row.get(0).unwrap(); - assert_eq!(id, 1); + assert_eq!(id, 1_i32); Ok(()) }) .unwrap(); diff --git a/packages/tauri/src/dedup.rs b/packages/tauri/src/dedup.rs index 3568bd1a5..863cf479a 100644 --- a/packages/tauri/src/dedup.rs +++ b/packages/tauri/src/dedup.rs @@ -30,7 +30,7 @@ pub fn dedup_fmt(existing: &[&str], new: &str, separator: &str) -> String { #[test] fn test_dedup() { - vec![ + for (existing, new, expected) in [ (vec!["foo", "foo 2"], "foo", "foo 1"), (vec!["foo", "foo 1", "foo 2"], "foo", "foo 3"), (vec!["foo", "foo 1", "foo 2"], "foo 1", "foo 1 1"), @@ -38,10 +38,7 @@ fn test_dedup() { (vec!["foo", "foo 1", "foo 2"], "foo 3", "foo 3"), (vec!["foo 2"], "foo", "foo"), (vec!["foo", "foo 1", "foo 2", "foo 4"], "foo", "foo 3"), - ] - .iter() - .enumerate() - .for_each(|(i, (existing, new, expected))| { - assert_eq!(dedup(existing, new), expected.to_string(), "test {}", i + 1); - }); + ] { + assert_eq!(dedup(&existing, new), expected.to_string()); + } } diff --git a/packages/tauri/src/deltas/document.rs b/packages/tauri/src/deltas/document.rs index 505f94826..d01f7dc2a 100644 --- a/packages/tauri/src/deltas/document.rs +++ b/packages/tauri/src/deltas/document.rs @@ -342,10 +342,10 @@ mod tests { #[test] fn test_unicode() { - let latest = reader::Content::UTF8("🌚".to_string()); - let current = reader::Content::UTF8("🌝".to_string()); + let latest = reader::Content::UTF8("\u{1f31a}".to_string()); + let current = reader::Content::UTF8("\u{1f31d}".to_string()); let mut document = Document::new(Some(&latest), vec![]).unwrap(); document.update(Some(¤t)).unwrap(); - assert_eq!(document.to_string(), "🌝"); + assert_eq!(document.to_string(), "\u{1f31d}"); } } diff --git a/packages/tauri/src/reader.rs b/packages/tauri/src/reader.rs index a3022e0e4..c0ac502b1 100644 --- a/packages/tauri/src/reader.rs +++ b/packages/tauri/src/reader.rs @@ -330,7 +330,7 @@ mod tests { fn test_directory_reader_is_dir() -> Result<()> { let dir = test_utils::temp_dir(); let reader = DirReader::open(dir.clone()); - std::fs::create_dir(dir.join("dir"))?; + std::fs::create_dir_all(dir.join("dir"))?; std::fs::write(dir.join("dir/test.txt"), "test")?; assert!(reader.is_dir(path::Path::new("."))); assert!(reader.is_dir(path::Path::new("dir"))); @@ -346,7 +346,7 @@ mod tests { let file_path = path::Path::new("test.txt"); std::fs::write(dir.join(file_path), "test")?; - let reader = DirReader::open(dir.to_path_buf()); + let reader = DirReader::open(dir.clone()); assert_eq!(reader.read(file_path)?, Content::UTF8("test".to_string())); Ok(()) @@ -356,7 +356,7 @@ mod tests { fn test_commit_reader_is_dir() -> Result<()> { let repository = test_utils::test_repository(); - std::fs::create_dir(repository.path().parent().unwrap().join("dir"))?; + std::fs::create_dir_all(repository.path().parent().unwrap().join("dir"))?; std::fs::write( repository.path().parent().unwrap().join("dir/test.txt"), "test", @@ -392,10 +392,10 @@ mod tests { let dir = test_utils::temp_dir(); std::fs::write(dir.join("test1.txt"), "test")?; - std::fs::create_dir(dir.join("dir"))?; + std::fs::create_dir_all(dir.join("dir"))?; std::fs::write(dir.join("dir").join("test.txt"), "test")?; - let reader = DirReader::open(dir.to_path_buf()); + let reader = DirReader::open(dir.clone()); let files = reader.list_files(path::Path::new("dir"))?; assert_eq!(files.len(), 1); assert!(files.contains(&path::Path::new("test.txt").to_path_buf())); @@ -408,10 +408,10 @@ mod tests { let dir = test_utils::temp_dir(); std::fs::write(dir.join("test.txt"), "test")?; - std::fs::create_dir(dir.join("dir"))?; + std::fs::create_dir_all(dir.join("dir"))?; std::fs::write(dir.join("dir").join("test.txt"), "test")?; - let reader = DirReader::open(dir.to_path_buf()); + let reader = DirReader::open(dir.clone()); let files = reader.list_files(path::Path::new(""))?; assert_eq!(files.len(), 2); assert!(files.contains(&path::Path::new("test.txt").to_path_buf())); @@ -428,7 +428,7 @@ mod tests { repository.path().parent().unwrap().join("test1.txt"), "test", )?; - std::fs::create_dir(repository.path().parent().unwrap().join("dir"))?; + std::fs::create_dir_all(repository.path().parent().unwrap().join("dir"))?; std::fs::write( repository .path() @@ -456,7 +456,7 @@ mod tests { let repository = test_utils::test_repository(); std::fs::write(repository.path().parent().unwrap().join("test.txt"), "test")?; - std::fs::create_dir(repository.path().parent().unwrap().join("dir"))?; + std::fs::create_dir_all(repository.path().parent().unwrap().join("dir"))?; std::fs::write( repository .path() @@ -486,7 +486,7 @@ mod tests { std::fs::write(dir.join("test.txt"), "test")?; - let reader = DirReader::open(dir.to_path_buf()); + let reader = DirReader::open(dir.clone()); assert!(reader.exists(path::Path::new("test.txt"))); assert!(!reader.exists(path::Path::new("test2.txt"))); @@ -512,29 +512,25 @@ mod tests { #[test] fn test_from_bytes() { - vec![ + for (bytes, expected) in [ ("test".as_bytes(), Content::UTF8("test".to_string())), (&[0, 159, 146, 150, 159, 146, 150], Content::Binary), - ] - .into_iter() - .for_each(|(bytes, expected)| { + ] { assert_eq!(Content::from(bytes), expected); - }); + } } #[test] fn test_serialize_content() { - vec![ + for (content, expected) in [ ( Content::UTF8("test".to_string()), r#"{"type":"utf8","value":"test"}"#, ), (Content::Binary, r#"{"type":"binary"}"#), (Content::Large, r#"{"type":"large"}"#), - ] - .into_iter() - .for_each(|(content, expected)| { + ] { assert_eq!(serde_json::to_string(&content).unwrap(), expected); - }); + } } } diff --git a/packages/tauri/src/search/searcher_test.rs b/packages/tauri/src/search/searcher_test.rs index c944a381b..f7f0af007 100644 --- a/packages/tauri/src/search/searcher_test.rs +++ b/packages/tauri/src/search/searcher_test.rs @@ -35,17 +35,18 @@ fn test_sorted_by_timestamp() -> Result<()> { let searcher = super::Searcher::try_from(&suite.local_app_data).unwrap(); - let write_result = searcher.index_session(&gb_repository, &session.unwrap()); - assert!(write_result.is_ok()); + searcher + .index_session(&gb_repository, &session.unwrap()) + .unwrap(); - let search_result = searcher.search(&super::Query { - project_id: gb_repository.get_project_id().to_string(), - q: "hello".to_string(), - limit: 10, - offset: None, - }); - assert!(search_result.is_ok()); - let search_result = search_result.unwrap(); + let search_result = searcher + .search(&super::Query { + project_id: gb_repository.get_project_id().to_string(), + q: "hello".to_string(), + limit: 10, + offset: None, + }) + .unwrap(); assert_eq!(search_result.total, 2); assert_eq!(search_result.page[0].index, 1); assert_eq!(search_result.page[1].index, 0); @@ -166,8 +167,7 @@ fn search_by_full_match() -> Result<()> { let searcher = super::Searcher::try_from(&suite.local_app_data).unwrap(); - let write_result = searcher.index_session(&gb_repository, &session); - assert!(write_result.is_ok()); + searcher.index_session(&gb_repository, &session).unwrap(); let result = searcher.search(&super::Query { project_id: gb_repository.get_project_id().to_string(), @@ -208,8 +208,7 @@ fn search_by_diff() -> Result<()> { let searcher = super::Searcher::try_from(&suite.local_app_data).unwrap(); - let write_result = searcher.index_session(&gb_repository, &session); - assert!(write_result.is_ok()); + searcher.index_session(&gb_repository, &session)?; let result = searcher.search(&super::Query { project_id: gb_repository.get_project_id().to_string(), diff --git a/packages/tauri/src/test_utils.rs b/packages/tauri/src/test_utils.rs index cf4026f62..95065a03d 100644 --- a/packages/tauri/src/test_utils.rs +++ b/packages/tauri/src/test_utils.rs @@ -135,8 +135,7 @@ pub fn temp_dir() -> path::PathBuf { pub fn empty_bare_repository() -> git::Repository { let path = temp_dir(); - let repository = git::Repository::init_bare(path).expect("failed to init repository"); - repository + git::Repository::init_bare(path).expect("failed to init repository") } pub fn test_repository() -> git::Repository { diff --git a/packages/tauri/src/virtual_branches/branch/file_ownership.rs b/packages/tauri/src/virtual_branches/branch/file_ownership.rs index d0a6fa1ad..de59624d8 100644 --- a/packages/tauri/src/virtual_branches/branch/file_ownership.rs +++ b/packages/tauri/src/virtual_branches/branch/file_ownership.rs @@ -184,7 +184,7 @@ mod tests { #[test] fn parse_ownership_no_ranges() { - assert!("foo/bar.rs".parse::().is_err()); + "foo/bar.rs".parse::().unwrap_err(); } #[test] diff --git a/packages/tauri/src/virtual_branches/branch/hunk.rs b/packages/tauri/src/virtual_branches/branch/hunk.rs index 8764afff7..8a634adae 100644 --- a/packages/tauri/src/virtual_branches/branch/hunk.rs +++ b/packages/tauri/src/virtual_branches/branch/hunk.rs @@ -144,7 +144,7 @@ mod tests { #[test] fn parse_invalid() { - assert!("3-2".parse::().is_err()); + "3-2".parse::().unwrap_err(); } #[test] @@ -165,7 +165,7 @@ mod tests { #[test] fn parse_invalid_2() { - assert!("3-2".parse::().is_err()); + "3-2".parse::().unwrap_err(); } #[test] @@ -178,7 +178,7 @@ mod tests { #[test] fn test_eq() { - vec![ + for (a, b, expected) in vec![ ( "1-2".parse::().unwrap(), "1-2".parse::().unwrap(), @@ -219,10 +219,8 @@ mod tests { "2-3-bcd".parse::().unwrap(), false, ), - ] - .iter() - .for_each(|(a, b, expected)| { - assert_eq!(a == b, *expected, "comapring {} and {}", a, b); - }); + ] { + assert_eq!(a == b, expected, "comapring {} and {}", a, b); + } } } diff --git a/packages/tauri/src/virtual_branches/branch/ownership.rs b/packages/tauri/src/virtual_branches/branch/ownership.rs index 0e364b0d0..46f284e54 100644 --- a/packages/tauri/src/virtual_branches/branch/ownership.rs +++ b/packages/tauri/src/virtual_branches/branch/ownership.rs @@ -223,7 +223,7 @@ mod tests { #[test] fn test_equal() { - vec![ + for (a, b, expected) in vec![ ( "src/main.rs:100-200".parse::().unwrap(), "src/main.rs:100-200".parse::().unwrap(), @@ -254,10 +254,8 @@ mod tests { .unwrap(), false, ), - ] - .into_iter() - .for_each(|(a, b, expected)| { + ] { assert_eq!(a == b, expected, "{:#?} == {:#?}", a, b); - }); + } } } diff --git a/packages/tauri/src/virtual_branches/branch/reader.rs b/packages/tauri/src/virtual_branches/branch/reader.rs index 0a35290d2..aa6613aee 100644 --- a/packages/tauri/src/virtual_branches/branch/reader.rs +++ b/packages/tauri/src/virtual_branches/branch/reader.rs @@ -54,7 +54,7 @@ mod tests { Branch { id: BranchId::generate(), name: format!("branch_name_{}", TEST_INDEX.load(Ordering::Relaxed)), - notes: "".to_string(), + notes: String::new(), applied: true, order: TEST_INDEX.load(Ordering::Relaxed), upstream: Some( diff --git a/packages/tauri/src/virtual_branches/branch/writer.rs b/packages/tauri/src/virtual_branches/branch/writer.rs index e3dfac29a..c1b18ce98 100644 --- a/packages/tauri/src/virtual_branches/branch/writer.rs +++ b/packages/tauri/src/virtual_branches/branch/writer.rs @@ -136,7 +136,7 @@ mod tests { Branch { id: BranchId::generate(), name: format!("branch_name_{}", TEST_INDEX.load(Ordering::Relaxed)), - notes: "".to_string(), + notes: String::new(), applied: true, upstream: Some( format!( @@ -227,7 +227,7 @@ mod tests { ); writer.delete(&branch)?; - assert!(fs::read_dir(root).is_err()); + fs::read_dir(root).unwrap(); Ok(()) } diff --git a/packages/tauri/src/virtual_branches/target/reader.rs b/packages/tauri/src/virtual_branches/target/reader.rs index 32628e8fe..32a98f0eb 100644 --- a/packages/tauri/src/virtual_branches/target/reader.rs +++ b/packages/tauri/src/virtual_branches/target/reader.rs @@ -63,7 +63,7 @@ mod tests { branch::Branch { id: BranchId::generate(), name: format!("branch_name_{}", TEST_INDEX.load(Ordering::Relaxed)), - notes: "".to_string(), + notes: String::new(), applied: true, upstream: Some( format!( diff --git a/packages/tauri/src/virtual_branches/tests.rs b/packages/tauri/src/virtual_branches/tests.rs index 3ef10aaf6..aecee41dc 100644 --- a/packages/tauri/src/virtual_branches/tests.rs +++ b/packages/tauri/src/virtual_branches/tests.rs @@ -75,7 +75,6 @@ fn test_commit_on_branch_then_change_file_then_get_status() -> Result<()> { let branches = list_virtual_branches(&gb_repository, &project_repository)?; let branch = &branches[0]; - dbg!(&branch); assert_eq!(branch.files.len(), 1); assert_eq!(branch.commits.len(), 0); @@ -327,7 +326,7 @@ fn test_create_branch_with_ownership() -> Result<()> { let files_by_branch_id = statuses .iter() - .map(|(branch, files)| (branch.id.clone(), files)) + .map(|(branch, files)| (branch.id, files)) .collect::>(); assert_eq!(files_by_branch_id.len(), 2); @@ -434,7 +433,7 @@ fn test_name_to_branch() -> Result<()> { &gb_repository, &project_repository, branch::BranchUpdateRequest { - id: branch1_id.clone(), + id: branch1_id, name: Some("branch1".to_string()), order: Some(1), ..Default::default() @@ -444,18 +443,18 @@ fn test_name_to_branch() -> Result<()> { &gb_repository, &project_repository, branch::BranchUpdateRequest { - id: branch2_id.clone(), + id: branch2_id, name: Some("branch1".to_string()), order: Some(0), ..Default::default() }, ); - assert!(result.is_err()); + result.unwrap_err(); update_branch( &gb_repository, &project_repository, branch::BranchUpdateRequest { - id: branch2_id.clone(), + id: branch2_id, name: Some("branch2".to_string()), order: Some(0), ..Default::default() @@ -501,7 +500,7 @@ fn test_hunk_expantion() -> Result<()> { let files_by_branch_id = statuses .iter() - .map(|(branch, files)| (branch.id.clone(), files)) + .map(|(branch, files)| (branch.id, files)) .collect::>(); assert_eq!(files_by_branch_id.len(), 2); @@ -513,7 +512,7 @@ fn test_hunk_expantion() -> Result<()> { &gb_repository, &project_repository, branch::BranchUpdateRequest { - id: branch1_id.clone(), + id: branch1_id, order: Some(1), ..Default::default() }, @@ -522,7 +521,7 @@ fn test_hunk_expantion() -> Result<()> { &gb_repository, &project_repository, branch::BranchUpdateRequest { - id: branch2_id.clone(), + id: branch2_id, order: Some(0), ..Default::default() }, @@ -538,7 +537,7 @@ fn test_hunk_expantion() -> Result<()> { get_status_by_branch(&gb_repository, &project_repository).expect("failed to get status"); let files_by_branch_id = statuses .iter() - .map(|(branch, files)| (branch.id.clone(), files)) + .map(|(branch, files)| (branch.id, files)) .collect::>(); assert_eq!(files_by_branch_id.len(), 2); @@ -594,7 +593,7 @@ fn test_get_status_files_by_branch() -> Result<()> { get_status_by_branch(&gb_repository, &project_repository).expect("failed to get status"); let files_by_branch_id = statuses .iter() - .map(|(branch, files)| (branch.id.clone(), files)) + .map(|(branch, files)| (branch.id, files)) .collect::>(); assert_eq!(files_by_branch_id.len(), 2); @@ -754,7 +753,7 @@ fn test_move_hunks_multiple_sources() -> Result<()> { let files_by_branch_id = statuses .iter() - .map(|(branch, files)| (branch.id.clone(), files)) + .map(|(branch, files)| (branch.id, files)) .collect::>(); assert_eq!(files_by_branch_id.len(), 3); @@ -768,7 +767,7 @@ fn test_move_hunks_multiple_sources() -> Result<()> { &gb_repository, &project_repository, branch::BranchUpdateRequest { - id: branch3_id.clone(), + id: branch3_id, ownership: Some("test.txt:1-5,11-15".parse()?), ..Default::default() }, @@ -779,7 +778,7 @@ fn test_move_hunks_multiple_sources() -> Result<()> { let files_by_branch_id = statuses .iter() - .map(|(branch, files)| (branch.id.clone(), files)) + .map(|(branch, files)| (branch.id, files)) .collect::>(); assert_eq!(files_by_branch_id.len(), 3); @@ -828,7 +827,7 @@ fn test_move_hunks_partial_explicitly() -> Result<()> { get_status_by_branch(&gb_repository, &project_repository).expect("failed to get status"); let files_by_branch_id = statuses .iter() - .map(|(branch, files)| (branch.id.clone(), files)) + .map(|(branch, files)| (branch.id, files)) .collect::>(); assert_eq!(files_by_branch_id.len(), 2); @@ -840,7 +839,7 @@ fn test_move_hunks_partial_explicitly() -> Result<()> { &gb_repository, &project_repository, branch::BranchUpdateRequest { - id: branch2_id.clone(), + id: branch2_id, ownership: Some("test.txt:1-5".parse()?), ..Default::default() }, @@ -851,7 +850,7 @@ fn test_move_hunks_partial_explicitly() -> Result<()> { let files_by_branch_id = statuses .iter() - .map(|(branch, files)| (branch.id.clone(), files)) + .map(|(branch, files)| (branch.id, files)) .collect::>(); assert_eq!(files_by_branch_id.len(), 2); @@ -908,7 +907,6 @@ fn test_add_new_hunk_to_the_end() -> Result<()> { let statuses = get_status_by_branch(&gb_repository, &project_repository).expect("failed to get status"); - dbg!(&statuses); assert!(statuses[0].1[0].hunks[0] .id .starts_with("12-17-b5850d4f66182e6630ed9683dbbc2f0b-")); @@ -1534,7 +1532,7 @@ fn test_update_target_with_conflicts_in_vbranches() -> Result<()> { &gb_repository, &project_repository, branch::BranchUpdateRequest { - id: branch7_id.clone(), + id: branch7_id, name: Some("Situation 7".to_string()), ownership: Some("test.txt:1-5".parse()?), ..Default::default() @@ -1567,7 +1565,7 @@ fn test_update_target_with_conflicts_in_vbranches() -> Result<()> { &gb_repository, &project_repository, branch::BranchUpdateRequest { - id: branch1_id.clone(), + id: branch1_id, name: Some("Situation 1".to_string()), ownership: Some("test.txt:1-5".parse()?), ..Default::default() @@ -1585,7 +1583,7 @@ fn test_update_target_with_conflicts_in_vbranches() -> Result<()> { &gb_repository, &project_repository, branch::BranchUpdateRequest { - id: branch2_id.clone(), + id: branch2_id, name: Some("Situation 2".to_string()), ownership: Some("test.txt:1-5".parse()?), ..Default::default() @@ -1608,7 +1606,7 @@ fn test_update_target_with_conflicts_in_vbranches() -> Result<()> { &gb_repository, &project_repository, branch::BranchUpdateRequest { - id: branch2_id.clone(), + id: branch2_id, ownership: Some("test.txt:1-6".parse()?), ..Default::default() }, @@ -1628,7 +1626,7 @@ fn test_update_target_with_conflicts_in_vbranches() -> Result<()> { &gb_repository, &project_repository, branch::BranchUpdateRequest { - id: branch3_id.clone(), + id: branch3_id, name: Some("Situation 3".to_string()), ownership: Some("test2.txt:1-5".parse()?), ..Default::default() @@ -1645,7 +1643,7 @@ fn test_update_target_with_conflicts_in_vbranches() -> Result<()> { &gb_repository, &project_repository, branch::BranchUpdateRequest { - id: branch5_id.clone(), + id: branch5_id, name: Some("Situation 5".to_string()), ownership: Some("test3.txt:1-4".parse()?), ..Default::default() @@ -1668,7 +1666,7 @@ fn test_update_target_with_conflicts_in_vbranches() -> Result<()> { &gb_repository, &project_repository, branch::BranchUpdateRequest { - id: branch5_id.clone(), + id: branch5_id, ownership: Some("test3.txt:1-5".parse()?), ..Default::default() }, @@ -1683,7 +1681,7 @@ fn test_update_target_with_conflicts_in_vbranches() -> Result<()> { &gb_repository, &project_repository, branch::BranchUpdateRequest { - id: branch4_id.clone(), + id: branch4_id, name: Some("Situation 4".to_string()), ownership: Some("test.txt:1-5".parse()?), ..Default::default() @@ -1699,7 +1697,7 @@ fn test_update_target_with_conflicts_in_vbranches() -> Result<()> { &gb_repository, &project_repository, branch::BranchUpdateRequest { - id: branch6_id.clone(), + id: branch6_id, name: Some("Situation 6".to_string()), ownership: Some("test2.txt:1-5".parse()?), ..Default::default() @@ -1749,7 +1747,7 @@ fn test_update_target_with_conflicts_in_vbranches() -> Result<()> { // 7. applied branch with commits but everything is upstream, delete it // branch7 was integrated and deleted let branch7 = branch_reader.read(&branch7_id); - assert!(branch7.is_err()); + branch7.unwrap_err(); Ok(()) } @@ -1986,7 +1984,7 @@ fn test_apply_unapply_added_deleted_files() -> Result<()> { &gb_repository, &project_repository, branch::BranchUpdateRequest { - id: branch2_id.clone(), + id: branch2_id, ownership: Some("test2.txt:0-0".parse()?), ..Default::default() }, @@ -1995,7 +1993,7 @@ fn test_apply_unapply_added_deleted_files() -> Result<()> { &gb_repository, &project_repository, branch::BranchUpdateRequest { - id: branch3_id.clone(), + id: branch3_id, ownership: Some("test3.txt:1-2".parse()?), ..Default::default() }, @@ -2071,7 +2069,7 @@ fn test_detect_mergeable_branch() -> Result<()> { &gb_repository, &project_repository, branch::BranchUpdateRequest { - id: branch2_id.clone(), + id: branch2_id, ownership: Some("test4.txt:1-3".parse()?), ..Default::default() }, @@ -2651,7 +2649,7 @@ fn test_upstream_integrated_vbranch() -> Result<()> { &gb_repository, &project_repository, branch::BranchUpdateRequest { - id: branch1_id.clone(), + id: branch1_id, name: Some("integrated".to_string()), ownership: Some("test.txt:1-2".parse()?), ..Default::default() @@ -2662,7 +2660,7 @@ fn test_upstream_integrated_vbranch() -> Result<()> { &gb_repository, &project_repository, branch::BranchUpdateRequest { - id: branch2_id.clone(), + id: branch2_id, name: Some("not integrated".to_string()), ownership: Some("test2.txt:1-2".parse()?), ..Default::default() @@ -2673,7 +2671,7 @@ fn test_upstream_integrated_vbranch() -> Result<()> { &gb_repository, &project_repository, branch::BranchUpdateRequest { - id: branch3_id.clone(), + id: branch3_id, name: Some("not committed".to_string()), ownership: Some("test3.txt:1-2".parse()?), ..Default::default() @@ -3197,12 +3195,8 @@ fn tree_to_file_list(repository: &git::Repository, tree: &git::Tree) -> Vec Result<()> { None, None, ); - assert!(result.is_err()); + result.unwrap_err(); // fix the conflict and commit it std::fs::write( @@ -3633,7 +3623,7 @@ fn test_verify_branch_commits_to_integration() -> Result<()> { set_test_target(&gb_repository, &project_repository)?; - assert!(integration::verify_branch(&gb_repository, &project_repository).is_ok()); + integration::verify_branch(&gb_repository, &project_repository).unwrap(); // write two commits let file_path2 = std::path::Path::new("test2.txt"); @@ -3646,7 +3636,7 @@ fn test_verify_branch_commits_to_integration() -> Result<()> { test_utils::commit_all(&project_repository.git_repository); // verify puts commits onto the virtual branch - assert!(integration::verify_branch(&gb_repository, &project_repository).is_ok()); + integration::verify_branch(&gb_repository, &project_repository).unwrap(); // one virtual branch with two commits was created let virtual_branches = list_virtual_branches(&gb_repository, &project_repository)?; @@ -3669,7 +3659,7 @@ fn test_verify_branch_not_integration() -> Result<()> { set_test_target(&gb_repository, &project_repository)?; - assert!(integration::verify_branch(&gb_repository, &project_repository).is_ok()); + integration::verify_branch(&gb_repository, &project_repository).unwrap(); project_repository .git_repository @@ -3948,12 +3938,12 @@ fn test_force_push() { ) .is_err()); - assert!(push( + push( &project_repository, &gb_repository, &branch_id, true, &keys::Key::from(suite.keys.get_or_create().unwrap()), ) - .is_ok()); + .unwrap(); } diff --git a/packages/tauri/src/watcher/dispatchers/tick.rs b/packages/tauri/src/watcher/dispatchers/tick.rs index c21b19e4a..d55a1872f 100644 --- a/packages/tauri/src/watcher/dispatchers/tick.rs +++ b/packages/tauri/src/watcher/dispatchers/tick.rs @@ -78,14 +78,13 @@ mod tests { dispatcher.stop(); }); - let mut count = 0; + let mut count = 0_i32; while let Some(event) = rx.recv().await { - match event { - events::Event::Tick(_, _) => count += 1, - _ => panic!("unexpected event: {:?}", event), + if let events::Event::Tick(_, _) = event { + count += 1_i32; } } - assert!(count >= 4); + assert!(count >= 4_i32); } } diff --git a/packages/tauri/src/watcher/handlers/fetch_gitbutler_data.rs b/packages/tauri/src/watcher/handlers/fetch_gitbutler_data.rs index 727a6600f..a256477ab 100644 --- a/packages/tauri/src/watcher/handlers/fetch_gitbutler_data.rs +++ b/packages/tauri/src/watcher/handlers/fetch_gitbutler_data.rs @@ -188,13 +188,13 @@ mod test { description: None, repository_id: "123".to_string(), git_url: cloud.path().to_str().unwrap().to_string(), - created_at: 0.to_string(), - updated_at: 0.to_string(), + created_at: 0_i32.to_string(), + updated_at: 0_i32.to_string(), sync: true, }; suite.projects.update(&projects::UpdateRequest { - id: project.id.clone(), + id: project.id, api: Some(api_project.clone()), ..Default::default() })?; @@ -212,7 +212,7 @@ mod test { } #[test] - fn test_fetch_fail_no_sync() -> Result<()> { + fn test_fetch_fail_no_sync() { let suite = Suite::default(); let Case { project, .. } = suite.new_case(); @@ -226,7 +226,5 @@ mod test { let res = listener.handle(&project.id, &SystemTime::now()); assert_eq!(&res.unwrap_err().to_string(), "sync disabled"); - - Ok(()) } } diff --git a/packages/tauri/src/watcher/handlers/tick_handler.rs b/packages/tauri/src/watcher/handlers/tick_handler.rs index 9ec3b3649..e78cad9a5 100644 --- a/packages/tauri/src/watcher/handlers/tick_handler.rs +++ b/packages/tauri/src/watcher/handlers/tick_handler.rs @@ -117,7 +117,7 @@ mod tests { #[test] fn test_should_flush() { let now = time::SystemTime::now(); - vec![ + for (start, last, expected) in vec![ (now, now, false), // just created (now - FIVE_MINUTES, now, false), // active ( @@ -132,9 +132,7 @@ mod tests { ), // not active (now - ONE_HOUR, now, true), // almost too old (now - ONE_HOUR - ONE_MILLISECOND, now, true), // too old - ] - .into_iter() - .for_each(|(start, last, expected)| { + ] { let session = sessions::Session { id: SessionId::generate(), hash: None, @@ -146,7 +144,7 @@ mod tests { }, }; assert_eq!(should_flush(&now, &session).unwrap(), expected); - }); + } } } @@ -179,13 +177,13 @@ mod test_handler { description: None, repository_id: "123".to_string(), git_url: cloud.path().to_str().unwrap().to_string(), - created_at: 0.to_string(), - updated_at: 0.to_string(), + created_at: 0_i32.to_string(), + updated_at: 0_i32.to_string(), sync: true, }; suite.projects.update(&projects::UpdateRequest { - id: project.id.clone(), + id: project.id, api: Some(api_project.clone()), ..Default::default() })?; @@ -206,7 +204,7 @@ mod test_handler { } #[test] - fn test_no_fetch_triggered() -> Result<()> { + fn test_no_fetch_triggered() { let suite = Suite::default(); let Case { project, .. } = suite.new_case(); @@ -221,7 +219,5 @@ mod test_handler { assert!(!result .iter() .any(|ev| matches!(ev, events::Event::FetchGitbutlerData(_, _)))); - - Ok(()) } } diff --git a/packages/tauri/src/zip/mod.rs b/packages/tauri/src/zip/mod.rs index 9ac407bb9..c505d3ff5 100644 --- a/packages/tauri/src/zip/mod.rs +++ b/packages/tauri/src/zip/mod.rs @@ -212,7 +212,7 @@ mod tests { let zipper_cache = tempdir().unwrap(); let zipper = Zipper::from(&zipper_cache.path().to_path_buf()); - assert!(zipper.zip(file_path).is_err()); + zipper.zip(file_path).unwrap_err(); } #[test] From cff22fbc66eb16fc0b68f2bae3643ab1547b9c1e Mon Sep 17 00:00:00 2001 From: Nikita Galaiko Date: Fri, 13 Oct 2023 15:54:16 +0200 Subject: [PATCH 3/3] fixup --- packages/tauri/src/virtual_branches/branch/writer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/tauri/src/virtual_branches/branch/writer.rs b/packages/tauri/src/virtual_branches/branch/writer.rs index c1b18ce98..f6bea1cce 100644 --- a/packages/tauri/src/virtual_branches/branch/writer.rs +++ b/packages/tauri/src/virtual_branches/branch/writer.rs @@ -227,7 +227,7 @@ mod tests { ); writer.delete(&branch)?; - fs::read_dir(root).unwrap(); + fs::read_dir(root).unwrap_err(); Ok(()) }