diff --git a/sqllogictest/src/parser.rs b/sqllogictest/src/parser.rs index c6ae90e..a4b3e14 100644 --- a/sqllogictest/src/parser.rs +++ b/sqllogictest/src/parser.rs @@ -68,27 +68,34 @@ impl Location { } } +/// Expectation for a statement. #[derive(Debug, Clone, PartialEq)] pub enum StatementExpect { - None, + /// Statement should succeed. + Ok, + /// Statement should succeed and return the given number of rows. Count(u64), + /// Statement should fail with the given error message. Error(ExpectedError), } +/// Expectation for a query. #[derive(Debug, Clone, PartialEq)] pub enum QueryExpect { + /// Query should succeed and return the given results. Results { types: Vec, sort_mode: Option, label: Option, results: Vec, }, + /// Query should fail with the given error message. Error(ExpectedError), } #[cfg(test)] impl QueryExpect { - fn default_results() -> Self { + fn empty_results() -> Self { Self::Results { types: Vec::new(), sort_mode: None, @@ -200,7 +207,7 @@ impl std::fmt::Display for Record { } => { write!(f, "statement ")?; match expected { - StatementExpect::None => write!(f, "ok")?, + StatementExpect::Ok => write!(f, "ok")?, StatementExpect::Count(cnt) => write!(f, "count {cnt}")?, StatementExpect::Error(err) => err.fmt_inline(f)?, } @@ -677,7 +684,7 @@ fn parse_inner(loc: &Location, script: &str) -> Result { - let mut expected = StatementExpect::None; + let mut expected = StatementExpect::Ok; match res { ["ok"] => {} ["error", tokens @ ..] => { @@ -1011,7 +1018,7 @@ select * from foo; conditions: vec![], connection: Connection::Default, sql: "select * from foo;".to_string(), - expected: QueryExpect::default_results(), + expected: QueryExpect::empty_results(), }] ); } diff --git a/sqllogictest/src/runner.rs b/sqllogictest/src/runner.rs index 632c7e9..b26ce4f 100644 --- a/sqllogictest/src/runner.rs +++ b/sqllogictest/src/runner.rs @@ -814,7 +814,7 @@ impl> Runner { .at(loc)); } } - (None, StatementExpect::None) => {} + (None, StatementExpect::Ok) => {} (Some(e), StatementExpect::Error(expected_error)) => { if !expected_error.is_match(&e.to_string()) { return Err(TestErrorKind::ErrorMismatch { @@ -826,7 +826,7 @@ impl> Runner { .at(loc)); } } - (Some(e), StatementExpect::Count(_) | StatementExpect::None) => { + (Some(e), StatementExpect::Count(_) | StatementExpect::Ok) => { return Err(TestErrorKind::Fail { sql, err: Arc::new(e), @@ -1231,7 +1231,7 @@ pub fn update_record_with_output( loc, conditions, connection, - expected: expected @ (StatementExpect::None | StatementExpect::Count(_)), + expected: expected @ (StatementExpect::Ok | StatementExpect::Count(_)), }, RecordOutput::Query { error: None, .. }, ) => { @@ -1265,7 +1265,7 @@ pub fn update_record_with_output( loc, conditions, connection, - expected: StatementExpect::None, + expected: StatementExpect::Ok, }), // statement, statement ( @@ -1286,7 +1286,7 @@ pub fn update_record_with_output( connection, expected: match expected { StatementExpect::Count(_) => StatementExpect::Count(*count), - StatementExpect::Error(_) | StatementExpect::None => StatementExpect::None, + StatementExpect::Error(_) | StatementExpect::Ok => StatementExpect::Ok, }, }), // Error match @@ -1299,7 +1299,7 @@ pub fn update_record_with_output( (Some(e), r) => { let reference = match &r { StatementExpect::Error(e) => Some(e), - StatementExpect::Count(_) | StatementExpect::None => None, + StatementExpect::Count(_) | StatementExpect::Ok => None, }; Some(Record::Statement { sql,