-
Notifications
You must be signed in to change notification settings - Fork 31
feat(expression_domain_testing): Create a testing suite for expression domains #1630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
ca1umac
wants to merge
14
commits into
main
Choose a base branch
from
domain_of_testing_suite
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
5780cc8
feat(domain_debugging): Basic outline
ca1umac 475aa8d
updating error printing
ca1umac 1a9627e
re-correct
ca1umac 4cc02a5
Putting the ExprInfo struct into the model file
ca1umac a724523
change from expr_ to expression-, finish moving Info struct out of CL…
ca1umac 91bb91c
remove redundant closure
ca1umac 5175bf3
Merge branch 'main' into testing-new-domain-output-format
ca1umac 3e8ae40
init
ca1umac 2d177aa
making clippy happy, part two electric boogaloo
ca1umac 9211e3f
Merge branch 'testing-new-domain-output-format' into domain_of_testin…
ca1umac 3696115
stash
ca1umac 38983a0
stash
ca1umac c1e4152
stash
ca1umac 6fb1596
fixed some of the function signatures, added function that'll run for…
ca1umac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 @@ | ||
| # Domain Tightening Tests | ||
| These tests are designed to check whether or not the pruning stage reduces the domains of expressions without making them invalid. | ||
|
|
||
| They will work by running the same underlying functions used in the `pretty <> --output-format=expression-domains` command. | ||
|
|
||
| The general steps of the algorithm (TBC) will likely involve: | ||
| 1. Parse essence file | ||
| 2. Get the domains of the expressions | ||
|
|
||
| We can then add subsequent steps that will run some ac-style algorithm and recheck the domains. | ||
|
|
||
| ## How to Run | ||
| cargo test tests_domain_tightening |
This file contains hidden or 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,114 @@ | ||
| use std::{ | ||
| env, | ||
| error::Error, | ||
| fs, | ||
| sync::{Arc, RwLock}, | ||
| }; | ||
|
|
||
| use conjure_cp::parse::tree_sitter::{parse_essence_file, parse_essence_file_native}; | ||
| use conjure_cp::settings::Parser; | ||
| use conjure_cp::{ | ||
| Model, ast::ExprInfo, context::Context, parse::tree_sitter::errors::ParseErrorCollection, | ||
| }; | ||
| use tests_integration::TestConfig; | ||
|
|
||
| /// Parser function used by expression domain tests. | ||
| type ParseFn = fn(&str, Arc<RwLock<Context<'static>>>) -> Result<Model, Box<ParseErrorCollection>>; | ||
|
|
||
| /// Runs a test for one model using each configured parser | ||
| fn expression_domain_test( | ||
| path: &str, | ||
| filename: &str, | ||
| extension: &str, | ||
| ) -> Result<(), Box<dyn Error>> { | ||
| let accept = env::var("ACCEPT").unwrap_or("false".to_string()) == "true"; | ||
|
|
||
| let file_config: TestConfig = | ||
| if let Ok(config_contents) = fs::read_to_string(format!("{path}/config.toml")) { | ||
| toml::from_str(&config_contents).unwrap() | ||
| } else { | ||
| Default::default() | ||
| }; | ||
|
|
||
| if accept { | ||
| clean_test_dir_for_accept(path)?; | ||
| } | ||
|
|
||
| let parsers = file_config | ||
| .configured_parsers() | ||
| .map_err(|err| std::io::Error::new(std::io::ErrorKind::InvalidInput, err))?; | ||
|
|
||
| for parser in parsers { | ||
| let case_name = parser.to_string(); | ||
| let parse = match parser { | ||
| Parser::TreeSitter => parse_essence_file_native, | ||
| Parser::ViaConjure => parse_essence_file, | ||
| }; | ||
| expression_domain_test_inner(path, filename, &case_name, extension, parse)?; | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| fn expression_domain_test_inner( | ||
| path: &str, | ||
| input_filename: &str, | ||
| case_name: &str, | ||
| extension: &str, | ||
| parse: ParseFn, | ||
| ) -> Result<(), Box<dyn Error>> { | ||
| unimplemented!() | ||
| } | ||
|
|
||
| fn clean_test_dir_for_accept(path: &str) -> Result<(), std::io::Error> { | ||
| for entry in std::fs::read_dir(path)? { | ||
| let entry = entry?; | ||
| let file_name = entry.file_name(); | ||
| let file_name = file_name.to_string_lossy(); | ||
| let entry_path = entry.path(); | ||
|
|
||
| if entry_path.is_dir() { | ||
| continue; | ||
| } | ||
|
|
||
| let keep = if file_name == "config.toml" { | ||
| true | ||
| } else { | ||
| let is_model_file = entry_path | ||
| .extension() | ||
| .and_then(|ext| ext.to_str()) | ||
| .is_some_and(|ext| ext == "essence"); | ||
| let is_generated_or_expected = | ||
| file_name.contains(".generated") || file_name.contains(".expected"); | ||
| is_model_file && !is_generated_or_expected | ||
| }; | ||
|
|
||
| if keep { | ||
| continue; | ||
| } | ||
|
|
||
| std::fs::remove_file(entry_path)?; | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| /// Returns the saved expression JSON path | ||
| fn expression_domains_json_path(path: &str, case_name: &str, file_type: &str) -> String { | ||
| format!("{path}/{case_name}.{file_type}.serialised.json") | ||
| } | ||
|
|
||
| /// Reads and initialises a saved expression domains snapshot. | ||
| fn read_expression_domains_json( | ||
| context: &Arc<RwLock<Context<'static>>>, | ||
| path: &str, | ||
| case_name: &str, | ||
| file_type: &str, | ||
| ) -> Result<Vec<ExprInfo>, std::io::Error> { | ||
| let serialised = fs::read_to_string(expression_domains_json_path(path, case_name, file_type))?; | ||
| let exprs: Vec<ExprInfo> = serde_json::from_str(&serialised).map_err(std::io::Error::other)?; | ||
|
|
||
| Ok(exprs) | ||
| } | ||
|
|
||
| // include!(concat!(env!("OUT_DIR"), "/gen_tests_domain_tightening.rs")); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function is completely copied from roundtrip testing. With the changes from #1548 , I can see:
acceptenv varas very standard in any testing framework. Should this be generalised?
All you would need to add would be a function pointer to the function signature so that it could run whatever function for each test (e.g.
expression_domain_test_inner).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same is also true for the
clean_test_dir_for_acceptfunction, except that wouldn't need any modification