-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Testing: Set up basic example parse tests (#404)
* Indentation * Build testing for example files * Fmt
- Loading branch information
Showing
6 changed files
with
142 additions
and
45 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,3 +58,4 @@ strum = "0.26.2" | |
strum_macros = "0.26.2" | ||
pretty_assertions = "1.0" | ||
rand = "0.9.0-alpha.1" | ||
walkdir = "2.5.0" |
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
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,81 @@ | ||
// Integration tests | ||
use log::info; | ||
use std::fs; | ||
use std::path::PathBuf; | ||
use walkdir::{DirEntry, WalkDir}; | ||
|
||
const EXAMPLES_DIR: &'static str = "../examples"; | ||
|
||
const EXCEPTIONS: &'static [&'static str] = &[ | ||
"contexts.tk", | ||
"enums.tk", | ||
"fib.tk", | ||
"fib_acc.tk", | ||
"generic_abstract_data_types.tk", | ||
"instances.tk", | ||
"vector_transpose.tk", | ||
"vector_transpose_failing.tk", | ||
]; | ||
|
||
fn is_hidden(entry: &DirEntry) -> bool { | ||
entry | ||
.file_name() | ||
.to_str() | ||
.map(|s| s.starts_with(".")) | ||
.unwrap_or(false) | ||
} | ||
|
||
fn find_files() -> Result<Vec<PathBuf>, walkdir::Error> { | ||
let walker = WalkDir::new(EXAMPLES_DIR).into_iter(); | ||
let mut paths = vec![]; | ||
for entry in walker.filter_entry(|e| !is_hidden(e)) { | ||
let entry = entry?; | ||
let meta = entry.metadata()?; | ||
if !meta.is_file() { | ||
continue; | ||
} | ||
let path = entry.path(); | ||
let name = path | ||
.file_name() | ||
.expect("Require that file names can be printed") | ||
.to_str() | ||
.expect("OSString to str"); | ||
if EXCEPTIONS.contains(&name) { | ||
info!("Skipping exception: {name}"); | ||
continue; | ||
} | ||
paths.push(path.to_path_buf()); | ||
} | ||
Ok(paths) | ||
} | ||
|
||
#[test] | ||
fn find_example_files() { | ||
let files = find_files().expect("Should be able to walk files"); | ||
info!("Files: {files:#?}"); | ||
let num_files = files.len(); | ||
assert_eq!( | ||
num_files, 1, | ||
"Example files appear to be missing, found {num_files}" | ||
); | ||
} | ||
|
||
#[test] | ||
fn parse_example_files() { | ||
let mut files = find_files().expect("Should be able to walk files"); | ||
files.sort(); | ||
|
||
for file in files { | ||
info!("Start: {file:#?}"); | ||
let contents = fs::read_to_string(&file).expect("Should have been able to read the file"); | ||
|
||
let tokens = crate::parser::tokens::lex(&contents) | ||
.expect(&format!("Should be able to lex: {file:?}")); | ||
|
||
info!("Tokens: {tokens:#?}"); | ||
|
||
let _ast = crate::parser::parse(&file, &contents, &tokens) | ||
.expect(&format!("Should be able to parse: {file:?}")); | ||
info!("Done: {file:#?}"); | ||
} | ||
} |