Skip to content

Commit

Permalink
[YTEST] added option for two different inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
Cr0a3 committed Oct 12, 2024
1 parent eb56b43 commit 7fc32d9
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dev-guide/book
*.o
*.exe
*.out
tmp.yl
tmp*

web/node_modules
web/.pnp
Expand Down
18 changes: 17 additions & 1 deletion fp.yl
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# RUN:
cargo run -p ylc -- -in=%s -o=out.o
gcc out.o %s2 -o a.exe
./a.exe

# IN:
define f32 @add(f32 %0, f32 %1) {
entry:
%2 = add f32 %0, %1
ret f32 %2
}
}

# IN2:
extern float add(float, float);

int main() {
float out = add(2.5f, 2.5f);
return (int)out;
}

# EXIT_CODE=5
30 changes: 28 additions & 2 deletions tools/ytest/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ fn main() {

let parsed = parse(buf);

let path_str = "./tmp.yl";
let path_str = "./tmp";
let path2_str = "./tmp2";

let path = std::path::PathBuf::from(path_str);

Expand All @@ -73,14 +74,39 @@ fn main() {
},
}
}

let path2 = std::path::PathBuf::from(path2_str);

if path2.exists() {
let _ = std::fs::remove_file(&path2);
}

if let Some(input) = parsed.input2 {
let mut file = match File::options().write(true).create(true).open(&path2) {
Ok(file) => file,
Err(err) => {
println!("{}: {}", "Error".red().bold(), err);
exit(-1)
},
};

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

let mut found = String::new();
let mut found_stderr = String::new();

let mut code = 0;

for cmd in parsed.cmd {
let args = cmd.replace("%s", path_str);
let args = cmd .replace("%s", path_str)
.replace("%s2", path2_str);
let args = unescaper::unescape(&args).unwrap();
let args = args.trim();
let mut args = args.split(" ").collect::<Vec<&str>>();
Expand Down
30 changes: 27 additions & 3 deletions tools/ytest/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pub struct Parsed {
pub cmd: Vec<String>,
pub input: Option<String>,
pub input2: Option<String>,
pub expected_out: Option<String>,
pub expected_stderr: Option<String>,
pub expected_code: Option<i32>,
Expand All @@ -12,6 +13,7 @@ pub fn parse(input: String) -> Parsed {
let mut out = Parsed {
cmd: Vec::new(),
input: None,
input2: None,
expected_out: None,
expected_code: None,
expected_stderr: None,
Expand All @@ -24,6 +26,8 @@ pub fn parse(input: String) -> Parsed {
let mut stderr = false;
let mut run = false;

let mut input2 = false;

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

Expand All @@ -32,27 +36,39 @@ pub fn parse(input: String) -> Parsed {
stdout = false;
stderr = false;
run = true;
input2 = false;
}

if line.trim().starts_with("# STDOUT:") {
append = false;
stdout = true;
stderr = false;
run = false;
input2 = false;
}

if line.trim().starts_with("# STDERR:") {
append = false;
stdout = true;
stderr = true;
run = false;
input2 = false;
}

if line.trim().starts_with("# IN2:") {
append = false;
stdout = false;
stderr = false;
run = false;
input2 = true;
}

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

if line.trim().starts_with("# EXPECT_FAIL") {
Expand Down Expand Up @@ -90,10 +106,18 @@ pub fn parse(input: String) -> Parsed {
out.expected_stderr = Some(format!("{line}\n"));
}
} else {
if let Some(input) = &mut out.input {
input.push_str(&format!("{line}\n"));
if input2 {
if let Some(input) = &mut out.input2 {
input.push_str(&format!("{line}\n"));
} else {
out.input2 = Some(format!("{line}\n"));
}
} else {
out.input = Some(format!("{line}\n"));
if let Some(input) = &mut out.input {
input.push_str(&format!("{line}\n"));
} else {
out.input = Some(format!("{line}\n"));
}
}
}
}
Expand Down

0 comments on commit 7fc32d9

Please sign in to comment.