diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/js.rs | 29 | ||||
-rw-r--r-- | runtime/ops/dispatch_minimal.rs | 77 |
2 files changed, 58 insertions, 48 deletions
diff --git a/runtime/js.rs b/runtime/js.rs index ebccaeba6..d61572b21 100644 --- a/runtime/js.rs +++ b/runtime/js.rs @@ -11,21 +11,26 @@ pub fn deno_isolate_init() -> Snapshot { Snapshot::Static(data) } -#[test] -fn cli_snapshot() { - let mut js_runtime = deno_core::JsRuntime::new(deno_core::RuntimeOptions { - startup_snapshot: Some(deno_isolate_init()), - ..Default::default() - }); - js_runtime - .execute( - "<anon>", - r#" +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn cli_snapshot() { + let mut js_runtime = deno_core::JsRuntime::new(deno_core::RuntimeOptions { + startup_snapshot: Some(deno_isolate_init()), + ..Default::default() + }); + js_runtime + .execute( + "<anon>", + r#" if (!(bootstrap.mainRuntime && bootstrap.workerRuntime)) { throw Error("bad"); } console.log("we have console.log!!!"); "#, - ) - .unwrap(); + ) + .unwrap(); + } } diff --git a/runtime/ops/dispatch_minimal.rs b/runtime/ops/dispatch_minimal.rs index 01a47e2ab..b35d0def5 100644 --- a/runtime/ops/dispatch_minimal.rs +++ b/runtime/ops/dispatch_minimal.rs @@ -75,23 +75,6 @@ impl Into<Box<[u8]>> for ErrorRecord { } } -#[test] -fn test_error_record() { - let expected = vec![ - 1, 0, 0, 0, 255, 255, 255, 255, 11, 0, 0, 0, 66, 97, 100, 82, 101, 115, - 111, 117, 114, 99, 101, 69, 114, 114, 111, 114, - ]; - let err_record = ErrorRecord { - promise_id: 1, - arg: -1, - error_len: 11, - error_class: b"BadResource", - error_message: b"Error".to_vec(), - }; - let buf: Box<[u8]> = err_record.into(); - assert_eq!(buf, expected.into_boxed_slice()); -} - pub fn parse_min_record(bytes: &[u8]) -> Option<Record> { if bytes.len() % std::mem::size_of::<i32>() != 0 { return None; @@ -113,25 +96,6 @@ pub fn parse_min_record(bytes: &[u8]) -> Option<Record> { }) } -#[test] -fn test_parse_min_record() { - let buf = vec![1, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0]; - assert_eq!( - parse_min_record(&buf), - Some(Record { - promise_id: 1, - arg: 3, - result: 4 - }) - ); - - let buf = vec![]; - assert_eq!(parse_min_record(&buf), None); - - let buf = vec![5]; - assert_eq!(parse_min_record(&buf), None); -} - pub fn minimal_op<F>(op_fn: F) -> Box<OpFn> where F: Fn(Rc<RefCell<OpState>>, bool, i32, BufVec) -> MinimalOp + 'static, @@ -203,3 +167,44 @@ where } }) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_error_record() { + let expected = vec![ + 1, 0, 0, 0, 255, 255, 255, 255, 11, 0, 0, 0, 66, 97, 100, 82, 101, 115, + 111, 117, 114, 99, 101, 69, 114, 114, 111, 114, + ]; + let err_record = ErrorRecord { + promise_id: 1, + arg: -1, + error_len: 11, + error_class: b"BadResource", + error_message: b"Error".to_vec(), + }; + let buf: Box<[u8]> = err_record.into(); + assert_eq!(buf, expected.into_boxed_slice()); + } + + #[test] + fn test_parse_min_record() { + let buf = vec![1, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0]; + assert_eq!( + parse_min_record(&buf), + Some(Record { + promise_id: 1, + arg: 3, + result: 4 + }) + ); + + let buf = vec![]; + assert_eq!(parse_min_record(&buf), None); + + let buf = vec![5]; + assert_eq!(parse_min_record(&buf), None); + } +} |