Add marine_test for mod and build.rs test examples (#28)

This commit is contained in:
Valery Antopol
2021-10-18 20:46:47 +03:00
committed by GitHub
parent 615141f888
commit ae33fa6232
7 changed files with 212 additions and 2 deletions

View File

@@ -0,0 +1,21 @@
[package]
name = "wasm-build-rs"
version = "0.1.0"
authors = ["Fluence Labs"]
description = "The greeting module for the Fluence network"
repository = "https://github.com/fluencelabs/marine/tree/master/examples/build_rs"
edition = "2018"
publish = false
[[bin]]
name = "build_rs_test"
path = "src/main.rs"
[dependencies]
marine-rs-sdk = "0.6.11"
[dev-dependencies]
marine-rs-sdk-test = "0.4.0"
[build-dependencies]
marine-rs-sdk-test = "0.4.0"

View File

@@ -0,0 +1,6 @@
modules_dir = "artifacts/"
[[module]]
name = "build_rs_test"
mem_pages_count = 50
logger_enabled = false

View File

@@ -0,0 +1,18 @@
use marine_rs_sdk_test::generate_marine_test_env;
use marine_rs_sdk_test::ServiceDescription;
fn main() {
let services = vec![(
"greeting".to_string(),
ServiceDescription {
config_path: "Config.toml".to_string(),
modules_dir: Some("artifacts".to_string()),
},
)];
let target = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
if target != "wasm32" {
generate_marine_test_env(services, "marine_test_env.rs", file!());
}
println!("cargo:rerun-if-changed=src/main.rs");
}

View File

@@ -0,0 +1,10 @@
#!/bin/sh
# This script builds all subprojects and puts all created Wasm modules in one dir
cargo update --aggressive
marine build --release
rm artifacts/* || true
mkdir -p artifacts
cp target/wasm32-wasi/release/build_rs_test.wasm artifacts/

View File

@@ -0,0 +1,38 @@
/*
* Copyright 2021 Fluence Labs Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use marine_rs_sdk::marine;
use marine_rs_sdk::module_manifest;
module_manifest!();
pub fn main() {}
#[marine]
pub fn greeting(name: String) -> String {
format!("Hi, {}", name)
}
#[cfg(test)]
mod built_tests {
marine_rs_sdk_test::include_test_env!("/marine_test_env.rs"); // <- 4
#[test]
fn non_empty_string() {
let mut greeting = marine_test_env::greeting::ServiceInterface::new();
let actual = greeting.greeting("name".to_string());
assert_eq!(actual, "Hi, name");
}
}