mirror of
https://github.com/fluencelabs/marine-rs-sdk-test
synced 2024-12-11 10:30:18 +00:00
wip code for sharing
This commit is contained in:
parent
2ee2cf3a2c
commit
a494b0ff24
@ -31,6 +31,7 @@ mod errors;
|
|||||||
mod marine_test;
|
mod marine_test;
|
||||||
|
|
||||||
pub use marine_test::marine_test_impl;
|
pub use marine_test::marine_test_impl;
|
||||||
|
pub use marine_test::marine_test_impl2;
|
||||||
pub use errors::TestGeneratorError;
|
pub use errors::TestGeneratorError;
|
||||||
|
|
||||||
pub(crate) type TResult<T> = std::result::Result<T, TestGeneratorError>;
|
pub(crate) type TResult<T> = std::result::Result<T, TestGeneratorError>;
|
||||||
|
@ -127,7 +127,7 @@ pub(super) fn generate_test_glue_code(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let app_service_ctor = generate_app_service_ctor(&attrs.config_path, &modules_dir)?;
|
let app_service_ctor = generate_app_service_ctor(&attrs.config_path, &modules_dir)?;
|
||||||
let modules_dir = file_path.join(modules_dir);
|
/*let modules_dir = file_path.join(modules_dir);
|
||||||
let module_interfaces =
|
let module_interfaces =
|
||||||
marine_test::config_utils::collect_modules(&marine_config, modules_dir)?;
|
marine_test::config_utils::collect_modules(&marine_config, modules_dir)?;
|
||||||
let linked_modules = marine_test::modules_linker::link_modules(&module_interfaces)?;
|
let linked_modules = marine_test::modules_linker::link_modules(&module_interfaces)?;
|
||||||
@ -135,7 +135,7 @@ pub(super) fn generate_test_glue_code(
|
|||||||
let module_definitions = marine_test::module_generator::generate_module_definitions(
|
let module_definitions = marine_test::module_generator::generate_module_definitions(
|
||||||
module_interfaces.iter(),
|
module_interfaces.iter(),
|
||||||
&linked_modules,
|
&linked_modules,
|
||||||
)?;
|
)?;*/
|
||||||
|
|
||||||
let original_block = func_item.block;
|
let original_block = func_item.block;
|
||||||
let signature = func_item.sig;
|
let signature = func_item.sig;
|
||||||
@ -148,9 +148,7 @@ pub(super) fn generate_test_glue_code(
|
|||||||
#[test]
|
#[test]
|
||||||
fn #name() {
|
fn #name() {
|
||||||
// definitions for wasm modules specified in config
|
// definitions for wasm modules specified in config
|
||||||
pub mod marine_test_env {
|
|
||||||
#(#module_definitions)*
|
|
||||||
}
|
|
||||||
// AppService constructor and instantiation to implicit `marine` variable
|
// AppService constructor and instantiation to implicit `marine` variable
|
||||||
#app_service_ctor
|
#app_service_ctor
|
||||||
|
|
||||||
@ -170,6 +168,42 @@ pub(super) fn generate_test_glue_code(
|
|||||||
Ok(glue_code)
|
Ok(glue_code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(super) fn generate_test_glue_code2(
|
||||||
|
attrs: MTestAttributes,
|
||||||
|
) -> TResult<TokenStream> {
|
||||||
|
let file_path = PathBuf::from(".");
|
||||||
|
let config_path = file_path.join(&attrs.config_path);
|
||||||
|
|
||||||
|
let marine_config = TomlAppServiceConfig::load(&config_path)?;
|
||||||
|
let modules_dir = match config_utils::resolve_modules_dir(&marine_config, attrs.modules_dir) {
|
||||||
|
Some(modules_dir) => modules_dir,
|
||||||
|
None => return Err(TestGeneratorError::ModulesDirUnspecified),
|
||||||
|
};
|
||||||
|
|
||||||
|
let modules_dir = file_path.join(modules_dir);
|
||||||
|
let module_interfaces =
|
||||||
|
marine_test::config_utils::collect_modules(&marine_config, modules_dir)?;
|
||||||
|
let linked_modules = marine_test::modules_linker::link_modules(&module_interfaces)?;
|
||||||
|
|
||||||
|
let module_definitions = marine_test::module_generator::generate_module_definitions(
|
||||||
|
module_interfaces.iter(),
|
||||||
|
&linked_modules,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let glue_code = quote! {
|
||||||
|
use marine_rs_sdk_test;
|
||||||
|
pub mod marine_test_env {
|
||||||
|
#(#module_definitions)*
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn message() -> String {
|
||||||
|
"hello".to_string()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(glue_code)
|
||||||
|
}
|
||||||
|
|
||||||
fn generate_app_service_ctor(config_path: &str, modules_dir: &Path) -> TResult<TokenStream> {
|
fn generate_app_service_ctor(config_path: &str, modules_dir: &Path) -> TResult<TokenStream> {
|
||||||
let modules_dir = modules_dir
|
let modules_dir = modules_dir
|
||||||
.to_str()
|
.to_str()
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
use crate::attributes::MTestAttributes;
|
use crate::attributes::MTestAttributes;
|
||||||
use crate::TResult;
|
use crate::TResult;
|
||||||
use crate::marine_test::glue_code_generator::generate_test_glue_code;
|
use crate::marine_test::glue_code_generator::generate_test_glue_code;
|
||||||
|
use crate::marine_test::glue_code_generator::generate_test_glue_code2;
|
||||||
|
|
||||||
use proc_macro2::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
use darling::FromMeta;
|
use darling::FromMeta;
|
||||||
@ -38,3 +39,15 @@ pub fn marine_test_impl(
|
|||||||
|
|
||||||
generate_test_glue_code(func_item, attrs, file_path)
|
generate_test_glue_code(func_item, attrs, file_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn marine_test_impl2(
|
||||||
|
attrs: TokenStream,
|
||||||
|
) -> TResult<TokenStream> {
|
||||||
|
// from https://github.com/dtolnay/syn/issues/788
|
||||||
|
let parser = syn::punctuated::Punctuated::<syn::NestedMeta, syn::Token![,]>::parse_terminated;
|
||||||
|
let attrs = parser.parse2(attrs)?;
|
||||||
|
let attrs: Vec<syn::NestedMeta> = attrs.into_iter().collect();
|
||||||
|
let attrs = MTestAttributes::from_list(&attrs)?;
|
||||||
|
|
||||||
|
generate_test_glue_code2(attrs)
|
||||||
|
}
|
||||||
|
@ -22,3 +22,4 @@ mod utils;
|
|||||||
mod modules_linker;
|
mod modules_linker;
|
||||||
|
|
||||||
pub use marine_test_impl::marine_test_impl;
|
pub use marine_test_impl::marine_test_impl;
|
||||||
|
pub use marine_test_impl::marine_test_impl2;
|
Loading…
Reference in New Issue
Block a user