mirror of
https://github.com/fluencelabs/marine-rs-sdk
synced 2025-03-15 14:30:48 +00:00
make paths relative
This commit is contained in:
parent
fa08316c5e
commit
17e2dd1cc0
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "fluence-sdk-test-macro-impl"
|
name = "fluence-sdk-test-macro-impl"
|
||||||
version = "0.1.3" # remember to update html_root_url
|
version = "0.1.4" # remember to update html_root_url
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "Implementation of the `#[fce_test]` macro"
|
description = "Implementation of the `#[fce_test]` macro"
|
||||||
repository = "https://github.com/fluencelabs/rust-sdk/crates/macro-test"
|
repository = "https://github.com/fluencelabs/rust-sdk/crates/macro-test"
|
||||||
@ -18,7 +18,8 @@ fce-wit-parser = "0.5.0"
|
|||||||
|
|
||||||
darling = "0.12.2"
|
darling = "0.12.2"
|
||||||
quote = "1.0.9"
|
quote = "1.0.9"
|
||||||
proc-macro2 = "1.0.24"
|
proc-macro2 = "1.0.26"
|
||||||
proc-macro-error = { version = "1.0.4", default-features = false }
|
proc-macro-error = { version = "1.0.4", default-features = false }
|
||||||
|
caller_modpath = "0.1.1"
|
||||||
syn = { version = '1.0.64', features = ['full'] }
|
syn = { version = '1.0.64', features = ['full'] }
|
||||||
thiserror = "1.0.24"
|
thiserror = "1.0.24"
|
||||||
|
@ -21,8 +21,9 @@ use crate::fce_test::glue_code_generator::generate_test_glue_code;
|
|||||||
use proc_macro2::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
use darling::FromMeta;
|
use darling::FromMeta;
|
||||||
use syn::parse::Parser;
|
use syn::parse::Parser;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
pub fn fce_test_impl(attrs: TokenStream, input: TokenStream) -> TResult<TokenStream> {
|
pub fn fce_test_impl(attrs: TokenStream, input: TokenStream, full_path: PathBuf) -> TResult<TokenStream> {
|
||||||
// from https://github.com/dtolnay/syn/issues/788
|
// from https://github.com/dtolnay/syn/issues/788
|
||||||
let parser = syn::punctuated::Punctuated::<syn::NestedMeta, syn::Token![,]>::parse_terminated;
|
let parser = syn::punctuated::Punctuated::<syn::NestedMeta, syn::Token![,]>::parse_terminated;
|
||||||
let attrs = parser.parse2(attrs)?;
|
let attrs = parser.parse2(attrs)?;
|
||||||
@ -31,5 +32,5 @@ pub fn fce_test_impl(attrs: TokenStream, input: TokenStream) -> TResult<TokenStr
|
|||||||
|
|
||||||
let func_item = syn::parse2::<syn::ItemFn>(input)?;
|
let func_item = syn::parse2::<syn::ItemFn>(input)?;
|
||||||
|
|
||||||
generate_test_glue_code(func_item, attrs)
|
generate_test_glue_code(func_item, attrs, full_path)
|
||||||
}
|
}
|
||||||
|
@ -23,9 +23,10 @@ use crate::fce_test::config_utils;
|
|||||||
use fluence_app_service::TomlAppServiceConfig;
|
use fluence_app_service::TomlAppServiceConfig;
|
||||||
use proc_macro2::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
use quote::ToTokens;
|
//use quote::ToTokens;
|
||||||
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
/// Generates glue code for tests.
|
/// Generates glue code for tests.
|
||||||
/// F.e. for this test for the greeting service
|
/// F.e. for this test for the greeting service
|
||||||
@ -114,6 +115,7 @@ use std::path::Path;
|
|||||||
pub(super) fn generate_test_glue_code(
|
pub(super) fn generate_test_glue_code(
|
||||||
func_item: syn::ItemFn,
|
func_item: syn::ItemFn,
|
||||||
attrs: FCETestAttributes,
|
attrs: FCETestAttributes,
|
||||||
|
full_path: PathBuf,
|
||||||
) -> TResult<TokenStream> {
|
) -> TResult<TokenStream> {
|
||||||
let fce_config = TomlAppServiceConfig::load(&attrs.config_path)?;
|
let fce_config = TomlAppServiceConfig::load(&attrs.config_path)?;
|
||||||
let modules_dir = match config_utils::resolve_modules_dir(&fce_config, attrs.modules_dir) {
|
let modules_dir = match config_utils::resolve_modules_dir(&fce_config, attrs.modules_dir) {
|
||||||
@ -121,7 +123,7 @@ pub(super) fn generate_test_glue_code(
|
|||||||
None => return Err(TestGeneratorError::ModulesDirUnspecified),
|
None => return Err(TestGeneratorError::ModulesDirUnspecified),
|
||||||
};
|
};
|
||||||
|
|
||||||
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, full_path);
|
||||||
let module_interfaces = fce_test::config_utils::collect_modules(&fce_config, modules_dir)?;
|
let module_interfaces = fce_test::config_utils::collect_modules(&fce_config, modules_dir)?;
|
||||||
|
|
||||||
let module_definitions =
|
let module_definitions =
|
||||||
@ -153,10 +155,14 @@ pub(super) fn generate_test_glue_code(
|
|||||||
Ok(glue_code)
|
Ok(glue_code)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_app_service_ctor(config_path: &str, modules_dir: &Path) -> TokenStream {
|
fn generate_app_service_ctor(config_path: &str, modules_dir: &Path, full_path: PathBuf) -> TokenStream {
|
||||||
let config_path = config_path.to_token_stream();
|
|
||||||
let modules_dir = modules_dir.to_string_lossy().to_string();
|
let modules_dir = modules_dir.to_string_lossy().to_string();
|
||||||
|
|
||||||
|
let config_path = full_path.join(config_path);
|
||||||
|
let config_path = config_path.to_str().unwrap();
|
||||||
|
let modules_dir = full_path.join(modules_dir);
|
||||||
|
let modules_dir = modules_dir.to_str().unwrap();
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
let tmp_dir = std::env::temp_dir();
|
let tmp_dir = std::env::temp_dir();
|
||||||
let service_id = fluence_test::internal::Uuid::new_v4().to_string();
|
let service_id = fluence_test::internal::Uuid::new_v4().to_string();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "fluence-sdk-test-macro"
|
name = "fluence-sdk-test-macro"
|
||||||
version = "0.1.3" # remember to update html_root_url
|
version = "0.1.4" # remember to update html_root_url
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "Definition of the `#[fce_test]` macro"
|
description = "Definition of the `#[fce_test]` macro"
|
||||||
repository = "https://github.com/fluencelabs/rust-sdk/crates/macro-test"
|
repository = "https://github.com/fluencelabs/rust-sdk/crates/macro-test"
|
||||||
@ -17,9 +17,10 @@ proc-macro = true
|
|||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
fluence-sdk-test-macro-impl = { path = "../fce-test-macro-impl", version = "0.1.3" }
|
fluence-sdk-test-macro-impl = { path = "../fce-test-macro-impl", version = "0.1.4" }
|
||||||
|
|
||||||
quote = "1.0.9"
|
quote = "1.0.9"
|
||||||
proc-macro2 = "1.0.24"
|
proc-macro2 = "1.0.24"
|
||||||
proc-macro-error = { version = "1.0.4", default-features = false }
|
proc-macro-error = { version = "1.0.4", default-features = false }
|
||||||
|
caller_modpath = "0.1.1"
|
||||||
syn = { version = '1.0.64', features = ['full'] }
|
syn = { version = '1.0.64', features = ['full'] }
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#![doc(html_root_url = "https://docs.rs/fluence-sdk-macro/0.5.0")]
|
#![doc(html_root_url = "https://docs.rs/fluence-test-macro/0.1.4")]
|
||||||
#![deny(
|
#![deny(
|
||||||
dead_code,
|
dead_code,
|
||||||
nonstandard_style,
|
nonstandard_style,
|
||||||
@ -24,14 +24,19 @@
|
|||||||
unused_unsafe,
|
unused_unsafe,
|
||||||
unreachable_patterns
|
unreachable_patterns
|
||||||
)]
|
)]
|
||||||
|
#![feature(proc_macro_span)]
|
||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
#![recursion_limit = "1024"]
|
#![recursion_limit = "1024"]
|
||||||
|
|
||||||
use fluence_sdk_test_macro_impl::fce_test_impl;
|
use fluence_sdk_test_macro_impl::fce_test_impl;
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
use proc_macro_error::proc_macro_error;
|
use proc_macro_error::proc_macro_error;
|
||||||
|
use caller_modpath::expose_caller_modpath;
|
||||||
|
use caller_modpath::CallerModpath;
|
||||||
use syn::spanned::Spanned;
|
use syn::spanned::Spanned;
|
||||||
|
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
/// This macro allows user to write tests for services in the following form:
|
/// This macro allows user to write tests for services in the following form:
|
||||||
///```rust
|
///```rust
|
||||||
/// #[fce_test(config = "/path/to/Config.toml", modules_dir = "path/to/service/modules")]
|
/// #[fce_test(config = "/path/to/Config.toml", modules_dir = "path/to/service/modules")]
|
||||||
@ -40,13 +45,16 @@ use syn::spanned::Spanned;
|
|||||||
/// assert_eq!(&service_result, "Hi, name!");
|
/// assert_eq!(&service_result, "Hi, name!");
|
||||||
/// }
|
/// }
|
||||||
///```
|
///```
|
||||||
|
#[expose_caller_modpath]
|
||||||
#[proc_macro_error]
|
#[proc_macro_error]
|
||||||
#[proc_macro_attribute]
|
#[proc_macro_attribute]
|
||||||
pub fn fce_test(attrs: TokenStream, input: TokenStream) -> TokenStream {
|
pub fn fce_test(attrs: TokenStream, input: TokenStream) -> TokenStream {
|
||||||
let attrs: proc_macro2::TokenStream = attrs.into();
|
let attrs: proc_macro2::TokenStream = attrs.into();
|
||||||
let attrs_span = attrs.span();
|
let attrs_span = attrs.span();
|
||||||
|
let full_path = proc_macro::Span::caller_modpath();
|
||||||
|
let full_path = PathBuf::from(full_path);
|
||||||
|
|
||||||
match fce_test_impl(attrs, input.into()) {
|
match fce_test_impl(attrs, input.into(), full_path) {
|
||||||
Ok(stream) => stream.into(),
|
Ok(stream) => stream.into(),
|
||||||
Err(e) => proc_macro_error::abort!(attrs_span, format!("{}", e)),
|
Err(e) => proc_macro_error::abort!(attrs_span, format!("{}", e)),
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "fluence-test"
|
name = "fluence-test"
|
||||||
version = "0.1.3" # remember to update html_root_url
|
version = "0.1.4" # remember to update html_root_url
|
||||||
description = "Fluence backend SDK for testing"
|
description = "Fluence backend SDK for testing"
|
||||||
documentation = "https://docs.rs/fluence/"
|
documentation = "https://docs.rs/fluence/"
|
||||||
repository = "https://github.com/fluencelabs/rust-sdk"
|
repository = "https://github.com/fluencelabs/rust-sdk"
|
||||||
@ -19,7 +19,7 @@ path = "src/lib.rs"
|
|||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
fluence-sdk-test-macro = { path = "../crates/fce-test-macro", version = "0.1.3" }
|
fluence-sdk-test-macro = { path = "../crates/fce-test-macro", version = "0.1.4" }
|
||||||
fluence-app-service = { version = "0.7.0", features = ["raw-module-api"] }
|
fluence-app-service = { version = "0.7.0", features = ["raw-module-api"] }
|
||||||
|
|
||||||
serde = { version = "1.0.118", features = ["derive"] }
|
serde = { version = "1.0.118", features = ["derive"] }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user