make paths relative

This commit is contained in:
vms 2021-04-28 22:47:22 +03:00
parent fa08316c5e
commit 17e2dd1cc0
6 changed files with 31 additions and 14 deletions

View File

@ -1,6 +1,6 @@
[package]
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"
description = "Implementation of the `#[fce_test]` macro"
repository = "https://github.com/fluencelabs/rust-sdk/crates/macro-test"
@ -18,7 +18,8 @@ fce-wit-parser = "0.5.0"
darling = "0.12.2"
quote = "1.0.9"
proc-macro2 = "1.0.24"
proc-macro2 = "1.0.26"
proc-macro-error = { version = "1.0.4", default-features = false }
caller_modpath = "0.1.1"
syn = { version = '1.0.64', features = ['full'] }
thiserror = "1.0.24"

View File

@ -21,8 +21,9 @@ use crate::fce_test::glue_code_generator::generate_test_glue_code;
use proc_macro2::TokenStream;
use darling::FromMeta;
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
let parser = syn::punctuated::Punctuated::<syn::NestedMeta, syn::Token![,]>::parse_terminated;
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)?;
generate_test_glue_code(func_item, attrs)
generate_test_glue_code(func_item, attrs, full_path)
}

View File

@ -23,9 +23,10 @@ use crate::fce_test::config_utils;
use fluence_app_service::TomlAppServiceConfig;
use proc_macro2::TokenStream;
use quote::quote;
use quote::ToTokens;
//use quote::ToTokens;
use std::path::Path;
use std::path::PathBuf;
/// Generates glue code for tests.
/// F.e. for this test for the greeting service
@ -114,6 +115,7 @@ use std::path::Path;
pub(super) fn generate_test_glue_code(
func_item: syn::ItemFn,
attrs: FCETestAttributes,
full_path: PathBuf,
) -> TResult<TokenStream> {
let fce_config = TomlAppServiceConfig::load(&attrs.config_path)?;
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),
};
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_definitions =
@ -153,10 +155,14 @@ pub(super) fn generate_test_glue_code(
Ok(glue_code)
}
fn generate_app_service_ctor(config_path: &str, modules_dir: &Path) -> TokenStream {
let config_path = config_path.to_token_stream();
fn generate_app_service_ctor(config_path: &str, modules_dir: &Path, full_path: PathBuf) -> TokenStream {
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! {
let tmp_dir = std::env::temp_dir();
let service_id = fluence_test::internal::Uuid::new_v4().to_string();

View File

@ -1,6 +1,6 @@
[package]
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"
description = "Definition of the `#[fce_test]` macro"
repository = "https://github.com/fluencelabs/rust-sdk/crates/macro-test"
@ -17,9 +17,10 @@ proc-macro = true
doctest = false
[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"
proc-macro2 = "1.0.24"
proc-macro-error = { version = "1.0.4", default-features = false }
caller_modpath = "0.1.1"
syn = { version = '1.0.64', features = ['full'] }

View File

@ -14,7 +14,7 @@
* 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(
dead_code,
nonstandard_style,
@ -24,14 +24,19 @@
unused_unsafe,
unreachable_patterns
)]
#![feature(proc_macro_span)]
#![warn(rust_2018_idioms)]
#![recursion_limit = "1024"]
use fluence_sdk_test_macro_impl::fce_test_impl;
use proc_macro::TokenStream;
use proc_macro_error::proc_macro_error;
use caller_modpath::expose_caller_modpath;
use caller_modpath::CallerModpath;
use syn::spanned::Spanned;
use std::path::PathBuf;
/// This macro allows user to write tests for services in the following form:
///```rust
/// #[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!");
/// }
///```
#[expose_caller_modpath]
#[proc_macro_error]
#[proc_macro_attribute]
pub fn fce_test(attrs: TokenStream, input: TokenStream) -> TokenStream {
let attrs: proc_macro2::TokenStream = attrs.into();
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(),
Err(e) => proc_macro_error::abort!(attrs_span, format!("{}", e)),
}

View File

@ -1,6 +1,6 @@
[package]
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"
documentation = "https://docs.rs/fluence/"
repository = "https://github.com/fluencelabs/rust-sdk"
@ -19,7 +19,7 @@ path = "src/lib.rs"
doctest = false
[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"] }
serde = { version = "1.0.118", features = ["derive"] }