add trybuild tests

This commit is contained in:
vms 2021-04-01 18:36:25 +03:00
parent ae3c6e1e98
commit fc320fe50d
23 changed files with 469 additions and 328 deletions

View File

@ -15,6 +15,7 @@ all-features = true
[lib]
proc-macro = true
doctest = false
[dependencies]
fluence-sdk-wit = { path = "../wit", version = "=0.5.0" }

View File

@ -14,6 +14,7 @@ all-features = true
[lib]
proc-macro = true
doctest = false
[dependencies]
fluence-sdk-test-macro-impl = { path = "../fce-test-macro-impl", version = "=0.5.0" }

View File

@ -16,6 +16,7 @@ all-features = true
[lib]
path = "src/lib.rs"
crate-type = ["rlib"]
doctest = false
[dependencies]
fluence-sdk-macro = { path = "../fce-macro", version = "=0.5.0" }

View File

@ -16,6 +16,7 @@ all-features = true
[lib]
path = "src/lib.rs"
doctest = false
[dependencies]
fluence-sdk-test-macro = { path = "../crates/fce-test-macro", version = "=0.5.0" }

View File

@ -16,11 +16,15 @@ all-features = true
[lib]
path = "src/lib.rs"
doctest = false
[dependencies]
fluence-sdk-macro = { path = "../crates/fce-macro", version = "=0.5.0" }
fluence-sdk-main = { path = "../crates/main", version = "=0.5.0" }
[dev-dependencies]
trybuild = "1.0"
[features]
# Print some internal logs by log_utf8_string
debug = ["fluence-sdk-main/debug"]

View File

@ -0,0 +1,67 @@
#![allow(improper_ctypes)]
use fluence::fce;
pub fn main() {}
#[fce]
pub fn byte_type( __arg: Vec<u8>) -> Vec<u8> {
unimplemented!()
}
#[fce]
pub fn inner_arrays_1(_arg: Vec<Vec<Vec<Vec<u8>>>>) -> Vec<Vec<Vec<Vec<u8>>>> {
unimplemented!()
}
#[fce]
#[derive(Default)]
pub struct TestRecord {
pub field_0: i32,
pub field_1: Vec<Vec<u8>>,
}
#[fce]
pub fn inner_arrays_2(_arg: Vec<Vec<Vec<Vec<TestRecord>>>>) -> Vec<Vec<Vec<Vec<TestRecord>>>> {
unimplemented!()
}
#[fce]
pub fn string_type(_arg: Vec<String>) -> Vec<String> {
unimplemented!()
}
#[fce]
pub fn f32_type(_arg: Vec<f32>) -> Vec<f32> {
unimplemented!()
}
#[fce]
pub fn f64_type(_arg: Vec<f64>) -> Vec<f64> {
unimplemented!()
}
#[fce]
pub fn u32_type(_arg: Vec<u32>) -> Vec<u32> {
unimplemented!()
}
#[fce]
pub fn u64_type(_arg: Vec<u64>) -> Vec<u64> {
unimplemented!()
}
#[fce]
pub fn i32_type(_arg: Vec<i32>) -> Vec<i32> {
unimplemented!()
}
#[fce]
pub fn i64_type(_arg: Vec<i64>) -> Vec<i64> {
unimplemented!()
}
#[fce]
pub fn empty_type() -> Vec<String> {
unimplemented!()
}

View File

@ -0,0 +1,73 @@
#![allow(improper_ctypes)]
use fluence::fce;
pub fn main() {}
#[fce]
pub fn all_types(
_arg_0: i8,
_arg_1: i16,
_arg_2: i32,
_arg_3: i64,
_arg_4: u8,
_arg_5: u16,
_arg_6: u32,
_arg_7: u64,
_arg_8: f32,
_arg_9: f64,
_arg_10: String,
_arg_11: Vec<u8>,
) -> Vec<u8> {
unimplemented!()
}
#[fce]
pub fn string_type(_arg: String) -> String {
unimplemented!()
}
#[fce]
pub fn bytearray_type(_arg: Vec<u8>) -> Vec<u8> {
unimplemented!()
}
#[fce]
pub fn bool_type(_arg: bool) -> bool {
unimplemented!()
}
#[fce]
pub fn f32_type(_arg: f32) -> f32 {
unimplemented!()
}
#[fce]
pub fn f64_type(_arg: f64) -> f64 {
unimplemented!()
}
#[fce]
pub fn u32_type(_arg: u32) -> u32 {
unimplemented!()
}
#[fce]
pub fn u64_type(_arg: u64) -> u64 {
unimplemented!()
}
#[fce]
pub fn i32_type(_arg: i32) -> i32 {
unimplemented!()
}
#[fce]
pub fn i64_type(_arg: i64) -> i64 {
unimplemented!()
}
#[fce]
pub fn empty_type() -> String {
unimplemented!()
}

View File

@ -0,0 +1,24 @@
#![allow(improper_ctypes)]
use fluence::fce;
pub fn main() {}
#[fce]
fn test(_arg_1: Box<i32>) {}
#[fce]
fn test2(_arg_1: std::rc::Rc<i32>) {}
#[fce]
fn test3(_arg_1: std::collections::HashMap<i32, String>) {}
#[fce]
fn test4(_arg_1: i32) -> (i32, i32) {
unimplemented!()
}
#[fce]
fn test5(_arg_1: i32) -> Box<i32> {
unimplemented!()
}

View File

@ -0,0 +1,29 @@
error: type with lifetimes or generics aren't allowed
--> $DIR/improper_types.rs:8:17
|
8 | fn test(_arg_1: Box<i32>) {}
| ^^^^^^^^
error: type with lifetimes or generics aren't allowed
--> $DIR/improper_types.rs:11:27
|
11 | fn test2(_arg_1: std::rc::Rc<i32>) {}
| ^^^^^^^
error: type with lifetimes or generics aren't allowed
--> $DIR/improper_types.rs:14:36
|
14 | fn test3(_arg_1: std::collections::HashMap<i32, String>) {}
| ^^^^^^^^^^^^^^^^^^^^
error: Incorrect argument type - passing only by value is supported now
--> $DIR/improper_types.rs:17:26
|
17 | fn test4(_arg_1: i32) -> (i32, i32) {
| ^^^^^^^^^^
error: type with lifetimes or generics aren't allowed
--> $DIR/improper_types.rs:22:26
|
22 | fn test5(_arg_1: i32) -> Box<i32> {
| ^^^^^^^^

View File

@ -0,0 +1,40 @@
#![allow(improper_ctypes)]
use fluence::fce;
pub fn main() {}
#[fce]
#[derive(Default)]
pub struct TestRecord {
pub field_0: i32,
pub field_1: Vec<Vec<u8>>,
}
#[fce]
#[link(wasm_import_module = "arrays_passing_effector")]
extern "C" {
pub fn inner_arrays_1(arg: Vec<Vec<Vec<Vec<u8>>>>) -> Vec<Vec<Vec<Vec<u8>>>>;
pub fn inner_arrays_2(
arg: Vec<Vec<Vec<Vec<TestRecord>>>>,
) -> Vec<Vec<Vec<Vec<TestRecord>>>>;
pub fn string_type(arg: Vec<String>) -> Vec<String>;
pub fn byte_type(arg: Vec<u8>) -> Vec<u8>;
pub fn f32_type(arg: Vec<f32>) -> Vec<f32>;
pub fn f64_type(arg: Vec<f64>) -> Vec<f64>;
pub fn u32_type(arg: Vec<u32>) -> Vec<u32>;
pub fn u64_type(arg: Vec<u64>) -> Vec<u64>;
pub fn i32_type(arg: Vec<i32>) -> Vec<i32>;
pub fn i64_type(arg: Vec<i64>) -> Vec<i64>;
pub fn empty_type() -> Vec<String>;
}

View File

@ -0,0 +1,40 @@
#![allow(improper_ctypes)]
use fluence::fce;
fn main() {}
#[fce]
#[link(wasm_import_module = "arguments_passing_effector")]
extern "C" {
pub fn all_types(
arg_0: i8,
arg_1: i16,
arg_2: i32,
arg_3: i64,
arg_4: u8,
arg_5: u16,
arg_6: u32,
arg_7: u64,
arg_8: f32,
arg_9: f64,
arg_10: String,
arg_11: Vec<u8>,
) -> Vec<u8>;
pub fn string_type(arg: String) -> String;
pub fn bytearray_type(arg: Vec<u8>) -> Vec<u8>;
pub fn bool_type(arg: bool) -> bool;
pub fn f32_type(arg: f32) -> f32;
pub fn f64_type(arg: f64) -> f64;
pub fn u32_type(arg: u32) -> u32;
pub fn u64_type(arg: u64) -> u64;
pub fn i32_type(arg: i32) -> i32;
pub fn i64_type(arg: i64) -> i64;
pub fn empty_type() -> String;
}

View File

@ -0,0 +1,24 @@
#![allow(improper_ctypes)]
use fluence::fce;
pub fn main() {}
#[fce]
#[link(wasm_import_module = "arguments_passing_effector")]
extern "C" {
#[fce]
fn test(_arg_1: Box<i32>);
#[fce]
fn test2(_arg_1: std::rc::Rc<i32>);
#[fce]
fn test3(_arg_1: std::collections::HashMap<i32, String>);
#[fce]
fn test4(_arg_1: i32) -> (i32, i32);
#[fce]
fn test5(_arg_1: i32) -> Box<i32>;
}

View File

@ -0,0 +1,5 @@
error: type with lifetimes or generics aren't allowed
--> $DIR/improper_types.rs:11:21
|
11 | fn test(_arg_1: Box<i32>);
| ^^^^^^^^

View File

@ -0,0 +1,82 @@
#![allow(improper_ctypes)]
use fluence::fce;
fn main() {}
#[fce]
pub struct TestRecord {
pub field_0: bool,
pub field_1: i8,
pub field_2: i16,
pub field_3: i32,
pub field_4: i64,
pub field_5: u8,
pub field_6: u16,
pub field_7: u32,
pub field_8: u64,
pub field_9: f32,
pub field_10: f64,
pub field_11: String,
pub field_12: Vec<u8>,
}
#[fce]
pub struct Tx {
pub block_hash: String,
pub block_number: String,
pub from: String,
pub gas: String,
pub gas_price: String,
pub hash: String,
pub input: String,
pub nonce: String,
pub to: String,
pub transaction_index: String,
pub value: String,
}
#[fce]
#[derive(Debug)]
pub struct JsonRpcResult {
pub json_rpc: String,
pub result: String,
pub error: String,
pub id: u64,
}
#[fce]
#[derive(Clone, Debug, Default, Eq, PartialEq, Hash)]
pub struct User {
pub peer_id: String,
pub relay_id: String,
pub signature: String,
pub name: String,
}
#[fce]
pub struct GetUsersServiceResult {
pub ret_code: i32,
pub err_msg: String,
pub users: Vec<User>,
}
#[fce]
pub struct EmptyServiceResult {
pub ret_code: i32,
pub err_msg: String,
}
#[fce]
pub struct ExistsServiceResult {
pub ret_code: i32,
pub err_msg: String,
pub is_exists: bool,
}
#[fce]
pub struct AuthResult {
pub ret_code: i32,
pub err_msg: String,
pub is_authenticated: bool,
}

View File

@ -0,0 +1,8 @@
#![allow(improper_ctypes)]
use fluence::fce;
fn main() {}
#[fce]
struct A {}

View File

@ -0,0 +1,20 @@
#![allow(improper_ctypes)]
use fluence::fce;
fn main() {}
#[fce]
struct StructWithBox {
pub a: Box<i32>,
}
#[fce]
struct StructWithRc {
pub a: std::rc::Rc<i32>,
}
#[fce]
struct StructWithHashMap {
pub a: std::collections::HashMap<i32, String>,
}

View File

@ -0,0 +1,17 @@
error: type with lifetimes or generics aren't allowed
--> $DIR/struct_with_improper_types.rs:9:12
|
9 | pub a: Box<i32>,
| ^^^^^^^^
error: type with lifetimes or generics aren't allowed
--> $DIR/struct_with_improper_types.rs:14:21
|
14 | pub a: std::rc::Rc<i32>,
| ^^^^^^^
error: type with lifetimes or generics aren't allowed
--> $DIR/struct_with_improper_types.rs:19:30
|
19 | pub a: std::collections::HashMap<i32, String>,
| ^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,11 @@
#![allow(improper_ctypes)]
use fluence::fce;
fn main() {}
#[fce]
struct StructWithPrivateFields {
a: i32,
b: usize,
}

View File

@ -0,0 +1,5 @@
error: #[fce] could be applied only to struct with all public fields
--> $DIR/struct_with_private_fields.rs:9:5
|
9 | a: i32,
| ^^^^^^

View File

@ -0,0 +1,16 @@
#[test]
fn test() {
let tests = trybuild::TestCases::new();
tests.pass("tests/export_functions/arrays.rs");
tests.pass("tests/export_functions/basic_types.rs");
tests.compile_fail("tests/export_functions/improper_types.rs");
tests.pass("tests/import_functions/arrays.rs");
tests.pass("tests/import_functions/basic_types.rs");
tests.compile_fail("tests/import_functions/improper_types.rs");
tests.pass("tests/records/basic_structs.rs");
tests.pass("tests/records/empty_struct.rs");
tests.compile_fail("tests/records/struct_with_improper_types.rs");
tests.compile_fail("tests/records/struct_with_private_fields.rs");
}

View File

@ -1,175 +0,0 @@
use fluence::fce;
pub fn main() {}
#[fce]
pub fn byte_type(mut arg: Vec<u8>) -> Vec<u8> {
arg.push(0);
let mut arg = unsafe { effector::byte_type(arg) };
arg.push(2);
arg
}
#[fce]
pub fn inner_arrays_1(mut arg: Vec<Vec<Vec<Vec<u8>>>>) -> Vec<Vec<Vec<Vec<u8>>>> {
arg.push(vec![vec![vec![0]]]);
let mut arg = unsafe { effector::inner_arrays_1(arg) };
arg.push(vec![vec![vec![2]]]);
arg
}
#[fce]
#[derive(Default)]
pub struct TestRecord {
pub field_0: i32,
pub field_1: Vec<Vec<u8>>,
}
#[fce]
pub fn inner_arrays_2(mut arg: Vec<Vec<Vec<Vec<TestRecord>>>>) -> Vec<Vec<Vec<Vec<TestRecord>>>> {
arg.push(vec![vec![vec![
TestRecord {
field_0: 0,
field_1: vec![vec![1]],
},
TestRecord::default(),
]]]);
let mut arg = unsafe { effector::inner_arrays_2(arg) };
arg.push(vec![vec![vec![
TestRecord {
field_0: 1,
field_1: vec![vec![2]],
},
TestRecord::default(),
]]]);
arg
}
#[fce]
pub fn string_type(mut arg: Vec<String>) -> Vec<String> {
arg.push(String::from("fce"));
let mut arg = unsafe { effector::string_type(arg) };
arg.push(String::from("test"));
arg
}
/*
#[fce]
pub fn bool_type(arg: Vec<bool>) -> Vec<bool> {
let mut arg = unsafe { effector::bool_type(arg) };
arg.push(false);
arg
}
*/
#[fce]
pub fn f32_type(mut arg: Vec<f32>) -> Vec<f32> {
arg.push(0.0);
let mut arg = unsafe { effector::f32_type(arg) };
arg.push(1.0);
arg
}
#[fce]
pub fn f64_type(mut arg: Vec<f64>) -> Vec<f64> {
arg.push(0.0);
let mut arg = unsafe { effector::f64_type(arg) };
arg.push(1.0);
arg
}
#[fce]
pub fn u32_type(mut arg: Vec<u32>) -> Vec<u32> {
arg.push(0);
let mut arg = unsafe { effector::u32_type(arg) };
arg.push(2);
arg
}
#[fce]
pub fn u64_type(mut arg: Vec<u64>) -> Vec<u64> {
arg.push(0);
let mut arg = unsafe { effector::u64_type(arg) };
arg.push(2);
arg
}
#[fce]
pub fn i32_type(mut arg: Vec<i32>) -> Vec<i32> {
arg.push(0);
let mut arg = unsafe { effector::i32_type(arg) };
arg.push(2);
arg
}
#[fce]
pub fn i64_type(mut arg: Vec<i64>) -> Vec<i64> {
arg.push(0);
let mut arg = unsafe { effector::i64_type(arg) };
arg.push(1);
arg
}
#[fce]
pub fn empty_type() -> Vec<String> {
unsafe { effector::empty_type() }
}
mod effector {
use fluence::fce;
use super::TestRecord;
#[fce]
#[link(wasm_import_module = "arrays_passing_effector")]
extern "C" {
pub fn inner_arrays_1(arg: Vec<Vec<Vec<Vec<u8>>>>) -> Vec<Vec<Vec<Vec<u8>>>>;
pub fn inner_arrays_2(
arg: Vec<Vec<Vec<Vec<TestRecord>>>>,
) -> Vec<Vec<Vec<Vec<TestRecord>>>>;
pub fn string_type(arg: Vec<String>) -> Vec<String>;
pub fn byte_type(arg: Vec<u8>) -> Vec<u8>;
/*
pub fn bool_type(arg: Vec<bool>) -> Vec<bool>;
*/
pub fn f32_type(arg: Vec<f32>) -> Vec<f32>;
pub fn f64_type(arg: Vec<f64>) -> Vec<f64>;
pub fn u32_type(arg: Vec<u32>) -> Vec<u32>;
pub fn u64_type(arg: Vec<u64>) -> Vec<u64>;
pub fn i32_type(arg: Vec<i32>) -> Vec<i32>;
pub fn i64_type(arg: Vec<i64>) -> Vec<i64>;
pub fn empty_type() -> Vec<String>;
}
}

View File

@ -1,153 +0,0 @@
#![allow(improper_ctypes)]
use fluence::fce;
pub fn main() {}
#[fce]
pub fn all_types(
arg_0: i8,
arg_1: i16,
arg_2: i32,
arg_3: i64,
arg_4: u8,
arg_5: u16,
arg_6: u32,
arg_7: u64,
arg_8: f32,
arg_9: f64,
arg_10: String,
arg_11: Vec<u8>,
) -> Vec<u8> {
let mut result = unsafe {
effector::all_types(
arg_0,
arg_1,
arg_2,
arg_3,
arg_4,
arg_5,
arg_6,
arg_7,
arg_8,
arg_9,
arg_10.clone(),
arg_11.clone(),
)
};
result.push(arg_0 as u8);
result.extend(safe_transmute::transmute_one_to_bytes(&arg_1));
result.extend(safe_transmute::transmute_one_to_bytes(&arg_2));
result.extend(safe_transmute::transmute_one_to_bytes(&arg_3));
result.extend(safe_transmute::transmute_one_to_bytes(&arg_4));
result.extend(safe_transmute::transmute_one_to_bytes(&arg_5));
result.extend(safe_transmute::transmute_one_to_bytes(&arg_6));
result.extend(safe_transmute::transmute_one_to_bytes(&arg_7));
result.extend(&arg_8.to_be_bytes());
result.extend(&arg_9.to_be_bytes());
result.extend(arg_10.into_bytes());
result.extend(arg_11);
result
}
#[fce]
pub fn string_type(arg: String) -> String {
let arg = unsafe { effector::string_type(arg) };
format!("{}_{}", arg, arg)
}
#[fce]
pub fn bytearray_type(arg: Vec<u8>) -> Vec<u8> {
let mut arg = unsafe { effector::bytearray_type(arg) };
arg.push(1);
arg
}
#[fce]
pub fn bool_type(arg: bool) -> bool {
unsafe { effector::bool_type(arg) }
}
#[fce]
pub fn f32_type(arg: f32) -> f32 {
let arg = unsafe { effector::f32_type(arg) };
arg + 1.0
}
#[fce]
pub fn f64_type(arg: f64) -> f64 {
let arg = unsafe { effector::f64_type(arg) };
arg + 1.0
}
#[fce]
pub fn u32_type(arg: u32) -> u32 {
let arg = unsafe { effector::u32_type(arg) };
arg + 1
}
#[fce]
pub fn u64_type(arg: u64) -> u64 {
let arg = unsafe { effector::u64_type(arg) };
arg + 1
}
#[fce]
pub fn i32_type(arg: i32) -> i32 {
let arg = unsafe { effector::i32_type(arg) };
arg + 1
}
#[fce]
pub fn i64_type(arg: i64) -> i64 {
let arg = unsafe { effector::i64_type(arg) };
arg + 1
}
#[fce]
pub fn empty_type() -> String {
unsafe { effector::empty_type() }
}
mod effector {
use fluence::fce;
#[fce]
#[link(wasm_import_module = "arguments_passing_effector")]
extern "C" {
pub fn all_types(
arg_0: i8,
arg_1: i16,
arg_2: i32,
arg_3: i64,
arg_4: u8,
arg_5: u16,
arg_6: u32,
arg_7: u64,
arg_8: f32,
arg_9: f64,
arg_10: String,
arg_11: Vec<u8>,
) -> Vec<u8>;
pub fn string_type(arg: String) -> String;
pub fn bytearray_type(arg: Vec<u8>) -> Vec<u8>;
pub fn bool_type(arg: bool) -> bool;
pub fn f32_type(arg: f32) -> f32;
pub fn f64_type(arg: f64) -> f64;
pub fn u32_type(arg: u32) -> u32;
pub fn u64_type(arg: u64) -> u64;
pub fn i32_type(arg: i32) -> i32;
pub fn i64_type(arg: i64) -> i64;
pub fn empty_type() -> String;
}
}