Skip to content

Commit 59e1c60

Browse files
committed
rune: Clean tests a bit more
1 parent 496577c commit 59e1c60

File tree

2 files changed

+44
-11
lines changed

2 files changed

+44
-11
lines changed

crates/rune/src/tests.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub(crate) mod prelude {
2525
pub(crate) use crate::tests::{eval, run};
2626
pub(crate) use crate::{
2727
from_value, prepare, sources, span, vm_try, Any, Context, ContextError, Diagnostics,
28-
FromValue, Hash, Item, ItemBuf, Module, Options, Source, Sources, Value, Vm,
28+
FromValue, Hash, Item, ItemBuf, Module, Source, Sources, Value, Vm,
2929
};
3030
pub(crate) use futures_executor::block_on;
3131

@@ -43,7 +43,7 @@ use ::rust_alloc::sync::Arc;
4343

4444
use anyhow::{Context as _, Error, Result};
4545

46-
use crate::runtime::{Args, VmError};
46+
use crate::runtime::{GuardedArgs, VmError};
4747
use crate::{
4848
alloc, termcolor, BuildError, Context, Diagnostics, FromValue, Hash, Options, Source, Sources,
4949
Unit, Vm,
@@ -149,24 +149,21 @@ pub fn run_helper<T>(
149149
context: &Context,
150150
sources: &mut Sources,
151151
diagnostics: &mut Diagnostics,
152-
args: impl Args,
152+
args: impl GuardedArgs,
153153
script: bool,
154154
) -> Result<T, TestError>
155155
where
156156
T: FromValue,
157157
{
158158
let mut vm = vm(context, sources, diagnostics, script)?;
159159

160-
let mut execute = if script {
161-
vm.execute(Hash::EMPTY, args).map_err(TestError::VmError)?
160+
let result = if script {
161+
::futures_executor::block_on(vm.async_call(Hash::EMPTY, args))
162162
} else {
163-
vm.execute(["main"], args).map_err(TestError::VmError)?
163+
::futures_executor::block_on(vm.async_call(["main"], args))
164164
};
165165

166-
let output = ::futures_executor::block_on(execute.async_complete())
167-
.into_result()
168-
.map_err(TestError::VmError)?;
169-
166+
let output = result.map_err(TestError::VmError)?;
170167
crate::from_value(output).map_err(|error| TestError::VmError(error.into()))
171168
}
172169

@@ -180,7 +177,7 @@ pub fn sources(source: &str) -> Sources {
180177
}
181178

182179
/// Run the given source with diagnostics being printed to stderr.
183-
pub fn run<T>(context: &Context, source: &str, args: impl Args, script: bool) -> Result<T>
180+
pub fn run<T>(context: &Context, source: &str, args: impl GuardedArgs, script: bool) -> Result<T>
184181
where
185182
T: FromValue,
186183
{
@@ -487,6 +484,7 @@ mod getter_setter;
487484
mod iterator;
488485
#[cfg(not(miri))]
489486
mod macros;
487+
mod matching;
490488
#[cfg(not(miri))]
491489
mod moved;
492490
#[cfg(not(miri))]

crates/rune/src/tests/matching.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
prelude!();
2+
3+
#[derive(Debug, Any)]
4+
struct External {
5+
#[rune(get, set)]
6+
value: u32,
7+
}
8+
9+
pub fn module() -> Result<Module, ContextError> {
10+
let mut module = Module::new();
11+
module.ty::<External>()?;
12+
Ok(module)
13+
}
14+
15+
#[test]
16+
#[ignore = "fix this"]
17+
fn try_matching() -> crate::support::Result<()> {
18+
let m = module()?;
19+
20+
let external = External { value: 1337 };
21+
22+
let b: bool = rune_n! {
23+
mod m,
24+
(&external,),
25+
pub fn main(external) {
26+
match external {
27+
External { value: 1337 } => true,
28+
_ => false,
29+
}
30+
}
31+
};
32+
33+
assert!(b);
34+
Ok(())
35+
}

0 commit comments

Comments
 (0)