mirror of
https://github.com/HigherOrderCO/Kind1.git
synced 2024-10-26 12:27:36 +03:00
tests: added erasure tests
This commit is contained in:
parent
7b9c711b1a
commit
94e979e3d3
2
crates/kind-tests/suite/erasure/Ignores.golden
Normal file
2
crates/kind-tests/suite/erasure/Ignores.golden
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
Main = 3
|
5
crates/kind-tests/suite/erasure/Ignores.kind2
Normal file
5
crates/kind-tests/suite/erasure/Ignores.kind2
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
Kek <a: U60> : U60
|
||||||
|
Kek a = a
|
||||||
|
|
||||||
|
Main : U60
|
||||||
|
Main = 3
|
6
crates/kind-tests/suite/erasure/Removes.golden
Normal file
6
crates/kind-tests/suite/erasure/Removes.golden
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
Main = (Kuk)
|
||||||
|
|
||||||
|
Kuk = (Kek 3)
|
||||||
|
|
||||||
|
Kek a = a
|
8
crates/kind-tests/suite/erasure/Removes.kind2
Normal file
8
crates/kind-tests/suite/erasure/Removes.kind2
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
Kek (a: U60) : U60
|
||||||
|
Kek a = a
|
||||||
|
|
||||||
|
Main : U60
|
||||||
|
Main = (Kuk) ~(20)
|
||||||
|
|
||||||
|
Kuk : ~(a : U60) -> U60
|
||||||
|
Kuk = ~x => Kek 3
|
10
crates/kind-tests/suite/erasure/fail/ErrInType.golden
Normal file
10
crates/kind-tests/suite/erasure/fail/ErrInType.golden
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
ERROR This irrelevant parameter should not be used in a relevant position.
|
||||||
|
|
||||||
|
/--[suite/erasure/fail/ErrInType.kind2:2:8]
|
||||||
|
|
|
||||||
|
1 | Main : Type
|
||||||
|
2 | Main = Type
|
||||||
|
| v---
|
||||||
|
| \It's in relevant position!
|
||||||
|
|
||||||
|
|
2
crates/kind-tests/suite/erasure/fail/ErrInType.kind2
Normal file
2
crates/kind-tests/suite/erasure/fail/ErrInType.kind2
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Main : Type
|
||||||
|
Main = Type
|
11
crates/kind-tests/suite/erasure/fail/ShouldErr.golden
Normal file
11
crates/kind-tests/suite/erasure/fail/ShouldErr.golden
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
ERROR This irrelevant parameter should not be used in a relevant position.
|
||||||
|
|
||||||
|
/--[suite/erasure/fail/ShouldErr.kind2:2:9]
|
||||||
|
|
|
||||||
|
1 | Kek <a: U60> : U60
|
||||||
|
2 | Kek a = a
|
||||||
|
| v
|
||||||
|
| \It's in relevant position!
|
||||||
|
3 |
|
||||||
|
|
||||||
|
|
8
crates/kind-tests/suite/erasure/fail/ShouldErr.kind2
Normal file
8
crates/kind-tests/suite/erasure/fail/ShouldErr.kind2
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
Kek <a: U60> : U60
|
||||||
|
Kek a = a
|
||||||
|
|
||||||
|
Main : U60
|
||||||
|
Main = (Kuk) ~(20)
|
||||||
|
|
||||||
|
Kuk : ~(a : U60) -> U60
|
||||||
|
Kuk = ~x => Kek 3
|
@ -13,7 +13,7 @@ use walkdir::{Error, WalkDir};
|
|||||||
|
|
||||||
use kind_driver as driver;
|
use kind_driver as driver;
|
||||||
|
|
||||||
fn golden_test(path: &Path, run: fn(&Path) -> String) {
|
fn golden_test(path: &Path, run: &dyn Fn(&Path) -> String) {
|
||||||
let result = run(path);
|
let result = run(path);
|
||||||
|
|
||||||
let golden_path = path.with_extension("golden");
|
let golden_path = path.with_extension("golden");
|
||||||
@ -25,12 +25,36 @@ fn golden_test(path: &Path, run: fn(&Path) -> String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_kind2(path: &Path, run: fn(&Path) -> String) -> Result<(), Error> {
|
fn test_kind2(path: &Path, run: fn(&PathBuf, &mut Session) -> Option<String>) -> Result<(), Error> {
|
||||||
for entry in WalkDir::new(path).follow_links(true) {
|
for entry in WalkDir::new(path).follow_links(true) {
|
||||||
let entry = entry?;
|
let entry = entry?;
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
if path.is_file() && path.extension().map(|x| x == "kind2").unwrap_or(false) {
|
if path.is_file() && path.extension().map(|x| x == "kind2").unwrap_or(false) {
|
||||||
golden_test(path, run);
|
golden_test(path, &|path| {
|
||||||
|
let (rx, tx) = std::sync::mpsc::channel();
|
||||||
|
let root = PathBuf::from("./suite/lib").canonicalize().unwrap();
|
||||||
|
let mut session = Session::new(root, rx);
|
||||||
|
|
||||||
|
let res = run(&PathBuf::from(path), &mut session);
|
||||||
|
|
||||||
|
let diagnostics = tx.try_iter().collect::<Vec<Box<dyn Diagnostic>>>();
|
||||||
|
let render = RenderConfig::ascii(2);
|
||||||
|
|
||||||
|
kind_report::check_if_colors_are_supported(true);
|
||||||
|
|
||||||
|
match res {
|
||||||
|
Some(res) if diagnostics.is_empty() => res,
|
||||||
|
_ => {
|
||||||
|
let mut res_string = String::new();
|
||||||
|
|
||||||
|
for diag in diagnostics {
|
||||||
|
diag.render(&session, &render, &mut res_string).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
res_string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -39,31 +63,10 @@ fn test_kind2(path: &Path, run: fn(&Path) -> String) -> Result<(), Error> {
|
|||||||
#[test]
|
#[test]
|
||||||
#[timeout(30000)]
|
#[timeout(30000)]
|
||||||
fn test_checker() -> Result<(), Error> {
|
fn test_checker() -> Result<(), Error> {
|
||||||
test_kind2(Path::new("./suite/checker"), |path| {
|
test_kind2(Path::new("./suite/checker"), |path, session| {
|
||||||
let (rx, tx) = std::sync::mpsc::channel();
|
|
||||||
let root = PathBuf::from("./suite/lib").canonicalize().unwrap();
|
|
||||||
let mut session = Session::new(root, rx);
|
|
||||||
|
|
||||||
let entrypoints = vec!["Main".to_string()];
|
let entrypoints = vec!["Main".to_string()];
|
||||||
let check = driver::type_check_book(&mut session, &PathBuf::from(path), entrypoints, Some(1));
|
let check = driver::type_check_book(session, path, entrypoints, Some(1));
|
||||||
|
check.map(|_| "Ok!".to_string()).ok()
|
||||||
let diagnostics = tx.try_iter().collect::<Vec<Box<dyn Diagnostic>>>();
|
|
||||||
let render = RenderConfig::ascii(2);
|
|
||||||
|
|
||||||
kind_report::check_if_colors_are_supported(true);
|
|
||||||
|
|
||||||
match check {
|
|
||||||
Ok(_) if diagnostics.is_empty() => "Ok!".to_string(),
|
|
||||||
_ => {
|
|
||||||
let mut res_string = String::new();
|
|
||||||
|
|
||||||
for diag in diagnostics {
|
|
||||||
diag.render(&mut session, &render, &mut res_string).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
res_string
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})?;
|
})?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -71,69 +74,35 @@ fn test_checker() -> Result<(), Error> {
|
|||||||
#[test]
|
#[test]
|
||||||
#[timeout(15000)]
|
#[timeout(15000)]
|
||||||
fn test_eval() -> Result<(), Error> {
|
fn test_eval() -> Result<(), Error> {
|
||||||
test_kind2(Path::new("./suite/eval"), |path| {
|
test_kind2(Path::new("./suite/eval"), |path, session| {
|
||||||
let (rx, tx) = std::sync::mpsc::channel();
|
|
||||||
let root = PathBuf::from("./suite/lib").canonicalize().unwrap();
|
|
||||||
let mut session = Session::new(root, rx);
|
|
||||||
|
|
||||||
let entrypoints = vec!["Main".to_string()];
|
let entrypoints = vec!["Main".to_string()];
|
||||||
let check = driver::erase_book(&mut session, &PathBuf::from(path), entrypoints)
|
let check = driver::erase_book(session, path, entrypoints)
|
||||||
.map(|x| driver::compile_book_to_hvm(x, false));
|
.map(|file| driver::compile_book_to_hvm(file, false))
|
||||||
|
.map(|file| driver::execute_file(&file.to_string(), Some(1)).map_or_else(|e| e, |f| f));
|
||||||
|
|
||||||
let diagnostics = tx.try_iter().collect::<Vec<_>>();
|
check.ok()
|
||||||
let render = RenderConfig::ascii(2);
|
|
||||||
|
|
||||||
kind_report::check_if_colors_are_supported(true);
|
|
||||||
|
|
||||||
match check {
|
|
||||||
Ok(file) if diagnostics.is_empty() => {
|
|
||||||
driver::execute_file(&file.to_string(), Some(1)).map_or_else(|e| e, |f| f)
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
let mut res_string = String::new();
|
|
||||||
|
|
||||||
for diag in diagnostics {
|
|
||||||
diag.render(&mut session, &render, &mut res_string).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
res_string
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})?;
|
})?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[timeout(15000)]
|
#[timeout(15000)]
|
||||||
fn test_kdl() -> Result<(), Error> {
|
fn test_kdl() -> Result<(), Error> {
|
||||||
test_kind2(Path::new("./suite/kdl"), |path| {
|
test_kind2(Path::new("./suite/kdl"), |path, session| {
|
||||||
let (rx, tx) = std::sync::mpsc::channel();
|
|
||||||
let root = PathBuf::from("./suite/lib").canonicalize().unwrap();
|
|
||||||
let mut session = Session::new(root, rx);
|
|
||||||
|
|
||||||
let entrypoints = vec!["Main".to_string()];
|
let entrypoints = vec!["Main".to_string()];
|
||||||
let check = driver::compile_book_to_kdl(&PathBuf::from(path), &mut session, "", entrypoints);
|
let check = driver::compile_book_to_kdl(path, session, "", entrypoints);
|
||||||
|
check.ok().map(|x| x.to_string())
|
||||||
let diagnostics = tx.try_iter().collect::<Vec<_>>();
|
})?;
|
||||||
let render = RenderConfig::ascii(2);
|
Ok(())
|
||||||
|
}
|
||||||
kind_report::check_if_colors_are_supported(true);
|
|
||||||
|
#[test]
|
||||||
match check {
|
#[timeout(15000)]
|
||||||
Ok(file) if diagnostics.is_empty() => {
|
fn test_erasure() -> Result<(), Error> {
|
||||||
file.to_string()
|
test_kind2(Path::new("./suite/erasure"), |path, session| {
|
||||||
},
|
let entrypoints = vec!["Main".to_string()];
|
||||||
_ => {
|
let check = driver::erase_book(session, path, entrypoints).map(|file| file.to_string());
|
||||||
let mut res_string = String::new();
|
check.ok()
|
||||||
|
|
||||||
for diag in diagnostics {
|
|
||||||
diag.render(&mut session, &render, &mut res_string).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
res_string
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})?;
|
})?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user