mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 18:58:30 +00:00
feat: add integration eval tests base
This commit is contained in:
parent
a76da9feb2
commit
529bd51bb2
4 changed files with 53 additions and 0 deletions
20
tests/eval/basic.rs
Normal file
20
tests/eval/basic.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
use crate::eval::eval_code;
|
||||
|
||||
#[test]
|
||||
fn eval_print() {
|
||||
assert_eq!(eval_code("print! 1").stdout, "1\n");
|
||||
assert!(!eval_code("print 0").stderr.is_empty());
|
||||
assert_eq!(eval_code("print! \"abc\"").stdout, "abc\n");
|
||||
assert_eq!(eval_code("print! \"0.3\"").stdout, "0.3\n");
|
||||
assert_eq!(eval_code("num = -3\nprint! num * 2").stdout, "-6\n");
|
||||
assert_eq!(eval_code("print True").status.code().unwrap(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn eval_assert() {
|
||||
assert!(eval_code("assert True").status.success());
|
||||
assert!(!eval_code("assert False").status.success());
|
||||
assert_eq!(eval_code("assert 1").status.code().unwrap(), 0);
|
||||
assert!(!eval_code("assert 0.2").status.success());
|
||||
assert!(eval_code("flag = True\nassert flag").status.success());
|
||||
}
|
8
tests/eval/literal.rs
Normal file
8
tests/eval/literal.rs
Normal file
|
@ -0,0 +1,8 @@
|
|||
use crate::eval::eval_code;
|
||||
|
||||
#[test]
|
||||
fn eval_int() {
|
||||
assert!(eval_code("assert 100 == 100").status.success());
|
||||
assert_eq!(eval_code("print! \"abc\"").stdout, "abc\n");
|
||||
assert_eq!(eval_code("print! \"0.3\"").stdout, "0.3\n");
|
||||
}
|
24
tests/eval/mod.rs
Normal file
24
tests/eval/mod.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
use erg_common::style::{colors::DEBUG_MAIN, RESET};
|
||||
use std::process::Command;
|
||||
|
||||
mod basic;
|
||||
mod literal;
|
||||
|
||||
pub(crate) struct CommandOutput {
|
||||
pub(crate) stdout: String,
|
||||
pub(crate) stderr: String,
|
||||
pub(crate) status: std::process::ExitStatus,
|
||||
}
|
||||
|
||||
pub(crate) fn eval_code(code: &'static str) -> CommandOutput {
|
||||
println!("{DEBUG_MAIN}[test] eval:\n{code}{RESET}");
|
||||
let output = Command::new(env!(concat!("CARGO_BIN_EXE_", env!("CARGO_PKG_NAME"))))
|
||||
.args(["-c", code])
|
||||
.output()
|
||||
.unwrap();
|
||||
CommandOutput {
|
||||
stdout: String::from_utf8(output.stdout).unwrap(),
|
||||
stderr: String::from_utf8(output.stderr).unwrap(),
|
||||
status: output.status,
|
||||
}
|
||||
}
|
1
tests/eval_tests.rs
Normal file
1
tests/eval_tests.rs
Normal file
|
@ -0,0 +1 @@
|
|||
mod eval;
|
Loading…
Add table
Add a link
Reference in a new issue