Files
JsonRPC-Rust/src/test.rs

86 lines
2.6 KiB
Rust

use std::{
fs::File,
io::{Read, Stderr, Stdout},
process::{Command, Stdio},
};
#[test]
fn compare_tools() {
let targets = vec!["js-esm", "rust"];
for target in targets {
std::fs::remove_dir_all("./tests").unwrap();
std::fs::create_dir_all("./tests").unwrap();
let result1 = Command::new("cargo")
.arg("run")
.arg("--")
.arg("compile")
.arg("--verbose")
.arg("examples/test.jrpc")
.arg("-o")
.arg(target.to_string() + ":tests/rust")
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()
.expect("Failed to spawn process")
.wait()
.unwrap();
if !result1.success() {
panic!("Failed to generate Rust code");
}
// let result2 = Command::new("node")
// .arg("JsonRPC/lib/jrpc.js")
// .arg("compile")
// .arg("--verbose")
// .arg("examples/test.jrpc")
// .arg("-o")
// .arg(target.to_string() + ":tests/js")
// .stdout(Stdio::null())
// .stderr(Stdio::null())
// .spawn()
// .expect("Failed to spawn process")
// .wait()
// .unwrap();
// if !result2.success() {
// panic!("Failed to generate JavaScript code");
// }
// let rust_files = walkdir::WalkDir::new("tests/rust")
// .into_iter()
// .map(|e| e.unwrap())
// .filter(|e| e.file_type().is_file())
// .collect::<Vec<_>>();
// let js_files = walkdir::WalkDir::new("tests/js")
// .into_iter()
// .map(|e| e.unwrap())
// .filter(|e| e.file_type().is_file())
// .collect::<Vec<_>>();
// if rust_files.len() != js_files.len() {
// panic!("Number of files mismatch");
// }
// for (rust_file, js_file) in rust_files.iter().zip(js_files.iter()) {
// println!("Testing files {:?} {:?}", rust_file.path(), js_file.path());
// let mut rust_str = String::new();
// File::open(rust_file.path())
// .unwrap()
// .read_to_string(&mut rust_str)
// .unwrap();
// let mut js_str = String::new();
// File::open(js_file.path())
// .unwrap()
// .read_to_string(&mut js_str)
// .unwrap();
// if rust_str != js_str {
// panic!("Files are different!")
// }
// }
}
}