Skip to content

Commit

Permalink
add docs
Browse files Browse the repository at this point in the history
Signed-off-by: Bugen Zhao <[email protected]>
  • Loading branch information
BugenZhao committed Nov 9, 2023
1 parent f48bd67 commit 9042231
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
17 changes: 12 additions & 5 deletions sqllogictest/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: ColumnType> {
/// Query should succeed and return the given results.
Results {
types: Vec<T>,
sort_mode: Option<SortMode>,
label: Option<String>,
results: Vec<String>,
},
/// Query should fail with the given error message.
Error(ExpectedError),
}

#[cfg(test)]
impl<T: ColumnType> QueryExpect<T> {
fn default_results() -> Self {
fn empty_results() -> Self {
Self::Results {
types: Vec::new(),
sort_mode: None,
Expand Down Expand Up @@ -200,7 +207,7 @@ impl<T: ColumnType> std::fmt::Display for Record<T> {
} => {
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)?,
}
Expand Down Expand Up @@ -677,7 +684,7 @@ fn parse_inner<T: ColumnType>(loc: &Location, script: &str) -> Result<Vec<Record
records.push(Record::Connection(conn));
}
["statement", res @ ..] => {
let mut expected = StatementExpect::None;
let mut expected = StatementExpect::Ok;
match res {
["ok"] => {}
["error", tokens @ ..] => {
Expand Down Expand Up @@ -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(),
}]
);
}
Expand Down
12 changes: 6 additions & 6 deletions sqllogictest/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ impl<D: AsyncDB, M: MakeConnection<Conn = D>> Runner<D, M> {
.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 {
Expand All @@ -826,7 +826,7 @@ impl<D: AsyncDB, M: MakeConnection<Conn = D>> Runner<D, M> {
.at(loc));
}
}
(Some(e), StatementExpect::Count(_) | StatementExpect::None) => {
(Some(e), StatementExpect::Count(_) | StatementExpect::Ok) => {
return Err(TestErrorKind::Fail {
sql,
err: Arc::new(e),
Expand Down Expand Up @@ -1231,7 +1231,7 @@ pub fn update_record_with_output<T: ColumnType>(
loc,
conditions,
connection,
expected: expected @ (StatementExpect::None | StatementExpect::Count(_)),
expected: expected @ (StatementExpect::Ok | StatementExpect::Count(_)),
},
RecordOutput::Query { error: None, .. },
) => {
Expand Down Expand Up @@ -1265,7 +1265,7 @@ pub fn update_record_with_output<T: ColumnType>(
loc,
conditions,
connection,
expected: StatementExpect::None,
expected: StatementExpect::Ok,
}),
// statement, statement
(
Expand All @@ -1286,7 +1286,7 @@ pub fn update_record_with_output<T: ColumnType>(
connection,
expected: match expected {
StatementExpect::Count(_) => StatementExpect::Count(*count),
StatementExpect::Error(_) | StatementExpect::None => StatementExpect::None,
StatementExpect::Error(_) | StatementExpect::Ok => StatementExpect::Ok,
},
}),
// Error match
Expand All @@ -1299,7 +1299,7 @@ pub fn update_record_with_output<T: ColumnType>(
(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,
Expand Down

0 comments on commit 9042231

Please sign in to comment.