Skip to content

Commit

Permalink
Test features reverting
Browse files Browse the repository at this point in the history
  • Loading branch information
ark0f committed Mar 19, 2024
1 parent 28e631c commit d230744
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions utils/wasm-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ regex.workspace = true
[dev-dependencies]
wabt.workspace = true
wasmi = { workspace = true, features = ["std"] }
parity-wasm.workspace = true

[features]
metawasm = ["gmeta/codegen"]
4 changes: 4 additions & 0 deletions utils/wasm-builder/test-program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ gear-wasm-builder = { path = ".." }

# To exclude this project from the outer workspace
[workspace]

[features]
a = []
b = []
15 changes: 9 additions & 6 deletions utils/wasm-builder/test-program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ include!("rebuild_test.rs");

use gstd::{debug, msg};

#[cfg(feature = "a")]
#[no_mangle]
extern "C" fn handle_reply() {}

#[cfg(feature = "b")]
#[no_mangle]
extern "C" fn handle_signal() {}

#[no_mangle]
extern "C" fn handle() {
debug!("handle()");
Expand All @@ -29,12 +37,7 @@ mod gtest_tests {
let this_program = Program::current(&system);

let res = this_program.send_bytes(123, "INIT");
assert!(res.contains(
&Log::builder()
.source(1)
.dest(123)
.payload_bytes([])
));
assert!(res.contains(&Log::builder().source(1).dest(123).payload_bytes([])));

let res = this_program.send_bytes(123, "Hi");
assert!(res.contains(
Expand Down
29 changes: 29 additions & 0 deletions utils/wasm-builder/tests/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,32 @@ fn no_infinite_build() {

CargoRunner::new().args(["build"]).run();
}

#[ignore]
#[test]
fn features_tracking() {
#[track_caller]
fn read_export_entry(name: &str) -> Option<parity_wasm::elements::ExportEntry> {
parity_wasm::deserialize_file(format!(
"test-program/target/wasm32-unknown-unknown/{}/test_program.wasm",
if cfg!(debug_assertions) {
"debug"
} else {
"release"
}
))
.unwrap()
.export_section()
.unwrap()
.entries()
.iter()
.find(|entry| entry.field() == name)
.cloned()
}

CargoRunner::new().args(["build", "--features=a"]).run();
assert!(read_export_entry("handle_reply").is_some());

CargoRunner::new().args(["build", "--features=b"]).run();
assert!(read_export_entry("handle_signal").is_some());
}

0 comments on commit d230744

Please sign in to comment.