make tests use files for uxn

input hype!!!!
This commit is contained in:
phyto 2023-05-29 18:11:07 +00:00
parent c3574bce92
commit 11bfa81c25
Signed by: phyto
SSH Key Fingerprint: SHA256:FJdIUDW+Q/c/oLlaNI7vrxCrv0VMxMgT6usJ+7A/wo0
2 changed files with 15 additions and 4 deletions

View File

@ -8,3 +8,6 @@ edition = "2021"
[dependencies]
clap = { version = "4.3.0", features = ["derive"] }
ruxnasm = { git = "https://git.disroot.org/phyto/ruxnasm.git" }
[dev-dependencies]
temp-dir = "0.1.11"

View File

@ -14,13 +14,13 @@ mod tests {
use super::bf::Op;
use super::uxn;
fn interp_uxn(uxn: Vec<u8>, _input: &str) -> Vec<u8> {
fn interp_uxn(uxn: std::path::PathBuf, input: String) -> Vec<u8> {
use std::process::Command;
use std::process::Stdio;
let mut x = Command::new("uxncli")
.env_clear()
.arg("/dev/stdin")
.arg(uxn.into_os_string())
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
@ -30,7 +30,9 @@ mod tests {
let mut stdin = x.stdin.take().expect("failed to get stdin");
let thread = std::thread::spawn(move || {
stdin.write_all(&uxn).expect("failed to write to stdin");
stdin
.write_all(input.as_bytes())
.expect("failed to write to stdin");
dbg!("done writing");
});
@ -53,6 +55,10 @@ mod tests {
fn compare_bf_uxn() {
let files = std::fs::read_dir("tests/samples").unwrap();
// make our temp dir
use temp_dir::TempDir;
let d = TempDir::new().unwrap();
for f in files {
let path = f.unwrap().path();
dbg!(&path);
@ -69,7 +75,9 @@ mod tests {
let tal = uxn::from_ops(&bf);
let (uxn, err) = ruxnasm::assemble(tal.as_bytes()).unwrap();
assert_eq!(err, vec![]);
let uxn_out = interp_uxn(uxn, "");
let uxn_file = d.child(path.file_name().unwrap().to_string_lossy());
std::fs::write(&uxn_file, uxn).unwrap();
let uxn_out = interp_uxn(uxn_file, String::new());
eprintln!("uxn done");
assert_eq!(bf_out, uxn_out);