Working on a testing method
This commit is contained in:
29
Cargo.lock
generated
29
Cargo.lock
generated
@ -587,6 +587,7 @@ dependencies = [
|
||||
"clap",
|
||||
"libjrpc",
|
||||
"log",
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -962,6 +963,15 @@ version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
|
||||
|
||||
[[package]]
|
||||
name = "same-file"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
|
||||
dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "schannel"
|
||||
version = "0.1.24"
|
||||
@ -1313,6 +1323,16 @@ version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||
|
||||
[[package]]
|
||||
name = "walkdir"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b"
|
||||
dependencies = [
|
||||
"same-file",
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "want"
|
||||
version = "0.3.1"
|
||||
@ -1441,6 +1461,15 @@ dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-util"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
|
||||
dependencies = [
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-registry"
|
||||
version = "0.2.0"
|
||||
|
@ -11,4 +11,6 @@ members = [".", "zed", "libjrpc"]
|
||||
anyhow = "1"
|
||||
clap = { version = "4", features = ["derive"] }
|
||||
libjrpc = { path = "libjrpc" }
|
||||
log = "0.4.27"
|
||||
log = "0.4"
|
||||
[dev-dependencies]
|
||||
walkdir = "2"
|
||||
|
@ -1,4 +1,4 @@
|
||||
import "./import.jrpc";
|
||||
import "./import";
|
||||
|
||||
type TestAtom {
|
||||
val_number?: float;
|
@ -54,7 +54,7 @@ service TestService {
|
||||
|
||||
FunctionWithArrayAsParamAndReturn(values1: float[], values2: float[]): float[];
|
||||
|
||||
FunctionWithKeywords(type: float, static: float, event: float): float;
|
||||
FunctionWithKeywords(_type: float, static: float, event: float): float;
|
||||
}
|
||||
|
||||
type Test2 {
|
@ -66,7 +66,7 @@ impl FileGenerator {
|
||||
}
|
||||
|
||||
pub fn a<T: ToString>(&mut self, indent: usize, content: T) {
|
||||
let line = " ".repeat(indent) + &content.to_string();
|
||||
let line = " ".repeat(indent) + &content.to_string();
|
||||
self.content.push(line);
|
||||
}
|
||||
|
||||
|
@ -13,10 +13,7 @@ pub use tokenizer::{tokenize, Token, TokenError, TokenPosition, TokenType};
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::{
|
||||
compile::{Compile, CompileContext},
|
||||
targets::{self, rust::RustCompiler},
|
||||
};
|
||||
use crate::targets::{self, rust::RustCompiler};
|
||||
|
||||
#[cfg(test)]
|
||||
#[ctor::ctor]
|
||||
|
@ -1,6 +1,6 @@
|
||||
use anyhow::Result;
|
||||
use log::{debug, trace};
|
||||
use std::{collections::HashMap, error::Error, fmt::Display, sync::Arc};
|
||||
use std::{error::Error, fmt::Display, sync::Arc};
|
||||
|
||||
use crate::{Token, TokenPosition, TokenType};
|
||||
|
||||
|
17
src/main.rs
17
src/main.rs
@ -2,6 +2,9 @@ use anyhow::Result;
|
||||
use clap::{Parser, Subcommand};
|
||||
use libjrpc::{targets::rust::RustCompiler, FileProcessor};
|
||||
|
||||
#[cfg(test)]
|
||||
mod test;
|
||||
|
||||
#[derive(Parser)]
|
||||
struct Cli {
|
||||
#[command(subcommand)]
|
||||
@ -14,6 +17,7 @@ struct Cli {
|
||||
enum Commands {
|
||||
Compile {
|
||||
input: String,
|
||||
#[arg(short, long)]
|
||||
output: String,
|
||||
#[arg(short, long)]
|
||||
definition: Option<String>,
|
||||
@ -39,7 +43,18 @@ pub fn main() -> Result<()> {
|
||||
let mut fp = FileProcessor::new();
|
||||
let ir = fp.start_compile(&input)?;
|
||||
|
||||
libjrpc::targets::compile::<RustCompiler>(ir, &output)?;
|
||||
let output_split = output.split(':').collect::<Vec<&str>>();
|
||||
let output_target = output_split[0];
|
||||
let output_dir = output_split[1];
|
||||
|
||||
match output_target {
|
||||
"rust" => {
|
||||
libjrpc::targets::compile::<RustCompiler>(ir, output_dir)?;
|
||||
}
|
||||
_ => {
|
||||
println!("Unsupported target: {}", output_target);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Implement definition output!
|
||||
}
|
||||
|
77
src/test.rs
Normal file
77
src/test.rs
Normal file
@ -0,0 +1,77 @@
|
||||
use std::{
|
||||
fs::File,
|
||||
io::{Read, Stderr, Stdout},
|
||||
process::{Command, Stdio},
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn compare_tools() {
|
||||
let targets = vec!["rust"];
|
||||
for target in targets {
|
||||
std::fs::remove_dir_all("./tests").unwrap();
|
||||
std::fs::create_dir_all("./tests").unwrap();
|
||||
|
||||
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();
|
||||
|
||||
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();
|
||||
|
||||
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!")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user