Optimize test

This commit is contained in:
Shunsuke Shibayama 2022-10-30 09:52:40 +09:00
parent 9132d452f9
commit b06f51c5b3
2 changed files with 11 additions and 2 deletions

View file

@ -295,15 +295,23 @@ impl ErgConfig {
.expect("the value of `-py-command` is not a valid Python command"); .expect("the value of `-py-command` is not a valid Python command");
cfg.py_command = Some(Box::leak(py_command.into_boxed_str())); cfg.py_command = Some(Box::leak(py_command.into_boxed_str()));
} }
"--py-magic-num" | "--python-magic-number" => { "--hex-py-magic-num" | "--hex-python-magic-number" => {
let s_hex_magic_num = args let s_hex_magic_num = args
.next() .next()
.expect("the value of `--py-magic-num` is not passed"); .expect("the value of `--hex-py-magic-num` is not passed");
let first_byte = u8::from_str_radix(&s_hex_magic_num[0..=1], 16).unwrap(); let first_byte = u8::from_str_radix(&s_hex_magic_num[0..=1], 16).unwrap();
let second_byte = u8::from_str_radix(&s_hex_magic_num[2..=3], 16).unwrap(); let second_byte = u8::from_str_radix(&s_hex_magic_num[2..=3], 16).unwrap();
let py_magic_num = get_magic_num_from_bytes(&[first_byte, second_byte, 0, 0]); let py_magic_num = get_magic_num_from_bytes(&[first_byte, second_byte, 0, 0]);
cfg.py_magic_num = Some(py_magic_num); cfg.py_magic_num = Some(py_magic_num);
} }
"--py-magic-num" | "--python-magic-number" => {
cfg.py_magic_num = Some(
args.next()
.expect("the value of `--py-magic-num` is not passed")
.parse::<u32>()
.expect("the value of `--py-magic-num` is not a number"),
);
}
"--py-server-timeout" => { "--py-server-timeout" => {
cfg.py_server_timeout = args cfg.py_server_timeout = args
.next() .next()

View file

@ -196,6 +196,7 @@ fn _exec_vm(file_path: &'static str) -> Result<i32, CompileErrors> {
let mut cfg = ErgConfig::with_main_path(PathBuf::from(file_path)); let mut cfg = ErgConfig::with_main_path(PathBuf::from(file_path));
cfg.py_command = Some("python"); cfg.py_command = Some("python");
cfg.target_version = Some(PythonVersion::new(3, Some(10), Some(8))); cfg.target_version = Some(PythonVersion::new(3, Some(10), Some(8)));
cfg.py_magic_num = Some(3439);
let mut vm = DummyVM::new(cfg); let mut vm = DummyVM::new(cfg);
vm.exec() vm.exec()
} }