mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-11-22 15:07:00 -05:00
First pass at test setup function (#22)
This commit is contained in:
parent
517c213f1e
commit
0e02971a35
5 changed files with 42 additions and 10 deletions
|
@ -83,7 +83,7 @@ pub fn set_flags_from_command_line(args: Vec<String>) -> Vec<String> {
|
|||
fn test_set_flags_from_command_line() {
|
||||
let r = set_flags_from_command_line(vec![
|
||||
"binaryname".to_string(),
|
||||
"--log".to_string(),
|
||||
"--log-colour".to_string(),
|
||||
"--should-be-ignored".to_string(),
|
||||
]);
|
||||
assert_eq!(
|
||||
|
|
|
@ -66,14 +66,11 @@ mod tests {
|
|||
use super::*;
|
||||
use crate::array_buffer::Allocator;
|
||||
use crate::isolate::*;
|
||||
use crate::platform::*;
|
||||
use crate::Locker;
|
||||
use crate::V8::*;
|
||||
|
||||
#[test]
|
||||
fn test_handle_scope() {
|
||||
initialize_platform(new_default_platform());
|
||||
initialize();
|
||||
let g = crate::test_util::setup();
|
||||
let mut params = CreateParams::new();
|
||||
params.set_array_buffer_allocator(Allocator::new_default_allocator());
|
||||
let isolate = Isolate::new(params);
|
||||
|
@ -81,5 +78,6 @@ mod tests {
|
|||
HandleScope::new(&mut locker).enter(|scope| {
|
||||
HandleScope::new(scope).enter(|_scope| {});
|
||||
});
|
||||
drop(g);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,18 +72,16 @@ impl Delete for CreateParams {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(disabled_test)]
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::platform::*;
|
||||
use crate::V8::*;
|
||||
|
||||
#[test]
|
||||
fn test_isolate() {
|
||||
initialize_platform(new_default_platform());
|
||||
initialize();
|
||||
let g = crate::test_util::setup();
|
||||
let mut params = CreateParams::new();
|
||||
params.set_array_buffer_allocator(Allocator::new_default_allocator());
|
||||
Isolate::new(params);
|
||||
drop(g);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ pub mod string_buffer;
|
|||
pub mod string_view;
|
||||
pub mod support;
|
||||
|
||||
mod test_util;
|
||||
|
||||
// This module is intentionally named "V8" rather than "v8" to match the
|
||||
// C++ namespace "v8::V8".
|
||||
#[allow(non_snake_case)]
|
||||
|
|
34
src/test_util.rs
Normal file
34
src/test_util.rs
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||
#![cfg(test)]
|
||||
use std::sync::Mutex;
|
||||
|
||||
lazy_static! {
|
||||
static ref INIT_LOCK: Mutex<u32> = Mutex::new(0);
|
||||
}
|
||||
|
||||
pub struct TestGuard {}
|
||||
|
||||
impl Drop for TestGuard {
|
||||
fn drop(&mut self) {
|
||||
// TODO shutdown process cleanly.
|
||||
/*
|
||||
*g -= 1;
|
||||
if *g == 0 {
|
||||
unsafe { crate::V8::dispose() };
|
||||
crate::V8::shutdown_platform();
|
||||
}
|
||||
drop(g);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
pub fn setup() -> TestGuard {
|
||||
let mut g = INIT_LOCK.lock().unwrap();
|
||||
*g += 1;
|
||||
if *g == 1 {
|
||||
crate::V8::initialize_platform(crate::platform::new_default_platform());
|
||||
crate::V8::initialize();
|
||||
}
|
||||
drop(g);
|
||||
TestGuard {}
|
||||
}
|
Loading…
Reference in a new issue