Merge pull request #1650 from palaviv/run-unittests

Run unittests
This commit is contained in:
Noah
2020-01-03 19:41:54 -06:00
committed by GitHub
18 changed files with 2695 additions and 47 deletions

View File

@@ -0,0 +1,44 @@
use crate::frame::FrameRef;
use crate::function::OptionalArg;
use crate::pyobject::PyObjectRef;
use crate::vm::VirtualMachine;
fn dump_frame(frame: &FrameRef) {
eprintln!(
" File \"{}\", line {} in {}",
frame.code.source_path,
frame.get_lineno().row(),
frame.code.obj_name
)
}
fn dump_traceback(_file: OptionalArg<i64>, _all_threads: OptionalArg<bool>, vm: &VirtualMachine) {
eprintln!("Stack (most recent call first):");
for frame in vm.frames.borrow().iter() {
dump_frame(frame);
}
}
fn enable(_file: OptionalArg<i64>, _all_threads: OptionalArg<bool>, _vm: &VirtualMachine) {
// TODO
}
fn register(
_signum: i64,
_file: OptionalArg<i64>,
_all_threads: OptionalArg<bool>,
_chain: OptionalArg<bool>,
_vm: &VirtualMachine,
) {
// TODO
}
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
let ctx = &vm.ctx;
py_module!(vm, "faulthandler", {
"dump_traceback" => ctx.new_rustfunc(dump_traceback),
"enable" => ctx.new_rustfunc(enable),
"register" => ctx.new_rustfunc(register),
})
}

View File

@@ -35,7 +35,8 @@ mod weakref;
use std::collections::HashMap;
use crate::vm::VirtualMachine;
#[cfg(not(target_arch = "wasm32"))]
mod faulthandler;
#[cfg(not(target_arch = "wasm32"))]
mod multiprocessing;
#[cfg(not(target_arch = "wasm32"))]
@@ -116,6 +117,10 @@ pub fn get_module_inits() -> HashMap<String, StdlibInitFunc> {
modules.insert("select".to_string(), Box::new(select::make_module));
modules.insert("_subprocess".to_string(), Box::new(subprocess::make_module));
modules.insert("zlib".to_string(), Box::new(zlib::make_module));
modules.insert(
"faulthandler".to_string(),
Box::new(faulthandler::make_module),
);
}
// Unix-only

View File

@@ -382,7 +382,12 @@ fn os_remove(path: PyStringRef, dir_fd: DirFd, vm: &VirtualMachine) -> PyResult<
fs::remove_file(path.as_str()).map_err(|err| convert_io_error(vm, err))
}
fn os_mkdir(path: PyStringRef, dir_fd: DirFd, vm: &VirtualMachine) -> PyResult<()> {
fn os_mkdir(
path: PyStringRef,
_mode: OptionalArg<PyIntRef>,
dir_fd: DirFd,
vm: &VirtualMachine,
) -> PyResult<()> {
let path = make_path(vm, path, &dir_fd);
fs::create_dir(path.as_str()).map_err(|err| convert_io_error(vm, err))
}

View File

@@ -264,6 +264,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
"strptime" => ctx.new_rustfunc(time_strptime),
"sleep" => ctx.new_rustfunc(time_sleep),
"struct_time" => struct_time_type,
"time" => ctx.new_rustfunc(time_time)
"time" => ctx.new_rustfunc(time_time),
"perf_counter" => ctx.new_rustfunc(time_time), // TODO: fix
})
}

View File

@@ -386,6 +386,7 @@ settrace() -- set the global debug tracing function
"exec_prefix" => ctx.new_str(exec_prefix.to_string()),
"base_exec_prefix" => ctx.new_str(base_exec_prefix.to_string()),
"exit" => ctx.new_rustfunc(sys_exit),
"abiflags" => ctx.new_str("".to_string()),
});
modules.set_item("sys", module.clone(), vm).unwrap();