Files
scryer-prolog/tests/scryer/helper.rs
Danil Platonov 39c850b4f4 Test that SIGINT interrupts non-terminating goals on unix.
Cleanup: use tokio::test instead of special test helpers

Added pty_exec.py helper script to run binaries with a pseudoterminal attached (bug won't trigger otherwise).

Tested CI to fail on all unixes (ubuntu+macos) with older rustyline, and pass with new one.
2026-05-30 11:45:57 -07:00

53 lines
1.4 KiB
Rust

use scryer_prolog::MachineBuilder;
use std::borrow::Cow;
use scryer_prolog::{InputStreamConfig, StreamConfig};
pub(crate) trait Expectable {
#[track_caller]
fn assert_eq(self, other: &[u8]);
}
impl Expectable for &str {
#[track_caller]
fn assert_eq(self, other: &[u8]) {
if let Ok(other_str) = std::str::from_utf8(other) {
assert_eq!(other_str, self)
} else {
// should always fail as other is not valid utf-8 but self is
// just for consistent assert error message
assert_eq!(other, self.as_bytes())
}
}
}
impl Expectable for &[u8] {
#[track_caller]
fn assert_eq(self, other: &[u8]) {
assert_eq!(other, self)
}
}
/// Tests whether the file can be successfully loaded
/// and produces the expected output during it
pub(crate) fn load_module_test<T: Expectable>(file: &str, expected: T) {
use scryer_prolog::MachineBuilder;
let mut wam = MachineBuilder::default().build();
expected.assert_eq(wam.test_load_file(file).as_slice());
}
pub(crate) fn load_module_test_with_input<T: Expectable>(
file: &str,
input: impl Into<Cow<'static, str>>,
expected: T,
) {
use scryer_prolog::MachineBuilder;
let mut wam = MachineBuilder::default()
.with_streams(StreamConfig::in_memory().with_user_input(InputStreamConfig::string(input)))
.build();
expected.assert_eq(wam.test_load_file(file).as_slice());
}