Skip to content

Commit

Permalink
[YTEST] changing format a little
Browse files Browse the repository at this point in the history
  • Loading branch information
Cr0a3 committed Sep 9, 2024
1 parent 896df53 commit a7d7125
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
7 changes: 5 additions & 2 deletions tools/ytest/example.yl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# RUN: cargo run -p ylc -- -in=%s -o=out.o && gcc out.o -o a.exe && ./a.exe
# RUN:
cargo run -p ylc -- -in=%s -o=out.o && gcc out.o -o a.exe && ./a.exe

# IN:
const const0 = "Hello World!\n\00"

define void @main() {
Expand All @@ -11,4 +13,5 @@ define void @main() {
}
declare void @printf( ptr %0, ... )

# STDOUT: Hello World!
# STDOUT:
Hello World!
8 changes: 7 additions & 1 deletion tools/ytest/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn main() {
};

let parsed = parse(buf);

let path_str = "./tmp.yl";

let path = std::path::PathBuf::from(path_str);
Expand Down Expand Up @@ -128,4 +128,10 @@ fn main() {
}
};
}

if parsed.expected_out != found {
println!("{}: expected output didn't match actual output", "Error".red().bold());
println!("found: {:?}", found);
println!("expected: {:?}", parsed.expected_out);
}
}
29 changes: 24 additions & 5 deletions tools/ytest/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,44 @@ pub fn parse(input: String) -> Parsed {

let mut append ;

let mut stdout = false;
let mut run = false;

for line in input.lines() {
append = true;

if line.trim_start().starts_with("# RUN:") {
out.cmd += &line.replace("# RUN:", "");
if line.trim().starts_with("# RUN:") {
append = false;
stdout = false;
run = true;
}

if line.trim_start().starts_with("# STDOUT:") {
out.expected_out += &line.replace("# STDOUT:", "");
if line.trim().starts_with("# STDOUT:") {
append = false;
stdout = true;
run = false;
}

if line.trim().starts_with("# IN:") {
append = false;
stdout = false;
run = false;
}

if append {
out.input.push_str(&format!("{}\n", line));
if run {
out.cmd.push_str(&format!("{line}\n"));
} else if stdout {
out.expected_out.push_str(&format!("{line}\n"));
} else {
out.input.push_str(&format!("{line}\n"));
}
}
}

out.cmd = out.cmd.trim_start().to_string();

//out.expected_out = unescaper::unescape(&out.expected_out).unwrap();

out
}

0 comments on commit a7d7125

Please sign in to comment.