diff --git a/crates/marine-test-macro-impl/src/errors.rs b/crates/marine-test-macro-impl/src/errors.rs index 9c9361f..f3d9c5e 100644 --- a/crates/marine-test-macro-impl/src/errors.rs +++ b/crates/marine-test-macro-impl/src/errors.rs @@ -16,6 +16,7 @@ use marine_it_parser::ITParserError; use fluence_app_service::AppServiceError; +use fluence_app_service::MarineError; use darling::Error as DarlingError; use syn::Error as SynError; @@ -25,8 +26,8 @@ use std::path::PathBuf; #[derive(Debug, ThisError)] pub enum TestGeneratorError { - #[error("Can't load Wasm modules into Marine: {0}")] - ITParserError(#[from] ITParserError), + #[error("Can't load Wasm module at {0} into Marine: {1}")] + ITParserError(PathBuf, ITParserError), #[error("{0}")] CorruptedITSection(#[from] CorruptedITSection), @@ -34,8 +35,11 @@ pub enum TestGeneratorError { #[error("{0}")] SynError(#[from] SynError), - #[error("Can't load Wasm modules from the provided config: {0}")] - ConfigLoadError(#[from] AppServiceError), + #[error("Can't load Wasm modules from the provided config at {0}: {1}")] + ConfigLoadError(PathBuf, AppServiceError), + + #[error("Can't resolve module {0} path: {1}")] + ModuleResolveError(String, MarineError), #[error("{0}")] AttributesError(#[from] DarlingError), diff --git a/crates/marine-test-macro-impl/src/marine_test/config_utils.rs b/crates/marine-test-macro-impl/src/marine_test/config_utils.rs index ced1ce4..570c470 100644 --- a/crates/marine-test-macro-impl/src/marine_test/config_utils.rs +++ b/crates/marine-test-macro-impl/src/marine_test/config_utils.rs @@ -16,10 +16,12 @@ use crate::{TResult, TestGeneratorError}; +use fluence_app_service::AppServiceConfig; use fluence_app_service::TomlAppServiceConfig; use marine_it_parser::module_it_interface; use marine_it_parser::it_interface::IModuleInterface; +use std::convert::TryInto; use std::path::{PathBuf, Path}; #[derive(Debug, Clone, PartialEq, Eq)] @@ -34,77 +36,47 @@ impl<'m> Module<'m> { } } -pub(crate) struct ConfigWrapper { - pub config: TomlAppServiceConfig, - pub resolved_modules_dir: PathBuf, -} - -pub(crate) fn load_config( - config_path: &str, - modules_dir: Option, - file_path: &Path, -) -> TResult { +pub(crate) fn load_config(config_path: &str, file_path: &Path) -> TResult { let config_path_buf = file_path.join(config_path); - let marine_config = TomlAppServiceConfig::load(config_path_buf)?; - let modules_dir = match resolve_modules_dir(&marine_config, modules_dir) { - Some(modules_dir) => modules_dir, - None => return Err(TestGeneratorError::ModulesDirUnspecified), - }; + let mut marine_config = TomlAppServiceConfig::load(&config_path_buf) + .map_err(|e| TestGeneratorError::ConfigLoadError(config_path_buf.clone(), e))?; - Ok(ConfigWrapper { - config: marine_config, - resolved_modules_dir: modules_dir, - }) + marine_config.toml_marine_config.base_path = config_path_buf + .parent() + .map(PathBuf::from) + .unwrap_or_default(); + + let marine_config = marine_config + .try_into() + .map_err(|e| TestGeneratorError::ConfigLoadError(config_path_buf, e))?; + + Ok(marine_config) } /// Returns all modules the provided config consists of. -pub(super) fn collect_modules<'config>( - config: &'config TomlAppServiceConfig, - modules_dir: &Path, -) -> TResult>> { - let module_paths = collect_module_paths(config, modules_dir); +pub(super) fn collect_modules(config: &AppServiceConfig) -> TResult>> { + let module_paths = collect_module_paths(config)?; module_paths .into_iter() - .map(|(name, path)| module_it_interface(path).map(|interface| Module::new(name, interface))) - .collect::, _>>() - .map_err(Into::into) + .map(|(name, path)| { + module_it_interface(&path) + .map(|interface| Module::new(name, interface)) + .map_err(|e| TestGeneratorError::ITParserError(path.to_owned(), e)) + }) + .collect::>>() } -fn collect_module_paths<'config>( - config: &'config TomlAppServiceConfig, - modules_dir: &Path, -) -> Vec<(&'config str, PathBuf)> { +fn collect_module_paths(config: &AppServiceConfig) -> TResult> { config - .toml_marine_config - .module + .marine_config + .modules_config .iter() .map(|m| { - let module_file_name = m.file_name.as_ref().unwrap_or(&m.name); - let module_file_name = PathBuf::from(module_file_name); - // TODO: is it correct to always have .wasm extension? - let module_path = modules_dir.join(module_file_name).with_extension("wasm"); - - (m.name.as_str(), module_path) + m.get_path(&config.marine_config.modules_dir) + .map(|path| (m.import_name.as_str(), path)) + .map_err(|e| TestGeneratorError::ModuleResolveError(m.import_name.to_owned(), e)) }) - .collect::>() -} - -/// Tries to determine a dir with compiled Wasm modules according to the following rules: -/// - if the modules_dir attribute is specified (by user) it will be chosen, -/// - otherwise if modules_dir is specified in AppService config it will be chosen, -/// - otherwise None will be returned. -pub(super) fn resolve_modules_dir( - config: &TomlAppServiceConfig, - modules_dir: Option, -) -> Option { - match modules_dir { - Some(modules_dir) => Some(PathBuf::from(modules_dir)), - None => config - .toml_marine_config - .modules_dir - .as_ref() - .map(PathBuf::from), - } + .collect::>>() } diff --git a/crates/marine-test-macro-impl/src/marine_test/glue_code_generator.rs b/crates/marine-test-macro-impl/src/marine_test/glue_code_generator.rs index 95bee75..de8ad63 100644 --- a/crates/marine-test-macro-impl/src/marine_test/glue_code_generator.rs +++ b/crates/marine-test-macro-impl/src/marine_test/glue_code_generator.rs @@ -131,16 +131,16 @@ fn generate_test_glue_code_single_service( service: ServiceDescription, test_file_path: PathBuf, ) -> TResult { + marine_test::utils::maybe_warn_about_modules_dir(&service); + let func_item = match item { syn::Item::Fn(func_item) => func_item, _ => return Err(TestGeneratorError::ExpectedFn), }; - let config_wrapper = - config_utils::load_config(&service.config_path, service.modules_dir, &test_file_path)?; - let modules_dir_test_relative = test_file_path.join(&config_wrapper.resolved_modules_dir); - let module_interfaces = - config_utils::collect_modules(&config_wrapper.config, &modules_dir_test_relative)?; + let config = config_utils::load_config(&service.config_path, &test_file_path)?; + + let module_interfaces = config_utils::collect_modules(&config)?; let linked_modules = marine_test::modules_linker::link_modules( module_interfaces .iter() @@ -158,11 +158,8 @@ fn generate_test_glue_code_single_service( let inputs = &signature.inputs; let arg_names = generate_arg_names(inputs.iter())?; let module_ctors = generate_module_ctors(inputs.iter())?; - let app_service_ctor = token_stream_generator::generate_app_service_ctor( - &service.config_path, - &config_wrapper.resolved_modules_dir, - &test_file_path, - )?; + let app_service_ctor = + token_stream_generator::generate_app_service_ctor(&service.config_path, &test_file_path)?; let glue_code = quote! { #[test] fn #name() { @@ -184,7 +181,7 @@ fn generate_test_glue_code_single_service( #original_block } - test_func(#(#arg_names,)*) + test_func(#(#arg_names),*) } }; diff --git a/crates/marine-test-macro-impl/src/marine_test/token_stream_generator.rs b/crates/marine-test-macro-impl/src/marine_test/token_stream_generator.rs index 245b6b7..d17c14f 100644 --- a/crates/marine-test-macro-impl/src/marine_test/token_stream_generator.rs +++ b/crates/marine-test-macro-impl/src/marine_test/token_stream_generator.rs @@ -23,6 +23,7 @@ mod service_generation_utils; use crate::marine_test::config_utils::Module; use crate::marine_test::modules_linker::{LinkedModule, LinkedModules, UseDescription}; use crate::marine_test::utils; +use crate::marine_test::utils::new_ident; use crate::TResult; pub(super) use service_generator::generate_service_definitions; @@ -30,7 +31,6 @@ pub(super) use service_generation_utils::generate_app_service_ctor; use proc_macro2::TokenStream; use quote::quote; -use crate::marine_test::utils::new_ident; /// Generates definitions of modules and records of this modules. /// F.e. for the greeting service the following definitions would be generated: @@ -101,11 +101,11 @@ fn generate_module_definition( #(#module_records)* pub struct #struct_ident { - marine: std::rc::Rc, >, + marine: std::rc::Rc >, } impl #struct_ident { - pub fn new(marine: std::rc::Rc, >) -> Self { + pub fn new(marine: std::rc::Rc, >,) -> Self { Self { marine } } } diff --git a/crates/marine-test-macro-impl/src/marine_test/token_stream_generator/methods_generator_utils.rs b/crates/marine-test-macro-impl/src/marine_test/token_stream_generator/methods_generator_utils.rs index 03aebd4..1a03a58 100644 --- a/crates/marine-test-macro-impl/src/marine_test/token_stream_generator/methods_generator_utils.rs +++ b/crates/marine-test-macro-impl/src/marine_test/token_stream_generator/methods_generator_utils.rs @@ -45,7 +45,7 @@ pub(super) fn generate_module_method( let (cp, func_name) = generate_call_parameters(&cp_setting, signature)?; let module_method = quote! { - pub fn #func_name(&mut self, #(#arguments),* #cp) #output_type { + pub fn #func_name(&mut self #(,#arguments)* #cp) #output_type { #mcall } }; @@ -65,7 +65,7 @@ pub(super) fn generate_module_method_forward( let (cp, func_name) = generate_call_parameters(&cp_setting, signature)?; let module_method = quote! { - pub fn #func_name(&mut self, #(#arguments),* #cp) #output_type { + pub fn #func_name(&mut self #(,#arguments)* #cp) #output_type { #mcall } }; @@ -228,13 +228,7 @@ fn generate_call_parameters( Ok((TokenStream::new(), func_name)) } CallParametersSettings::UserDefined => { - let maybe_comma = if signature.arguments.is_empty() { - TokenStream::new() - } else { - quote! { , } - }; - - let cp = quote! { #maybe_comma cp: marine_rs_sdk_test::CallParameters }; + let cp = quote! { , cp: marine_rs_sdk_test::CallParameters, }; let func_name = format!("{}_cp", signature.name); let func_name = new_ident(&func_name)?; Ok((cp, func_name)) diff --git a/crates/marine-test-macro-impl/src/marine_test/token_stream_generator/record_type_generator.rs b/crates/marine-test-macro-impl/src/marine_test/token_stream_generator/record_type_generator.rs index 6dd0400..28a9dad 100644 --- a/crates/marine-test-macro-impl/src/marine_test/token_stream_generator/record_type_generator.rs +++ b/crates/marine-test-macro-impl/src/marine_test/token_stream_generator/record_type_generator.rs @@ -42,10 +42,10 @@ pub(super) fn generate_records( let fields = prepare_field(record.record_type.fields.iter(), record.records)?; Ok(quote! { - #[derive(Clone, Debug, marine_rs_sdk_test::internal::serde::Serialize, marine_rs_sdk_test::internal::serde::Deserialize)] + #[derive(Clone, Debug, marine_rs_sdk_test::internal::serde::Serialize, marine_rs_sdk_test::internal::serde::Deserialize,)] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct #record_name_ident { - #(pub #fields),* + #(pub #fields,)* } }) } diff --git a/crates/marine-test-macro-impl/src/marine_test/token_stream_generator/service_generation_utils.rs b/crates/marine-test-macro-impl/src/marine_test/token_stream_generator/service_generation_utils.rs index 704d395..9cc6699 100644 --- a/crates/marine-test-macro-impl/src/marine_test/token_stream_generator/service_generation_utils.rs +++ b/crates/marine-test-macro-impl/src/marine_test/token_stream_generator/service_generation_utils.rs @@ -14,13 +14,8 @@ use itertools::Itertools; pub(crate) fn generate_app_service_ctor( config_path: &str, - modules_dir: &Path, test_file_path: &Path, ) -> TResult { - let modules_dir = modules_dir - .to_str() - .ok_or_else(|| TestGeneratorError::InvalidUTF8Path(modules_dir.to_path_buf()))?; - let test_file_path = test_file_path .to_str() .ok_or_else(|| TestGeneratorError::InvalidUTF8Path(test_file_path.to_path_buf()))?; @@ -59,15 +54,18 @@ pub(crate) fn generate_app_service_ctor( } let config_path = module_path.join(#config_path); - let modules_dir = module_path.join(#modules_dir); - let modules_dir = modules_dir.to_str().expect("modules_dir contains invalid UTF8 string"); - let mut __m_generated_marine_config = marine_rs_sdk_test::internal::TomlAppServiceConfig::load(&config_path) - .unwrap_or_else(|e| panic!("app service config located at `{:?}` can't be loaded: {}", config_path, e)); + let mut __m_generated_marine_config = marine_rs_sdk_test::internal::TomlAppServiceConfig::load(&config_path,) + .unwrap_or_else(|e| { + panic!("app service config located at `{:?}` can't be loaded: {}", config_path, e) + } ); __m_generated_marine_config.service_base_dir = Some(tmp_dir); - __m_generated_marine_config.toml_marine_config.modules_dir = Some(std::path::PathBuf::from(modules_dir)); + __m_generated_marine_config.toml_marine_config.base_path = config_path + .parent() + .map(std::path::PathBuf::from) + .unwrap_or_default(); - let marine = marine_rs_sdk_test::internal::AppService::new_with_empty_facade(__m_generated_marine_config, service_id, std::collections::HashMap::new()) + let marine = marine_rs_sdk_test::internal::AppService::new_with_empty_facade(__m_generated_marine_config, service_id, std::collections::HashMap::new(),) .unwrap_or_else(|e| panic!("app service can't be created: {}", e)); let marine = std::rc::Rc::new(std::cell::RefCell::new(marine)); @@ -78,13 +76,10 @@ pub(crate) fn generate_app_service_ctor( pub(super) fn generate_service_definition( service: &ProcessedService, - test_file_path: &Path, linked_facade: &LinkedModule<'_>, file_path_for_app_service: &Path, ) -> TResult { - let modules_dir_test_relative = test_file_path.join(&service.config.resolved_modules_dir); - let modules = - config_utils::collect_modules(&service.config.config, &modules_dir_test_relative)?; + let modules = config_utils::collect_modules(&service.config)?; let linked_modules = modules_linker::link_modules( modules .iter() @@ -106,11 +101,8 @@ pub(super) fn generate_service_definition( let facade_override_ident = new_ident("__facade_override")?; let facade_structs = generate_facade_structs(facade, &facade_override_ident)?; - let app_service_ctor = generate_app_service_ctor( - &service.config_path, - &service.config.resolved_modules_dir, - file_path_for_app_service, - )?; + let app_service_ctor = + generate_app_service_ctor(&service.config_path, file_path_for_app_service)?; let modules_type = generate_modules_type(&modules)?; let service_definition = quote! { diff --git a/crates/marine-test-macro-impl/src/marine_test/token_stream_generator/service_generator.rs b/crates/marine-test-macro-impl/src/marine_test/token_stream_generator/service_generator.rs index 28da15f..8fa08c1 100644 --- a/crates/marine-test-macro-impl/src/marine_test/token_stream_generator/service_generator.rs +++ b/crates/marine-test-macro-impl/src/marine_test/token_stream_generator/service_generator.rs @@ -14,14 +14,17 @@ * limitations under the License. */ -use crate::attributes::{ServiceDescription}; +use crate::attributes::ServiceDescription; use crate::TResult; use crate::TestGeneratorError; -use crate::marine_test::config_utils::{Module, ConfigWrapper, load_config}; -use crate::marine_test::{modules_linker, config_utils}; +use crate::marine_test::config_utils::Module; +use crate::marine_test::config_utils::load_config; +use crate::marine_test::modules_linker; +use crate::marine_test::config_utils; use crate::marine_test::modules_linker::LinkedModules; use super::service_generation_utils::generate_service_definition; +use fluence_app_service::AppServiceConfig; use marine_it_parser::it_interface::IModuleInterface; use proc_macro2::TokenStream; use itertools::Itertools; @@ -43,9 +46,7 @@ pub(crate) fn generate_service_definitions( let service_modules = services .iter() .map(|service| { - let modules_dir_test_relative = file_path.join(&service.config.resolved_modules_dir); - let modules = - config_utils::collect_modules(&service.config.config, &modules_dir_test_relative)?; + let modules = config_utils::collect_modules(&service.config)?; Ok(modules) }) .collect::>>>>()?; @@ -57,7 +58,6 @@ pub(crate) fn generate_service_definitions( // entry with service.name was added in link_services(...), so unwrap is safe generate_service_definition( service, - file_path, link_info.get::(&service.name).unwrap(), file_path_for_app_service, ) @@ -75,7 +75,7 @@ pub(super) fn get_facace<'modules, 'm>( } pub(super) struct ProcessedService { - pub(super) config: ConfigWrapper, + pub(super) config: AppServiceConfig, pub(super) config_path: String, pub(super) name: String, } @@ -86,7 +86,8 @@ impl ProcessedService { name: String, file_path: &Path, ) -> TResult { - let config_wrapper = load_config(&service.config_path, service.modules_dir, file_path)?; + crate::marine_test::utils::maybe_warn_about_modules_dir(&service); + let config_wrapper = load_config(&service.config_path, file_path)?; Ok(Self { config: config_wrapper, diff --git a/crates/marine-test-macro-impl/src/marine_test/utils.rs b/crates/marine-test-macro-impl/src/marine_test/utils.rs index f17fdba..d3f1a7b 100644 --- a/crates/marine-test-macro-impl/src/marine_test/utils.rs +++ b/crates/marine-test-macro-impl/src/marine_test/utils.rs @@ -15,6 +15,8 @@ */ use crate::TResult; +use crate::ServiceDescription; + use marine_it_parser::it_interface::IRecordTypes; use marine_it_parser::it_interface::it::IType; @@ -60,3 +62,11 @@ pub(super) fn itype_to_tokens(itype: &IType, records: &IRecordTypes) -> TResult< Ok(token_stream) } + +pub(crate) fn maybe_warn_about_modules_dir(service: &ServiceDescription) { + if service.modules_dir.is_some() { + println!( + r#"WARNING: #[marine-test] macro attribute "modules_dir" is deprecated. It will not be used by macro. Please specify loading options in config file."#, + ) + } +} diff --git a/crates/marine-test-macro-impl/tests/generation_tests/empty_func/expanded.rs b/crates/marine-test-macro-impl/tests/generation_tests/empty_func/expanded.rs index 56e3cc9..b262588 100644 --- a/crates/marine-test-macro-impl/tests/generation_tests/empty_func/expanded.rs +++ b/crates/marine-test-macro-impl/tests/generation_tests/empty_func/expanded.rs @@ -8,7 +8,7 @@ fn empty_string() { Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct CallParameters { @@ -17,55 +17,55 @@ fn empty_string() { pub service_creator_peer_id: String, pub host_id: String, pub particle_id: String, - pub tetraplets: Vec> + pub tetraplets: Vec>, } #[derive( Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct MountedBinaryResult { pub ret_code: i32, pub error: String, pub stdout: Vec, - pub stderr: Vec + pub stderr: Vec, } #[derive( Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct MountedBinaryStringResult { pub ret_code: i32, pub error: String, pub stdout: String, - pub stderr: String + pub stderr: String, } #[derive( Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct SecurityTetraplet { pub peer_pk: String, pub service_id: String, pub function_name: String, - pub json_path: String + pub json_path: String, } pub struct ModuleInterface { - marine: - std::rc::Rc, >, + marine: std::rc::Rc>, } impl ModuleInterface { pub fn new( marine: std::rc::Rc< - std::cell::RefCell,> + std::cell::RefCell, + >, ) -> Self { Self { marine } } @@ -101,24 +101,24 @@ fn empty_string() { module_path.push(path); } let config_path = module_path.join("Config.toml"); - let modules_dir = module_path.join("artifacts"); - let modules_dir = modules_dir - .to_str() - .expect("modules_dir contains invalid UTF8 string"); let mut __m_generated_marine_config = marine_rs_sdk_test::internal::TomlAppServiceConfig::load( - &config_path + &config_path, ) - .unwrap_or_else(|e| + .unwrap_or_else(|e| { panic!( "app service config located at `{:?}` can't be loaded: {}", config_path, e - )); + ) + }); __m_generated_marine_config.service_base_dir = Some(tmp_dir); - __m_generated_marine_config.toml_marine_config.modules_dir = Some(std::path::PathBuf::from(modules_dir)); + __m_generated_marine_config.toml_marine_config.base_path = config_path + .parent() + .map(std::path::PathBuf::from) + .unwrap_or_default(); let marine = marine_rs_sdk_test::internal::AppService::new_with_empty_facade( __m_generated_marine_config, service_id, - std::collections::HashMap::new() + std::collections::HashMap::new(), ) .unwrap_or_else(|e| panic!("app service can't be created: {}", e)); let marine = std::rc::Rc::new(std::cell::RefCell::new(marine)); diff --git a/crates/marine-test-macro-impl/tests/generation_tests/mounted_binary/expanded.rs b/crates/marine-test-macro-impl/tests/generation_tests/mounted_binary/expanded.rs index 83e8d49..8de91c9 100644 --- a/crates/marine-test-macro-impl/tests/generation_tests/mounted_binary/expanded.rs +++ b/crates/marine-test-macro-impl/tests/generation_tests/mounted_binary/expanded.rs @@ -8,7 +8,7 @@ fn test() { Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct CallParameters { @@ -17,56 +17,55 @@ fn test() { pub service_creator_peer_id: String, pub host_id: String, pub particle_id: String, - pub tetraplets: Vec> + pub tetraplets: Vec>, } #[derive( Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct MountedBinaryResult { pub ret_code: i32, pub error: String, pub stdout: Vec, - pub stderr: Vec + pub stderr: Vec, } #[derive( Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct MountedBinaryStringResult { pub ret_code: i32, pub error: String, pub stdout: String, - pub stderr: String + pub stderr: String, } #[derive( Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct SecurityTetraplet { pub peer_pk: String, pub service_id: String, pub function_name: String, - pub json_path: String + pub json_path: String, } pub struct ModuleInterface { - marine: - std::rc::Rc, >, + marine: std::rc::Rc>, } impl ModuleInterface { pub fn new( marine: std::rc::Rc< std::cell::RefCell, - > + >, ) -> Self { Self { marine } } @@ -88,7 +87,7 @@ fn test() { pub fn download_cp( &mut self, url: String, - cp: marine_rs_sdk_test::CallParameters + cp: marine_rs_sdk_test::CallParameters, ) -> String { let arguments = marine_rs_sdk_test::internal::serde_json::json!([url]); let result = self @@ -133,25 +132,24 @@ fn test() { module_path.push(path); } let config_path = module_path.join("Config.toml"); - let modules_dir = module_path.join("artifacts"); - let modules_dir = modules_dir - .to_str() - .expect("modules_dir contains invalid UTF8 string"); let mut __m_generated_marine_config = marine_rs_sdk_test::internal::TomlAppServiceConfig::load( - &config_path + &config_path, ) - .unwrap_or_else(|e| + .unwrap_or_else(|e| { panic!( "app service config located at `{:?}` can't be loaded: {}", config_path, e ) - ); + }); __m_generated_marine_config.service_base_dir = Some(tmp_dir); - __m_generated_marine_config.toml_marine_config.modules_dir = Some(std::path::PathBuf::from(modules_dir)); + __m_generated_marine_config.toml_marine_config.base_path = config_path + .parent() + .map(std::path::PathBuf::from) + .unwrap_or_default(); let marine = marine_rs_sdk_test::internal::AppService::new_with_empty_facade( __m_generated_marine_config, service_id, - std::collections::HashMap::new() + std::collections::HashMap::new(), ) .unwrap_or_else(|e| panic!("app service can't be created: {}", e)); let marine = std::rc::Rc::new(std::cell::RefCell::new(marine)); @@ -162,5 +160,5 @@ fn test() { let _ = greeting.download("duckduckgo.com"); } } - test_func(greeting,) + test_func(greeting) } diff --git a/crates/marine-test-macro-impl/tests/generation_tests/multi-service-empty_mod/expanded.rs b/crates/marine-test-macro-impl/tests/generation_tests/multi-service-empty_mod/expanded.rs index 7a2a520..7cae447 100644 --- a/crates/marine-test-macro-impl/tests/generation_tests/multi-service-empty_mod/expanded.rs +++ b/crates/marine-test-macro-impl/tests/generation_tests/multi-service-empty_mod/expanded.rs @@ -7,10 +7,10 @@ pub mod tests { pub mod modules { pub mod greeting { #[derive( - Clone, - Debug, - marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + Clone, + Debug, + marine_rs_sdk_test :: internal :: serde :: Serialize, + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct CallParameters { @@ -19,57 +19,57 @@ pub mod tests { pub service_creator_peer_id: String, pub host_id: String, pub particle_id: String, - pub tetraplets: Vec> + pub tetraplets: Vec>, } #[derive( - Clone, - Debug, - marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + Clone, + Debug, + marine_rs_sdk_test :: internal :: serde :: Serialize, + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct MountedBinaryResult { pub ret_code: i32, pub error: String, pub stdout: Vec, - pub stderr: Vec + pub stderr: Vec, } #[derive( - Clone, - Debug, - marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + Clone, + Debug, + marine_rs_sdk_test :: internal :: serde :: Serialize, + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct MountedBinaryStringResult { pub ret_code: i32, pub error: String, pub stdout: String, - pub stderr: String + pub stderr: String, } #[derive( - Clone, - Debug, - marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + Clone, + Debug, + marine_rs_sdk_test :: internal :: serde :: Serialize, + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct SecurityTetraplet { pub peer_pk: String, pub service_id: String, pub function_name: String, - pub json_path: String + pub json_path: String, } pub struct ModuleInterface { marine: std::rc::Rc< - std::cell::RefCell, + std::cell::RefCell >, } impl ModuleInterface { pub fn new( marine: std::rc::Rc< std::cell::RefCell, - > + >, ) -> Self { Self { marine } } @@ -79,10 +79,10 @@ pub mod tests { } pub mod __facade_override { #[derive( - Clone, - Debug, - marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + Clone, + Debug, + marine_rs_sdk_test :: internal :: serde :: Serialize, + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct CallParameters { @@ -91,57 +91,56 @@ pub mod tests { pub service_creator_peer_id: String, pub host_id: String, pub particle_id: String, - pub tetraplets: Vec> + pub tetraplets: Vec>, } #[derive( - Clone, - Debug, - marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + Clone, + Debug, + marine_rs_sdk_test :: internal :: serde :: Serialize, + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct MountedBinaryResult { pub ret_code: i32, pub error: String, pub stdout: Vec, - pub stderr: Vec + pub stderr: Vec, } #[derive( - Clone, - Debug, - marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + Clone, + Debug, + marine_rs_sdk_test :: internal :: serde :: Serialize, + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct MountedBinaryStringResult { pub ret_code: i32, pub error: String, pub stdout: String, - pub stderr: String + pub stderr: String, } #[derive( - Clone, - Debug, - marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + Clone, + Debug, + marine_rs_sdk_test :: internal :: serde :: Serialize, + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct SecurityTetraplet { pub peer_pk: String, pub service_id: String, pub function_name: String, - pub json_path: String + pub json_path: String, } pub struct ModuleInterface { marine: - std::rc::Rc, - >, + std::rc::Rc >, } impl ModuleInterface { pub fn new( marine: std::rc::Rc< std::cell::RefCell, - > + >, ) -> Self { Self { marine } } @@ -180,7 +179,9 @@ pub mod tests { std::fs::create_dir(&tmp_dir) .expect("can't create a directory for service in tmp"); let mut module_path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); - let mut file_path = std::path::Path::new("tests/generation_tests/multi-service-empty_mod").components(); + let mut file_path = + std::path::Path::new("tests/generation_tests/multi-service-empty_mod") + .components(); let mut truncated_file_path = Vec::new(); loop { if module_path.ends_with(file_path.as_path()) { @@ -203,27 +204,25 @@ pub mod tests { module_path.push(path); } let config_path = module_path.join("Config.toml"); - let modules_dir = module_path.join("artifacts"); - let modules_dir = modules_dir - .to_str() - .expect("modules_dir contains invalid UTF8 string"); let mut __m_generated_marine_config = - marine_rs_sdk_test::internal::TomlAppServiceConfig::load(&config_path) - .unwrap_or_else(|e| + marine_rs_sdk_test::internal::TomlAppServiceConfig::load(&config_path,) + .unwrap_or_else(|e| { panic!( "app service config located at `{:?}` can't be loaded: {}", config_path, e ) - ); + }); __m_generated_marine_config.service_base_dir = Some(tmp_dir); - __m_generated_marine_config.toml_marine_config.modules_dir = - Some(std::path::PathBuf::from(modules_dir)); + __m_generated_marine_config.toml_marine_config.base_path = config_path + .parent() + .map(std::path::PathBuf::from) + .unwrap_or_default(); let marine = marine_rs_sdk_test::internal::AppService::new_with_empty_facade( __m_generated_marine_config, service_id, - std::collections::HashMap::new() + std::collections::HashMap::new(), ) - .unwrap_or_else(|e| panic!("app service can't be created: {}", e)); + .unwrap_or_else(|e| panic!("app service can't be created: {}", e)); let marine = std::rc::Rc::new(std::cell::RefCell::new(marine)); let modules = __GeneratedModules::new(marine.clone()); let __facade = __facade_override::ModuleInterface::new(marine.clone()); diff --git a/crates/marine-test-macro-impl/tests/generation_tests/multi-service-multiple/expanded.rs b/crates/marine-test-macro-impl/tests/generation_tests/multi-service-multiple/expanded.rs index 046928a..ddaef19 100644 --- a/crates/marine-test-macro-impl/tests/generation_tests/multi-service-multiple/expanded.rs +++ b/crates/marine-test-macro-impl/tests/generation_tests/multi-service-multiple/expanded.rs @@ -10,7 +10,7 @@ fn test() { Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct CallParameters { @@ -19,57 +19,57 @@ fn test() { pub service_creator_peer_id: String, pub host_id: String, pub particle_id: String, - pub tetraplets: Vec> + pub tetraplets: Vec>, } #[derive( Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct MountedBinaryResult { pub ret_code: i32, pub error: String, pub stdout: Vec, - pub stderr: Vec + pub stderr: Vec, } #[derive( Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct MountedBinaryStringResult { pub ret_code: i32, pub error: String, pub stdout: String, - pub stderr: String + pub stderr: String, } #[derive( Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct SecurityTetraplet { pub peer_pk: String, pub service_id: String, pub function_name: String, - pub json_path: String + pub json_path: String, } pub struct ModuleInterface { marine: std::rc::Rc< - std::cell::RefCell, + std::cell::RefCell >, } impl ModuleInterface { pub fn new( marine: std::rc::Rc< std::cell::RefCell, - > + >, ) -> Self { Self { marine } } @@ -82,7 +82,7 @@ fn test() { Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct CallParameters { @@ -91,57 +91,56 @@ fn test() { pub service_creator_peer_id: String, pub host_id: String, pub particle_id: String, - pub tetraplets: Vec> + pub tetraplets: Vec>, } #[derive( Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct MountedBinaryResult { pub ret_code: i32, pub error: String, pub stdout: Vec, - pub stderr: Vec + pub stderr: Vec, } #[derive( Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct MountedBinaryStringResult { pub ret_code: i32, pub error: String, pub stdout: String, - pub stderr: String + pub stderr: String, } #[derive( Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct SecurityTetraplet { pub peer_pk: String, pub service_id: String, pub function_name: String, - pub json_path: String + pub json_path: String, } pub struct ModuleInterface { marine: - std::rc::Rc, - >, + std::rc::Rc >, } impl ModuleInterface { pub fn new( marine: std::rc::Rc< std::cell::RefCell, - > + >, ) -> Self { Self { marine } } @@ -180,7 +179,9 @@ fn test() { std::fs::create_dir(&tmp_dir) .expect("can't create a directory for service in tmp"); let mut module_path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); - let mut file_path = std::path::Path::new("tests/generation_tests/multi-service-multiple").components(); + let mut file_path = + std::path::Path::new("tests/generation_tests/multi-service-multiple") + .components(); let mut truncated_file_path = Vec::new(); loop { if module_path.ends_with(file_path.as_path()) { @@ -203,25 +204,23 @@ fn test() { module_path.push(path); } let config_path = module_path.join("empty_func/Config.toml"); - let modules_dir = module_path.join("empty_func/artifacts"); - let modules_dir = modules_dir - .to_str() - .expect("modules_dir contains invalid UTF8 string"); let mut __m_generated_marine_config = - marine_rs_sdk_test::internal::TomlAppServiceConfig::load(&config_path) - .unwrap_or_else(|e| + marine_rs_sdk_test::internal::TomlAppServiceConfig::load(&config_path,) + .unwrap_or_else(|e| { panic!( "app service config located at `{:?}` can't be loaded: {}", config_path, e ) - ); + }); __m_generated_marine_config.service_base_dir = Some(tmp_dir); - __m_generated_marine_config.toml_marine_config.modules_dir = - Some(std::path::PathBuf::from(modules_dir)); + __m_generated_marine_config.toml_marine_config.base_path = config_path + .parent() + .map(std::path::PathBuf::from) + .unwrap_or_default(); let marine = marine_rs_sdk_test::internal::AppService::new_with_empty_facade( __m_generated_marine_config, service_id, - std::collections::HashMap::new() + std::collections::HashMap::new(), ) .unwrap_or_else(|e| panic!("app service can't be created: {}", e)); let marine = std::rc::Rc::new(std::cell::RefCell::new(marine)); @@ -242,7 +241,7 @@ fn test() { Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct CallParameters { @@ -251,57 +250,57 @@ fn test() { pub service_creator_peer_id: String, pub host_id: String, pub particle_id: String, - pub tetraplets: Vec> + pub tetraplets: Vec>, } #[derive( Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct MountedBinaryResult { pub ret_code: i32, pub error: String, pub stdout: Vec, - pub stderr: Vec + pub stderr: Vec, } #[derive( Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct MountedBinaryStringResult { pub ret_code: i32, pub error: String, pub stdout: String, - pub stderr: String + pub stderr: String, } #[derive( Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct SecurityTetraplet { pub peer_pk: String, pub service_id: String, pub function_name: String, - pub json_path: String + pub json_path: String, } pub struct ModuleInterface { marine: std::rc::Rc< - std::cell::RefCell, + std::cell::RefCell >, } impl ModuleInterface { pub fn new( marine: std::rc::Rc< std::cell::RefCell, - > + >, ) -> Self { Self { marine } } @@ -323,7 +322,7 @@ fn test() { pub fn download_cp( &mut self, url: String, - cp: marine_rs_sdk_test::CallParameters + cp: marine_rs_sdk_test::CallParameters, ) -> String { let arguments = marine_rs_sdk_test::internal::serde_json::json!([url]); let result = self @@ -347,14 +346,13 @@ fn test() { pub use super::super::empty_func::SecurityTetraplet; pub struct ModuleInterface { marine: - std::rc::Rc, - >, + std::rc::Rc>, } impl ModuleInterface { pub fn new( marine: std::rc::Rc< std::cell::RefCell, - > + >, ) -> Self { Self { marine } } @@ -376,7 +374,7 @@ fn test() { pub fn download_cp( &mut self, url: String, - cp: marine_rs_sdk_test::CallParameters + cp: marine_rs_sdk_test::CallParameters, ) -> String { let arguments = marine_rs_sdk_test::internal::serde_json::json!([url]); let result = self @@ -424,7 +422,9 @@ fn test() { std::fs::create_dir(&tmp_dir) .expect("can't create a directory for service in tmp"); let mut module_path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); - let mut file_path = std::path::Path::new("tests/generation_tests/multi-service-multiple").components(); + let mut file_path = + std::path::Path::new("tests/generation_tests/multi-service-multiple") + .components(); let mut truncated_file_path = Vec::new(); loop { if module_path.ends_with(file_path.as_path()) { @@ -447,25 +447,23 @@ fn test() { module_path.push(path); } let config_path = module_path.join("mounted_binary/Config.toml"); - let modules_dir = module_path.join("mounted_binary/artifacts"); - let modules_dir = modules_dir - .to_str() - .expect("modules_dir contains invalid UTF8 string"); let mut __m_generated_marine_config = - marine_rs_sdk_test::internal::TomlAppServiceConfig::load(&config_path) - .unwrap_or_else(|e| + marine_rs_sdk_test::internal::TomlAppServiceConfig::load(&config_path,) + .unwrap_or_else(|e| { panic!( "app service config located at `{:?}` can't be loaded: {}", config_path, e ) - ); + }); __m_generated_marine_config.service_base_dir = Some(tmp_dir); - __m_generated_marine_config.toml_marine_config.modules_dir = - Some(std::path::PathBuf::from(modules_dir)); + __m_generated_marine_config.toml_marine_config.base_path = config_path + .parent() + .map(std::path::PathBuf::from) + .unwrap_or_default(); let marine = marine_rs_sdk_test::internal::AppService::new_with_empty_facade( __m_generated_marine_config, service_id, - std::collections::HashMap::new() + std::collections::HashMap::new(), ) .unwrap_or_else(|e| panic!("app service can't be created: {}", e)); let marine = std::rc::Rc::new(std::cell::RefCell::new(marine)); @@ -483,7 +481,7 @@ fn test() { pub fn download_cp( &mut self, url: String, - cp: marine_rs_sdk_test::CallParameters + cp: marine_rs_sdk_test::CallParameters, ) -> String { self.__facade.download_cp(url, cp,) } diff --git a/crates/marine-test-macro-impl/tests/generation_tests/multi-service-single/expanded.rs b/crates/marine-test-macro-impl/tests/generation_tests/multi-service-single/expanded.rs index 7d031ed..bb172e7 100644 --- a/crates/marine-test-macro-impl/tests/generation_tests/multi-service-single/expanded.rs +++ b/crates/marine-test-macro-impl/tests/generation_tests/multi-service-single/expanded.rs @@ -10,7 +10,7 @@ fn empty_test() { Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct CallParameters { @@ -19,57 +19,57 @@ fn empty_test() { pub service_creator_peer_id: String, pub host_id: String, pub particle_id: String, - pub tetraplets: Vec> + pub tetraplets: Vec>, } #[derive( Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct MountedBinaryResult { pub ret_code: i32, pub error: String, pub stdout: Vec, - pub stderr: Vec + pub stderr: Vec, } #[derive( Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct MountedBinaryStringResult { pub ret_code: i32, pub error: String, pub stdout: String, - pub stderr: String + pub stderr: String, } #[derive( Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct SecurityTetraplet { pub peer_pk: String, pub service_id: String, pub function_name: String, - pub json_path: String + pub json_path: String, } pub struct ModuleInterface { marine: std::rc::Rc< - std::cell::RefCell, + std::cell::RefCell >, } impl ModuleInterface { pub fn new( marine: std::rc::Rc< std::cell::RefCell, - > + >, ) -> Self { Self { marine } } @@ -82,7 +82,7 @@ fn empty_test() { Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct CallParameters { @@ -91,57 +91,56 @@ fn empty_test() { pub service_creator_peer_id: String, pub host_id: String, pub particle_id: String, - pub tetraplets: Vec> + pub tetraplets: Vec>, } #[derive( Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct MountedBinaryResult { pub ret_code: i32, pub error: String, pub stdout: Vec, - pub stderr: Vec + pub stderr: Vec, } #[derive( Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct MountedBinaryStringResult { pub ret_code: i32, pub error: String, pub stdout: String, - pub stderr: String + pub stderr: String, } #[derive( Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct SecurityTetraplet { pub peer_pk: String, pub service_id: String, pub function_name: String, - pub json_path: String + pub json_path: String, } pub struct ModuleInterface { marine: - std::rc::Rc, - >, + std::rc::Rc>, } impl ModuleInterface { pub fn new( marine: std::rc::Rc< std::cell::RefCell, - > + >, ) -> Self { Self { marine } } @@ -180,7 +179,9 @@ fn empty_test() { std::fs::create_dir(&tmp_dir) .expect("can't create a directory for service in tmp"); let mut module_path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); - let mut file_path = std::path::Path::new("tests/generation_tests/multi-service-single").components(); + let mut file_path = + std::path::Path::new("tests/generation_tests/multi-service-single") + .components(); let mut truncated_file_path = Vec::new(); loop { if module_path.ends_with(file_path.as_path()) { @@ -203,25 +204,23 @@ fn empty_test() { module_path.push(path); } let config_path = module_path.join("empty_func/Config.toml"); - let modules_dir = module_path.join("empty_func/artifacts"); - let modules_dir = modules_dir - .to_str() - .expect("modules_dir contains invalid UTF8 string"); let mut __m_generated_marine_config = - marine_rs_sdk_test::internal::TomlAppServiceConfig::load(&config_path) - .unwrap_or_else(|e| + marine_rs_sdk_test::internal::TomlAppServiceConfig::load(&config_path, ) + .unwrap_or_else(|e| { panic!( "app service config located at `{:?}` can't be loaded: {}", config_path, e ) - ); + }); __m_generated_marine_config.service_base_dir = Some(tmp_dir); - __m_generated_marine_config.toml_marine_config.modules_dir = - Some(std::path::PathBuf::from(modules_dir)); + __m_generated_marine_config.toml_marine_config.base_path = config_path + .parent() + .map(std::path::PathBuf::from) + .unwrap_or_default(); let marine = marine_rs_sdk_test::internal::AppService::new_with_empty_facade( __m_generated_marine_config, service_id, - std::collections::HashMap::new() + std::collections::HashMap::new(), ) .unwrap_or_else(|e| panic!("app service can't be created: {}", e)); let marine = std::rc::Rc::new(std::cell::RefCell::new(marine)); diff --git a/crates/marine-test-macro-impl/tests/generation_tests/multiple_modules/expanded.rs b/crates/marine-test-macro-impl/tests/generation_tests/multiple_modules/expanded.rs index aee9926..5fcfb5d 100644 --- a/crates/marine-test-macro-impl/tests/generation_tests/multiple_modules/expanded.rs +++ b/crates/marine-test-macro-impl/tests/generation_tests/multiple_modules/expanded.rs @@ -8,7 +8,7 @@ fn empty_string() { Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct CallParameters { @@ -17,55 +17,55 @@ fn empty_string() { pub service_creator_peer_id: String, pub host_id: String, pub particle_id: String, - pub tetraplets: Vec> + pub tetraplets: Vec>, } #[derive( Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct MountedBinaryResult { pub ret_code: i32, pub error: String, pub stdout: Vec, - pub stderr: Vec + pub stderr: Vec, } #[derive( Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct MountedBinaryStringResult { pub ret_code: i32, pub error: String, pub stdout: String, - pub stderr: String + pub stderr: String, } #[derive( Clone, Debug, marine_rs_sdk_test :: internal :: serde :: Serialize, - marine_rs_sdk_test :: internal :: serde :: Deserialize + marine_rs_sdk_test :: internal :: serde :: Deserialize, )] #[serde(crate = "marine_rs_sdk_test::internal::serde")] pub struct SecurityTetraplet { pub peer_pk: String, pub service_id: String, pub function_name: String, - pub json_path: String + pub json_path: String, } pub struct ModuleInterface { - marine: std::rc::Rc, >, + marine: std::rc::Rc>, } impl ModuleInterface { pub fn new( marine: std::rc::Rc< std::cell::RefCell, - > + >, ) -> Self { Self { marine } } @@ -87,7 +87,7 @@ fn empty_string() { pub fn greeting_cp( &mut self, name: String, - cp: marine_rs_sdk_test::CallParameters + cp: marine_rs_sdk_test::CallParameters, ) -> String { let arguments = marine_rs_sdk_test::internal::serde_json::json!([name]); let result = self @@ -107,19 +107,19 @@ fn empty_string() { pub use super::greeting::CallParameters; pub use super::greeting::SecurityTetraplet; pub struct ModuleInterface { - marine: std::rc::Rc, >, + marine: std::rc::Rc>, } impl ModuleInterface { pub fn new( marine: std::rc::Rc< std::cell::RefCell, - > + >, ) -> Self { Self { marine } } } impl ModuleInterface { - pub fn call_parameters(&mut self, ) -> String { + pub fn call_parameters(&mut self) -> String { let arguments = marine_rs_sdk_test::internal::serde_json::json!([]); let result = self .marine @@ -139,7 +139,7 @@ fn empty_string() { } pub fn call_parameters_cp( &mut self, - cp: marine_rs_sdk_test::CallParameters + cp: marine_rs_sdk_test::CallParameters, ) -> String { let arguments = marine_rs_sdk_test::internal::serde_json::json!([]); let result = self @@ -153,7 +153,7 @@ fn empty_string() { .expect("the default deserializer shouldn't fail"); result } - pub fn return_string(&mut self,) -> String { + pub fn return_string(&mut self) -> String { let arguments = marine_rs_sdk_test::internal::serde_json::json!([]); let result = self .marine @@ -173,7 +173,7 @@ fn empty_string() { } pub fn return_string_cp( &mut self, - cp: marine_rs_sdk_test::CallParameters + cp: marine_rs_sdk_test::CallParameters, ) -> String { let arguments = marine_rs_sdk_test::internal::serde_json::json!([]); let result = self @@ -187,7 +187,7 @@ fn empty_string() { .expect("the default deserializer shouldn't fail"); result } - pub fn test_array_refs(&mut self, ) -> Vec { + pub fn test_array_refs(&mut self) -> Vec { let arguments = marine_rs_sdk_test::internal::serde_json::json!([]); let result = self .marine @@ -207,7 +207,7 @@ fn empty_string() { } pub fn test_array_refs_cp( &mut self, - cp: marine_rs_sdk_test::CallParameters + cp: marine_rs_sdk_test::CallParameters, ) -> Vec { let arguments = marine_rs_sdk_test::internal::serde_json::json!([]); let result = self @@ -230,7 +230,8 @@ fn empty_string() { let tmp_dir = tmp_dir.to_string_lossy().to_string(); std::fs::create_dir(&tmp_dir).expect("can't create a directory for service in tmp"); let mut module_path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); - let mut file_path = std::path::Path::new("tests/generation_tests/multiple_modules").components(); + let mut file_path = + std::path::Path::new("tests/generation_tests/multiple_modules").components(); let mut truncated_file_path = Vec::new(); loop { if module_path.ends_with(file_path.as_path()) { @@ -252,25 +253,24 @@ fn empty_string() { module_path.push(path); } let config_path = module_path.join("Config.toml"); - let modules_dir = module_path.join("artifacts"); - let modules_dir = modules_dir - .to_str() - .expect("modules_dir contains invalid UTF8 string"); let mut __m_generated_marine_config = marine_rs_sdk_test::internal::TomlAppServiceConfig::load( - &config_path + &config_path, ) - .unwrap_or_else(|e| + .unwrap_or_else(|e| { panic!( "app service config located at `{:?}` can't be loaded: {}", config_path, e ) - ); + }); __m_generated_marine_config.service_base_dir = Some(tmp_dir); - __m_generated_marine_config.toml_marine_config.modules_dir = Some(std::path::PathBuf::from(modules_dir)); + __m_generated_marine_config.toml_marine_config.base_path = config_path + .parent() + .map(std::path::PathBuf::from) + .unwrap_or_default(); let marine = marine_rs_sdk_test::internal::AppService::new_with_empty_facade( __m_generated_marine_config, service_id, - std::collections::HashMap::new() + std::collections::HashMap::new(), ) .unwrap_or_else(|e| panic!("app service can't be created: {}", e)); let marine = std::rc::Rc::new(std::cell::RefCell::new(marine)); @@ -310,5 +310,5 @@ fn empty_string() { assert_eq!(actual, expected); } } - test_func(greeting_m, call_parameters_m, ) + test_func(greeting_m, call_parameters_m) } diff --git a/crates/marine-test-macro-impl/tests/generation_tests_runner.rs b/crates/marine-test-macro-impl/tests/generation_tests_runner.rs index f3343b8..d316ddb 100644 --- a/crates/marine-test-macro-impl/tests/generation_tests_runner.rs +++ b/crates/marine-test-macro-impl/tests/generation_tests_runner.rs @@ -26,7 +26,6 @@ fn test_empty_func() { "tests/generation_tests/empty_func/marine_test.rs", "tests/generation_tests/empty_func/expanded.rs", "Config.toml", - "artifacts" )); } @@ -36,7 +35,6 @@ fn test_mounted_binary() { "tests/generation_tests/mounted_binary/marine_test.rs", "tests/generation_tests/mounted_binary/expanded.rs", "Config.toml", - "artifacts" )); } @@ -46,14 +44,12 @@ fn test_multiple_modules() { "tests/generation_tests/multiple_modules/marine_test.rs", "tests/generation_tests/multiple_modules/expanded.rs", "Config.toml", - "artifacts" )); } #[test] fn test_multiservice_single() { let descriptions = vec![TestServiceDescription { - modules_dir: "empty_func/artifacts", config_path: "empty_func/Config.toml", name: "empty_func", }]; @@ -68,12 +64,10 @@ fn test_multiservice_single() { fn test_multiservice_multiple() { let descriptions = vec![ TestServiceDescription { - modules_dir: "empty_func/artifacts", config_path: "empty_func/Config.toml", name: "empty_func", }, TestServiceDescription { - modules_dir: "mounted_binary/artifacts", config_path: "mounted_binary/Config.toml", name: "mounted_binary", }, @@ -88,7 +82,6 @@ fn test_multiservice_multiple() { #[test] fn test_multiservice_empty_mod() { let descriptions = vec![TestServiceDescription { - modules_dir: "artifacts", config_path: "Config.toml", name: "empty_mod", }]; diff --git a/crates/marine-test-macro-impl/tests/utils.rs b/crates/marine-test-macro-impl/tests/utils.rs index 1139659..2f0fe02 100644 --- a/crates/marine-test-macro-impl/tests/utils.rs +++ b/crates/marine-test-macro-impl/tests/utils.rs @@ -18,13 +18,14 @@ use marine_test_macro_impl::marine_test_impl; use marine_macro_testing_utils::{items_from_file, stream_from_file, to_syn_item}; +use std::cmp::min; +use std::cmp::max; use std::path::Path; pub fn test_marine_test_token_streams( marine_path: FP, expanded_path: EP, config_path: &str, - modules_dir: &str, ) -> bool where FP: AsRef, @@ -35,7 +36,6 @@ where let buf = marine_path.as_ref().to_path_buf(); let attrs = quote::quote! { config_path = #config_path, - modules_dir = #modules_dir, }; let marine_token_streams = marine_test_impl( attrs, @@ -47,12 +47,15 @@ where let expanded_item = items_from_file(&expanded_path); let marine_item = to_syn_item(marine_token_streams.clone()); + if expanded_item != marine_item { + print_token_streams_with_diff(&marine_token_streams, &expanded_path); + } + marine_item == expanded_item } pub struct TestServiceDescription { pub config_path: &'static str, - pub modules_dir: &'static str, pub name: &'static str, } @@ -72,9 +75,8 @@ where .iter() .map(|desc| { let config_path = desc.config_path; - let modules_dir = desc.modules_dir; let name = syn::parse_str::(desc.name)?; - Ok(quote::quote! {#name(config_path = #config_path, modules_dir = #modules_dir)}) + Ok(quote::quote! {#name(config_path = #config_path)}) }) .collect::, syn::Error>>() .unwrap_or_else(|e| panic!("failed to parse test arguments due to {}", e)); @@ -93,5 +95,32 @@ where let expanded_item = items_from_file(&expanded_path); let marine_item = to_syn_item(marine_token_streams.clone()); + if expanded_item != marine_item { + print_token_streams_with_diff(&marine_token_streams, &expanded_path); + } + marine_item == expanded_item } + +fn print_token_streams_with_diff>( + macro_output: &proc_macro2::TokenStream, + expanded_path: P, +) { + let actual = macro_output.to_string(); + let expected = stream_from_file(&expanded_path).to_string(); + let min_len = min(actual.len(), expected.len()); + let max_len = max(actual.len(), expected.len()); + let mut first_diff_index: usize = min_len; + for i in 0..min_len { + // String does not implement index access, but implements range access + if actual[i..i + 1] != expected[i..i + 1] { + first_diff_index = i; + break; + } + } + let diff = " ".repeat(first_diff_index) + &"^".repeat(max_len - first_diff_index); + + println!("actual : {}", &actual); + println!("expected: {}", &expected); + println!("diff : {}", &diff); +}