-
Notifications
You must be signed in to change notification settings - Fork 36
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
Add conformance testing DSL #826
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
318a8ea
Add conformance testing DSL implementation, CI/CD runner, and user ta…
nirosys 2c3808d
Fix remaining paths for ion 1.0 iontestdata
nirosys ad2b1ac
Handle typed nulls in read_resolved
nirosys 1743ea4
Add support for more data model clauses
nirosys a951e27
Remove left over comments; fix byte range; support multiple string in…
nirosys a8e2538
Update 1.1 skip list to address ion-test path changes
nirosys 703bba0
Address clippy checks, remove unused test
nirosys cf5dd98
Drop path separators from path replacement so the canonicalized windo…
nirosys 6811fbf
Remove conformance cli from default tests
nirosys 51b75f3
Add encoding and mactab fragments
nirosys 5204862
Add timestamp to denote data model
nirosys 2a69f4e
Missed some uses when --patch'ing
nirosys 499e649
Address PR feedback; Remove unused Each variant of Fragment since it …
nirosys 138f6b2
Merge remote-tracking branch 'origin/main' into rgiliam/conformance_t…
nirosys 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 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,54 @@ | ||
|
||
#[cfg(feature = "experimental-reader-writer")] | ||
mod conformance_dsl; | ||
|
||
#[cfg(feature = "experimental-reader-writer")] | ||
pub fn main() { | ||
use crate::conformance_dsl::prelude::*; | ||
|
||
let test_paths = std::env::args().skip(1).collect::<Vec<String>>(); | ||
let mut errors: Vec<(String, String, conformance_dsl::ConformanceError)> = vec!(); | ||
|
||
println!("Testing {} conformance collections.\n", test_paths.len()); | ||
|
||
let mut failures = 0; | ||
|
||
for test_path in test_paths { | ||
println!("\nRunning tests: {} ========================", test_path); | ||
let collection = TestCollection::load(&test_path).expect("unable to load test file"); | ||
let name_len = collection.iter().fold(0, |acc, d| std::cmp::max(acc, d.name.as_ref().map_or(0, |n| n.len()))); | ||
|
||
for doc in collection.iter() { | ||
match doc.name.as_ref() { | ||
Some(n) => print!(" {:<width$}", n, width = name_len), | ||
None => print!(" {:<width$}", "<unnamed>", width = name_len), | ||
} | ||
|
||
print!(" ... "); | ||
match doc.run() { | ||
Err(e) => { | ||
println!("[FAILED]"); | ||
failures += 1; | ||
errors.push((test_path.to_owned(), doc.name.as_deref().unwrap_or("<unnamed>").to_owned(), e.clone())); | ||
} | ||
Ok(_) => println!("[OK]"), | ||
} | ||
} | ||
} | ||
|
||
for (test_path, test_name, err) in errors { | ||
println!("-------------------------"); | ||
println!("File: {}", test_path); | ||
println!("Test: {}", test_name); | ||
println!("Error: {:?}", err); | ||
} | ||
|
||
if failures > 0 { | ||
panic!("Conformance test(s) failed"); | ||
} | ||
} | ||
|
||
#[cfg(not(feature = "experimental-reader-writer"))] | ||
pub fn main() { | ||
println!("Needs feature experimental-reader-writer"); | ||
} |
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,160 @@ | ||
//! A Clause represents the DSL's S-Expression operations for defining tests. Each possible | ||
//! expression should come from a Clause. | ||
//! | ||
//! The grammar defining each of the clauses can be found [here][Grammar]. | ||
//! | ||
//! [Grammar]: https://github.com/amazon-ion/ion-tests/blob/master/conformance/README.md#grammar | ||
|
||
use std::str::FromStr; | ||
|
||
use ion_rs::{Element, Sequence}; | ||
|
||
use super::*; | ||
|
||
/// Represents each type of S-Expression Clause that we can have in the DSL. This currently does | ||
/// not capture the Data Model clauses used in Denotes fragments. | ||
#[allow(non_camel_case_types)] | ||
#[derive(Debug)] | ||
pub(crate) enum ClauseType { | ||
/// Start an ion 1.0 test document. | ||
Ion1_0, | ||
/// Start an ion 1.1 test document. | ||
Ion1_1, | ||
/// Start a test document that validates both ion 1.1 and 1.0 | ||
Ion1_X, | ||
/// Provide a string as text ion, that will be inserted into the test document. | ||
Text, | ||
/// Provide a sequence of bytes that is interpreted as binary ion, that will be inserted into | ||
/// the document. | ||
Binary, | ||
/// Provide a major and minor version that will be emitted into the document as an IVM. | ||
Ivm, | ||
/// Specify a ion data to be inserted into the document, using inline ion syntax. | ||
TopLevel, | ||
/// Provide ion data defining the contents of an '$ion_encoding' directive. | ||
Encoding, | ||
/// Provide ion data defining the contents of a macro table wrapped by a module within an encoding directive. | ||
MacTab, | ||
/// Define data that is expected to be produced by the test's document, using inline ion | ||
/// syntax. | ||
Produces, | ||
/// Define data that is expected to be produced by the test's document, using a clause-based | ||
/// data model. | ||
Denotes, | ||
/// Specify that the test should signal (fail). | ||
Signals, | ||
/// Evaluate the logical conjunction of the clause's arguments. | ||
And, | ||
/// Negate the evaluation of the clause's argument. | ||
Not, | ||
/// A continuation that allows for the chaining of fragments and expectations. | ||
Then, | ||
/// Specify the start of a test. | ||
Document, | ||
/// Combine one or more continuations with a parent document separately. | ||
Each, | ||
/// Define a symbol using both text and symbol id for testing in a denotes clause. | ||
Absent, | ||
} | ||
|
||
impl FromStr for ClauseType { | ||
type Err = ConformanceErrorKind; | ||
|
||
fn from_str(s: &str) -> InnerResult<Self> { | ||
use ClauseType::*; | ||
|
||
match s { | ||
"ion_1_0" => Ok(Ion1_0), | ||
"ion_1_1" => Ok(Ion1_1), | ||
"ion_1_x" => Ok(Ion1_X), | ||
"document" => Ok(Document), | ||
"toplevel" => Ok(TopLevel), | ||
"produces" => Ok(Produces), | ||
"denotes" => Ok(Denotes), | ||
"text" => Ok(Text), | ||
"binary" => Ok(Binary), | ||
"and" => Ok(And), | ||
"not" => Ok(Not), | ||
"then" => Ok(Then), | ||
"each" => Ok(Each), | ||
"absent" => Ok(Absent), | ||
"ivm" => Ok(Ivm), | ||
"signals" => Ok(Signals), | ||
"encoding" => Ok(Encoding), | ||
"mactab" => Ok(MacTab), | ||
_ => Err(ConformanceErrorKind::UnknownClause(s.to_owned())), | ||
} | ||
} | ||
} | ||
|
||
impl ClauseType { | ||
|
||
/// Utility function to test if the Clause is a fragment node. | ||
pub fn is_fragment(&self) -> bool { | ||
use ClauseType::*; | ||
matches!(self, Text | Binary | Ivm | TopLevel | Encoding | MacTab) | ||
} | ||
|
||
/// Utility function to test if the Clause is an expectation node. | ||
pub fn is_expectation(&self) -> bool { | ||
use ClauseType::*; | ||
matches!(self, Produces | Denotes | Signals | And | Not) | ||
} | ||
} | ||
|
||
/// Represents a valid clause accepted by the conformance DSL for specifying a test. | ||
#[derive(Debug)] | ||
pub(crate) struct Clause { | ||
pub tpe: ClauseType, | ||
pub body: Vec<Element>, | ||
} | ||
|
||
impl TryFrom<&Sequence> for Clause { | ||
type Error = ConformanceErrorKind; | ||
|
||
fn try_from(other: &Sequence) -> InnerResult<Self> { | ||
let clause_type = other | ||
.iter() | ||
.next() | ||
.ok_or(ConformanceErrorKind::UnexpectedEndOfDocument)? | ||
.as_symbol() | ||
.ok_or(ConformanceErrorKind::ExpectedDocumentClause)?; | ||
|
||
let tpe = ClauseType::from_str(clause_type.text().ok_or(ConformanceErrorKind::ExpectedDocumentClause)?)?; | ||
let body: Vec<Element> = other.iter().skip(1).cloned().collect(); | ||
|
||
Ok(Clause { | ||
tpe, | ||
body, | ||
}) | ||
} | ||
} | ||
|
||
impl TryFrom<Sequence> for Clause { | ||
type Error = ConformanceErrorKind; | ||
|
||
fn try_from(other: Sequence) -> InnerResult<Self> { | ||
Self::try_from(&other) | ||
} | ||
} | ||
|
||
impl TryFrom<&[Element]> for Clause { | ||
type Error = ConformanceErrorKind; | ||
|
||
fn try_from(other: &[Element]) -> InnerResult<Self> { | ||
let clause_type = other | ||
.iter() | ||
.next() | ||
.ok_or(ConformanceErrorKind::UnexpectedEndOfDocument)? | ||
.as_symbol() | ||
.ok_or(ConformanceErrorKind::ExpectedDocumentClause)?; | ||
|
||
let tpe = ClauseType::from_str(clause_type.text().ok_or(ConformanceErrorKind::ExpectedDocumentClause)?)?; | ||
let body: Vec<Element> = other.iter().skip(1).cloned().collect(); | ||
|
||
Ok(Clause { | ||
tpe, | ||
body, | ||
}) | ||
} | ||
} |
Oops, something went wrong.
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.
Could you put this functionality in a
self.read_null()
method instead of having it happen inion_type()
?There are three other raw value types besides
LazyRawBinaryValue_1_1
:LazyRawBinaryValue_1_0
LazyRawTextValue_1_1
LazyRawTextValue_1_0
Each of them has an
ion_type()
method and I'm pretty sure at least some of them returnIonType::Null
if the value is a null value, even if it's a typed null. The behavior you've implemented is probably more correct, but if we make this change here we'd need to make it in the other three places too.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.
Added #828 to track this.
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.
ack, ty, I will follow up with that today.