Преглед на файлове

chore: enable rust_unit_test on windows (#1630)

Nathan.fooo преди 2 години
родител
ревизия
17def1ffab

+ 1 - 1
frontend/app_flowy/pubspec.lock

@@ -966,7 +966,7 @@ packages:
       name: reorderables
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "0.5.0"
+    version: "0.5.1"
   rich_clipboard:
     dependency: transitive
     description:

+ 1 - 1
frontend/app_flowy/pubspec.yaml

@@ -77,7 +77,7 @@ dependencies:
   device_info_plus: ^3.2.1
   fluttertoast: ^8.0.9
   table_calendar: ^3.0.5
-  reorderables: ^0.5.0
+  reorderables: ^0.5.1
   linked_scroll_controller: ^0.2.0
   hotkey_manager: ^0.1.7
   fixnum: ^1.0.1

+ 3 - 5
frontend/rust-lib/flowy-codegen/src/dart_event/dart_event.rs

@@ -22,7 +22,7 @@ pub fn gen(crate_name: &str) {
 
     let crate_path = std::fs::canonicalize(".").unwrap().as_path().display().to_string();
     let event_crates = parse_dart_event_files(vec![crate_path]);
-    let event_ast = event_crates.iter().map(parse_event_crate).flatten().collect::<Vec<_>>();
+    let event_ast = event_crates.iter().flat_map(parse_event_crate).collect::<Vec<_>>();
 
     let event_render_ctx = ast_to_event_render_ctx(event_ast.as_ref());
     let mut render_result = DART_IMPORTED.to_owned();
@@ -109,14 +109,14 @@ pub fn parse_event_crate(event_crate: &DartEventCrate) -> Vec<EventASTContext> {
     event_crate
         .event_files
         .iter()
-        .map(|event_file| {
+        .flat_map(|event_file| {
             let file_path = path_string_with_component(&event_crate.crate_path, vec![event_file.as_str()]);
 
             let file_content = read_file(file_path.as_ref()).unwrap();
             let ast = syn::parse_file(file_content.as_ref()).expect("Unable to parse file");
             ast.items
                 .iter()
-                .map(|item| match item {
+                .flat_map(|item| match item {
                     Item::Enum(item_enum) => {
                         let ast_result = ASTResult::new();
                         let attrs = flowy_ast::enum_from_ast(
@@ -135,10 +135,8 @@ pub fn parse_event_crate(event_crate: &DartEventCrate) -> Vec<EventASTContext> {
                     }
                     _ => vec![],
                 })
-                .flatten()
                 .collect::<Vec<_>>()
         })
-        .flatten()
         .collect::<Vec<EventASTContext>>()
 }
 

+ 2 - 2
frontend/rust-lib/flowy-codegen/src/protobuf_file/mod.rs

@@ -87,9 +87,9 @@ fn generate_rust_protobuf_files(
 fn generate_dart_protobuf_files(
     name: &str,
     proto_file_output_path: &str,
-    paths: &Vec<String>,
+    paths: &[String],
     file_names: &Vec<String>,
-    protoc_bin_path: &PathBuf,
+    protoc_bin_path: &Path,
 ) {
     if std::env::var("CARGO_MAKE_WORKING_DIRECTORY").is_err() {
         log::warn!("CARGO_MAKE_WORKING_DIRECTORY was not set, skip generate dart pb");

+ 2 - 2
frontend/rust-lib/flowy-document/Cargo.toml

@@ -18,7 +18,7 @@ lib-dispatch = { path = "../lib-dispatch" }
 flowy-database = { path = "../flowy-database" }
 flowy-revision = { path = "../flowy-revision" }
 flowy-error = { path = "../flowy-error", features = ["collaboration", "ot", "http_server", "serde", "db"] }
-dart-notify = { path = "../dart-notify", features = ["dart"] }
+dart-notify = { path = "../dart-notify" }
 
 diesel = {version = "1.4.8", features = ["sqlite"]}
 diesel_derives = {version = "1.4.1", features = ["sqlite"]}
@@ -59,4 +59,4 @@ flowy-codegen = { path = "../flowy-codegen"}
 sync = []
 cloud_sync = ["sync"]
 flowy_unit_test = ["lib-ot/flowy_unit_test", "flowy-revision/flowy_unit_test"]
-dart = ["flowy-codegen/dart"]
+dart = ["flowy-codegen/dart", "dart-notify/dart"]

+ 2 - 2
frontend/rust-lib/flowy-folder/Cargo.toml

@@ -16,7 +16,7 @@ lib-infra = { path = "../../../shared-lib/lib-infra" }
 flowy-document = { path = "../flowy-document" }
 flowy-database = { path = "../flowy-database" }
 flowy-error = { path = "../flowy-error", features = ["db", "http_server"]}
-dart-notify = { path = "../dart-notify", features = ["dart"] }
+dart-notify = { path = "../dart-notify" }
 lib-dispatch = { path = "../lib-dispatch" }
 flowy-revision = { path = "../flowy-revision" }
 
@@ -50,4 +50,4 @@ default = []
 sync = []
 cloud_sync = ["sync"]
 flowy_unit_test = ["lib-ot/flowy_unit_test", "flowy-revision/flowy_unit_test"]
-dart = ["flowy-codegen/dart"]
+dart = ["flowy-codegen/dart", "dart-notify/dart"]

+ 2 - 2
frontend/rust-lib/flowy-grid/Cargo.toml

@@ -7,7 +7,7 @@ edition = "2021"
 
 [dependencies]
 lib-dispatch = { path = "../lib-dispatch" }
-dart-notify = { path = "../dart-notify", features = ["dart"] }
+dart-notify = { path = "../dart-notify" }
 flowy-revision = { path = "../flowy-revision" }
 flowy-task= { path = "../flowy-task" }
 flowy-error = { path = "../flowy-error", features = ["db"]}
@@ -56,5 +56,5 @@ flowy-codegen = { path = "../flowy-codegen"}
 
 [features]
 default = []
-dart = ["flowy-codegen/dart"]
+dart = ["flowy-codegen/dart", "dart-notify/dart"]
 flowy_unit_test = ["flowy-revision/flowy_unit_test"]

+ 1 - 1
frontend/rust-lib/flowy-grid/src/services/field/type_options/text_type_option/text_type_option.rs

@@ -69,7 +69,7 @@ impl TypeOptionTransform for RichTextTypeOptionPB {
         {
             Some(stringify_cell_data(cell_str.to_owned(), decoded_field_type, decoded_field_type, field_rev).into())
         } else {
-            StrCellData::from_cell_str(&cell_str).ok()
+            StrCellData::from_cell_str(cell_str).ok()
         }
     }
 }

+ 3 - 3
frontend/rust-lib/flowy-grid/tests/grid/field_test/test.rs

@@ -206,7 +206,7 @@ async fn grid_switch_from_multi_select_to_text_test() {
     let mut test = GridFieldTest::new().await;
     let field_rev = test.get_first_field_rev(FieldType::MultiSelect).clone();
 
-    let mut multi_select_type_option = test.get_multi_select_type_option(&field_rev.id);
+    let multi_select_type_option = test.get_multi_select_type_option(&field_rev.id);
 
     let script_switch_field = vec![SwitchToField {
         field_id: field_rev.id.clone(),
@@ -221,8 +221,8 @@ async fn grid_switch_from_multi_select_to_text_test() {
         from_field_type: FieldType::MultiSelect,
         expected_content: format!(
             "{},{}",
-            multi_select_type_option.get_mut(0).unwrap().name.to_string(),
-            multi_select_type_option.get_mut(1).unwrap().name.to_string()
+            multi_select_type_option.get(0).unwrap().name,
+            multi_select_type_option.get(1).unwrap().name
         ),
     }];
 

+ 1 - 1
frontend/rust-lib/flowy-revision/src/rev_persistence.rs

@@ -364,7 +364,7 @@ impl<C> RevisionMemoryCacheDelegate for Arc<dyn RevisionDiskCache<C, Error = Flo
     fn receive_ack(&self, object_id: &str, rev_id: i64) {
         let changeset = RevisionChangeset {
             object_id: object_id.to_string(),
-            rev_id: rev_id.into(),
+            rev_id,
             state: RevisionState::Ack,
         };
         match self.update_revision_record(vec![changeset]) {

+ 2 - 2
frontend/rust-lib/flowy-user/Cargo.toml

@@ -11,7 +11,7 @@ flowy-database = { path = "../flowy-database" }
 flowy-error = { path = "../flowy-error", features = ["db", "http_server"] }
 
 lib-infra = { path = "../../../shared-lib/lib-infra" }
-dart-notify = { path = "../dart-notify", features = ["dart"] }
+dart-notify = { path = "../dart-notify" }
 lib-dispatch = { path = "../lib-dispatch" }
 
 tracing = { version = "0.1", features = ["log"] }
@@ -45,7 +45,7 @@ rand_core = "0.6.3"
 rand = "0.8.5"
 
 [features]
-dart = ["flowy-codegen/dart"]
+dart = ["flowy-codegen/dart", "dart-notify/dart"]
 
 [build-dependencies]
 flowy-codegen = { path = "../flowy-codegen"}

+ 6 - 1
frontend/rust-lib/flowy-user/src/services/database.rs

@@ -4,6 +4,7 @@ use flowy_database::{schema::user_table, DBConnection, Database};
 use flowy_error::{ErrorCode, FlowyError};
 use lazy_static::lazy_static;
 use parking_lot::RwLock;
+use std::path::PathBuf;
 use std::{collections::HashMap, sync::Arc, time::Duration};
 
 pub struct UserDB {
@@ -34,7 +35,11 @@ impl UserDB {
             Some(database) => return Ok(database.get_pool()),
         }
 
-        let dir = format!("{}/{}", self.db_dir, user_id);
+        let mut dir = PathBuf::new();
+        dir.push(&self.db_dir);
+        dir.push(user_id);
+        let dir = dir.to_str().unwrap().to_owned();
+
         tracing::trace!("open user db {} at path: {}", user_id, dir);
         let db = flowy_database::init(&dir).map_err(|e| {
             log::error!("open user: {} db failed, {:?}", user_id, e);

+ 6 - 12
frontend/scripts/makefile/tests.toml

@@ -1,21 +1,15 @@
 
-[tasks.dart_unit_test.macos]
-description = "Run flutter unit tests"
-script = '''
-cargo make --profile test-macos dart_unit_test_inner
-'''
-
-[tasks.dart_unit_test.linux]
-description = "Run flutter unit tests"
+[tasks.dart_unit_test]
 script = '''
-cargo make --profile test-linux dart_unit_test_inner
+cargo make dart_unit_test_inner
 '''
+script_runner = "@shell"
 
 [tasks.dart_unit_test.windows]
-description = "Run flutter unit tests"
 script = '''
 cargo make --profile test-windows dart_unit_test_inner
 '''
+script_runner = "@shell"
 
 [tasks.dart_unit_test_inner]
 dependencies = ["build-test-lib"]
@@ -32,14 +26,14 @@ run_task = { name = ["rust_lib_unit_test", "shared_lib_unit_test"] }
 description = "Run rust-lib unit tests"
 script = '''
 cd rust-lib
-RUST_LOG=info cargo test --no-default-features --features="sync"
+cargo test --no-default-features --features="sync"
 '''
 
 [tasks.shared_lib_unit_test]
 description = "Run shared-lib unit test"
 script = '''
 cd ../shared-lib
-RUST_LOG=info cargo test --no-default-features
+cargo test --no-default-features
 '''
 
 [tasks.check_grcov]