-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from ozgurakgun/cases
Adding test cases and updating the tester
- Loading branch information
Showing
14 changed files
with
196 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
*.log | ||
coverage | ||
|
||
conjure_oxide/tests/**/*.generated.* | ||
|
||
## Rust | ||
debug/ | ||
target/ | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,55 @@ | ||
use std::{ | ||
env::var, | ||
fs::File, | ||
fs::{read_dir, DirEntry}, | ||
io::Write, | ||
path::Path, | ||
}; | ||
use std::env::var; | ||
use std::fs::{read_dir, File}; | ||
use std::io::{self, Write}; | ||
use std::path::Path; | ||
use walkdir::WalkDir; | ||
|
||
fn main() { | ||
let out_dir = var("OUT_DIR").unwrap(); | ||
fn main() -> io::Result<()> { | ||
let out_dir = var("OUT_DIR").map_err(|e| io::Error::new(io::ErrorKind::Other, e))?; // wrapping in a std::io::Error to match main's error type | ||
let dest = Path::new(&out_dir).join("gen_tests.rs"); | ||
let mut f = File::create(&dest).unwrap(); | ||
let mut f = File::create(&dest)?; | ||
|
||
let test_dir = "tests/integration"; | ||
for dir in read_dir(test_dir).unwrap() { | ||
write_test(&mut f, &dir.unwrap()); | ||
|
||
for subdir in WalkDir::new(test_dir) { | ||
let subdir = subdir?; | ||
if subdir.file_type().is_dir() { | ||
let essence_files: Vec<String> = read_dir(subdir.path())? | ||
.filter_map(Result::ok) | ||
.filter(|entry| { | ||
entry | ||
.path() | ||
.extension() | ||
.map_or(false, |ext| ext == "essence") | ||
}) | ||
.filter_map(|entry| { | ||
entry | ||
.path() | ||
.file_stem() | ||
.and_then(|stem| stem.to_str()) | ||
.map(|s| s.to_owned()) | ||
}) | ||
.collect(); | ||
|
||
write_test(&mut f, subdir.path().display().to_string(), essence_files)?; | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn write_test(file: &mut File, dir: &DirEntry) { | ||
let binding = dir.path(); | ||
let path = binding.to_str().unwrap(); | ||
write!( | ||
file, | ||
include_str!("./tests/gen_test_template"), | ||
name = path.replace("./", "").replace("/", "_"), | ||
path = path | ||
) | ||
.unwrap(); | ||
fn write_test(file: &mut File, path: String, essence_files: Vec<String>) -> io::Result<()> { | ||
// TODO: Consider supporting multiple Essence files? | ||
if essence_files.len() == 1 { | ||
write!( | ||
file, | ||
include_str!("./tests/gen_test_template"), | ||
// TODO: better sanitisation of paths to function names | ||
test_name = path.replace("./", "").replace("/", "_").replace("-", "_"), | ||
test_dir = path, | ||
essence_file = essence_files[0] | ||
) | ||
} else { | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
use std::{collections::HashMap, fs::File, io::Read}; | ||
use std::collections::HashMap; | ||
|
||
use conjure_oxide::ast::*; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#[test] | ||
fn {name}() -> Result<(), Box<dyn Error>> {{ | ||
integration_test("{path}") | ||
fn {test_name}() -> Result<(), Box<dyn Error>> {{ | ||
integration_test("{test_dir}", "{essence_file}") | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
find x : bool |
13 changes: 13 additions & 0 deletions
13
conjure_oxide/tests/integration/basic/bool-01/bool-01.expected.serialised.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"variables": [ | ||
[ | ||
{ | ||
"UserName": "x" | ||
}, | ||
{ | ||
"domain": "BoolDomain" | ||
} | ||
] | ||
], | ||
"constraints": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
find x, y : bool |
21 changes: 21 additions & 0 deletions
21
conjure_oxide/tests/integration/basic/bool-02/bool-02.expected.serialised.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"variables": [ | ||
[ | ||
{ | ||
"UserName": "y" | ||
}, | ||
{ | ||
"domain": "BoolDomain" | ||
} | ||
], | ||
[ | ||
{ | ||
"UserName": "x" | ||
}, | ||
{ | ||
"domain": "BoolDomain" | ||
} | ||
] | ||
], | ||
"constraints": [] | ||
} |
2 changes: 2 additions & 0 deletions
2
conjure_oxide/tests/integration/basic/bool-03/bool-03.essence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
find x, y : bool | ||
such that x != y |
21 changes: 21 additions & 0 deletions
21
conjure_oxide/tests/integration/basic/bool-03/bool-03.expected.serialised.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"variables": [ | ||
[ | ||
{ | ||
"UserName": "x" | ||
}, | ||
{ | ||
"domain": "BoolDomain" | ||
} | ||
], | ||
[ | ||
{ | ||
"UserName": "y" | ||
}, | ||
{ | ||
"domain": "BoolDomain" | ||
} | ||
] | ||
], | ||
"constraints": [] | ||
} |
Oops, something went wrong.