Skip to content

Commit

Permalink
[FIX] fixing some bugs with ytest
Browse files Browse the repository at this point in the history
  • Loading branch information
Cr0a3 committed Sep 3, 2024
1 parent 6dfba4c commit 83599fd
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 54 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ members = [
"tools/ygen-mc",
"tools/simplelang",
"tools/ytest",
"tools/ylc",
"src/proc",
]

Expand Down
9 changes: 0 additions & 9 deletions test.ylc

This file was deleted.

1 change: 1 addition & 0 deletions tmp.yl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const .const0 = "Hello World!\n"define void @main() { entry: %0 = ptr .const0 %1 = call void printf ptr %0 ret void 0}declare void @printf( ptr %0, ... )Hello World!
2 changes: 1 addition & 1 deletion tools/ytest/example.yl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# RUN: cargo run -p ylc -- -in="%s" -input-is-str -o="out".o && gcc.o -o test.exe && ./a.exe
# RUN: cargo run -p ylc -- -in="%s" -o="out".o && rm "%s" && gcc.o -o test.exe && ./a.exe

const .const0 = "Hello World!\n"

Expand Down
95 changes: 51 additions & 44 deletions tools/ytest/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{fs::File, io::Read, process::{exit, Command}};
use std::{fs::File, io::{Read, Write}};
use std::process::{exit, Command};

use ygen::Support::{Cli, Colorize};

Expand Down Expand Up @@ -43,59 +44,65 @@ fn main() {

let parsed = parse(buf);

let args = parsed.cmd.replace("%s", &format!("\"{}\"", &parsed.input));
let mut args = args.split(" ").collect::<Vec<&str>>();
let path = "./tmp.yl";

let program = args.get(0).expect("expected valid excutable name").to_string();
let mut file = match File::options().write(true).create(true).open(path) {
Ok(file) => file,
Err(err) => {
println!("{}: {}", "Error".red().bold(), err);
exit(-1)
},
};

args.reverse();
args.pop();
args.reverse();
match file.write_all(parsed.input.as_bytes()) {
Ok(_) => {},
Err(err) => {
println!("{}: {}", "Error".red().bold(), err);
exit(-1)
},
}


println!("{}: executing following commandline: '{}{}'", "Info".blue().bold(), program, {
let mut fmt = String::new();
for cmd in parsed.cmd.split("&&") {
let args = cmd.replace("%s", path);
let mut args = args.split(" ").collect::<Vec<&str>>();

for arg in &args {
fmt.push_str(&format!(" {}", arg));
}
let program = args.get(0).expect("expected valid excutable name").to_string();

fmt
});
args.reverse();
args.pop();
args.reverse();

let mut cmd = Command::new( program );

for arg in args {
cmd.arg(arg);
}

match cmd.spawn() {
Ok(cmd) => cmd,
Err(err) => {
println!("{}: {}", "Error".red().bold(), err);
exit(-1)
}
};
println!("{}: executing following commandline: '{}{}'", "Info".blue().bold(), program, {
let mut fmt = String::new();

let out = cmd.output().expect("failed to execute process");
for arg in &args {
fmt.push_str(&format!(" {}", arg));
}

if out.stdout != parsed.expected_out.as_bytes().to_vec() {
println!("{}: expected stdout didn't match real stdout", "Error".red().bold());
println!("\texpected: \"{:#?}\"\n", out.stdout.iter()
.filter_map(|&byte| {
if byte >= 32 && byte <= 126 {
Some(byte as char)
} else {
None
}
}).collect::<String>());
println!("\tfound: \"{:#?}\"\n", parsed.expected_out.as_bytes().to_vec().iter()
.filter_map(|&byte| {
if byte >= 32 && byte <= 126 {
Some(byte as char)
} else {
None
fmt
});

let mut cmd = Command::new( program );

for arg in args {
cmd.arg(arg);
}

match cmd.status() {
Ok(status) => {
if !status.success() {
println!("{}: the programm didn't exit sucessfull", "Error".red().bold());
exit(-1)
}
}).collect::<String>());
},
Err(err) => {
println!("{}: {}", "Error".red().bold(), err);
exit(-1)
}
};

let _ = cmd.output().expect("failed to execute the process");
}
}

0 comments on commit 83599fd

Please sign in to comment.