From: Mark Thom Date: Sat, 4 Dec 2021 23:24:34 +0000 (-0700) Subject: start to retune testing infrastructure X-Git-Tag: v0.9.0^2~108 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=2b3e43f1600c6544620c7510d0ac8e7295c3155a;p=scryer-prolog.git start to retune testing infrastructure --- diff --git a/src/machine/mock_wam.rs b/src/machine/mock_wam.rs index 540db78f..0cbae419 100644 --- a/src/machine/mock_wam.rs +++ b/src/machine/mock_wam.rs @@ -2,7 +2,7 @@ pub use crate::arena::*; pub use crate::atom_table::*; use crate::heap_print::*; pub use crate::machine::heap::*; -pub use crate::machine::Machine; +pub use crate::machine::*; pub use crate::machine::machine_state::*; pub use crate::machine::stack::*; pub use crate::machine::streams::*; @@ -215,14 +215,100 @@ pub(crate) fn parse_and_write_parsed_term_to_heap( } impl Machine { + pub fn with_test_streams() -> Self { + use ref_thread_local::RefThreadLocal; + + let mut machine_st = MachineState::new(); + + let user_input = Stream::Null(StreamOptions::default()); + let user_output = Stream::from_owned_string("".to_owned(), &mut machine_st.arena); + let user_error = Stream::stderr(&mut machine_st.arena); + + let mut wam = Machine { + machine_st, + inner_heap: Heap::new(), + policies: MachinePolicies::new(), + indices: IndexStore::new(), + code_repo: CodeRepo::new(), + user_input, + user_output, + user_error, + load_contexts: vec![], + }; + + let mut lib_path = current_dir(); + + lib_path.pop(); + lib_path.push("lib"); + + bootstrapping_compile( + Stream::from_static_string( + LIBRARIES.borrow()["ops_and_meta_predicates"], + &mut wam.machine_st.arena, + ), + &mut wam, + ListingSource::from_file_and_path( + atom!("ops_and_meta_predicates.pl"), + lib_path.clone(), + ), + ) + .unwrap(); + + bootstrapping_compile( + Stream::from_static_string( + LIBRARIES.borrow()["builtins"], + &mut wam.machine_st.arena, + ), + &mut wam, + ListingSource::from_file_and_path(atom!("builtins.pl"), lib_path.clone()), + ) + .unwrap(); + + if let Some(builtins) = wam.indices.modules.get(&atom!("builtins")) { + load_module( + &mut wam.indices.code_dir, + &mut wam.indices.op_dir, + &mut wam.indices.meta_predicates, + &CompilationTarget::User, + builtins, + ); + } else { + unreachable!() + } + + lib_path.pop(); // remove the "lib" at the end + + bootstrapping_compile( + Stream::from_static_string(include_str!("../loader.pl"), &mut wam.machine_st.arena), + &mut wam, + ListingSource::from_file_and_path(atom!("loader.pl"), lib_path.clone()), + ) + .unwrap(); + + wam.configure_modules(); + + if let Some(loader) = wam.indices.modules.get(&atom!("loader")) { + load_module( + &mut wam.indices.code_dir, + &mut wam.indices.op_dir, + &mut wam.indices.meta_predicates, + &CompilationTarget::User, + loader, + ); + } else { + unreachable!() + } + + wam.load_special_forms(); + wam.load_top_level(); + wam.configure_streams(); + + wam + } + pub fn test_load_file(&mut self, file: &str) -> Vec { use std::io::Read; - let old_output = std::mem::replace( - &mut self.user_output, - Stream::from_owned_string("".to_owned(), &mut self.machine_st.arena), - ); - let stream = Stream::from_owned_string( std::fs::read_to_string(AsRef::::as_ref(file)).unwrap(), &mut self.machine_st.arena, @@ -231,7 +317,6 @@ impl Machine { self.load_file(file.into(), stream); let output = self.user_output.bytes().map(|b| b.unwrap()).collect(); - self.user_output = old_output; output } } diff --git a/tests/scryer/helper.rs b/tests/scryer/helper.rs index 3dec7e3e..9cb2f0a3 100644 --- a/tests/scryer/helper.rs +++ b/tests/scryer/helper.rs @@ -29,25 +29,10 @@ impl Expectable for &[u8] { /// Tests whether the file can be successfully loaded /// and produces the expected output during it pub(crate) fn load_module_test(file: &str, expected: T) { - use scryer_prolog::*; + use scryer_prolog::machine::mock_wam::*; - // let input = machine::Stream::from(""); - // let output = machine::Stream::from(String::new()); - // let error = machine::Stream::from(String::new()); - - let mut wam = machine::Machine::new(); // input, output.clone(), error); + let mut wam = Machine::with_test_streams(); expected.assert_eq(wam.test_load_file(file).as_slice()); - - // wam.load_file( - // file.into(), - // machine::Stream::from_owned_string( - // std::fs::read_to_string(AsRef::::as_ref(file)).unwrap(), - // &mut wam.machine_st.arena, - // ), - // ); - // - // let output = output.bytes().unwrap(); - // expected.assert_eq(output.as_slice()); } pub const SCRYER_PROLOG: &str = "scryer-prolog"; diff --git a/tests/scryer/main.rs b/tests/scryer/main.rs index 1b3ada5f..08072d36 100644 --- a/tests/scryer/main.rs +++ b/tests/scryer/main.rs @@ -1,4 +1,3 @@ mod helper; - -mod issues; +// mod issues; mod src_tests;