Skip to content

Commit

Permalink
feat: parse script of records with a given name (#172)
Browse files Browse the repository at this point in the history
* feat: parse script of records with a given name

Signed-off-by: Rustom Shareef <rustom.shareef@gmail.com>

* add run_script_with_name{_async} to runner

Signed-off-by: Rustom Shareef <rustom.shareef@gmail.com>

---------

Signed-off-by: Rustom Shareef <rustom.shareef@gmail.com>
  • Loading branch information
RustomMS authored Mar 11, 2023
1 parent f7c12f7 commit 33e9c11
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions sqllogictest/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,14 @@ pub fn parse<T: ColumnType>(script: &str) -> Result<Vec<Record<T>>, ParseError>
parse_inner(&Location::new("<unknown>", 0), script)
}

/// Parse a sqllogictest script into a list of records with a given script name.
pub fn parse_with_name<T: ColumnType>(
script: &str,
name: impl Into<Arc<str>>,
) -> Result<Vec<Record<T>>, ParseError> {
parse_inner(&Location::new(name, 0), script)
}

#[allow(clippy::collapsible_match)]
fn parse_inner<T: ColumnType>(loc: &Location, script: &str) -> Result<Vec<Record<T>>, ParseError> {
let mut lines = script.lines().enumerate().peekable();
Expand Down
19 changes: 19 additions & 0 deletions sqllogictest/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,16 @@ impl<D: AsyncDB> Runner<D> {
self.run_multi_async(records).await
}

/// Run a sqllogictest script with a given script name.
pub async fn run_script_with_name_async(
&mut self,
script: &str,
name: impl Into<Arc<str>>,
) -> Result<(), TestError> {
let records = parse_with_name(script, name).expect("failed to parse sqllogictest");
self.run_multi_async(records).await
}

/// Run a sqllogictest file.
pub async fn run_file_async(&mut self, filename: impl AsRef<Path>) -> Result<(), TestError> {
let records = parse_file(filename)?;
Expand All @@ -813,6 +823,15 @@ impl<D: AsyncDB> Runner<D> {
block_on(self.run_script_async(script))
}

/// Run a sqllogictest script with a given script name.
pub fn run_script_with_name(
&mut self,
script: &str,
name: impl Into<Arc<str>>,
) -> Result<(), TestError> {
block_on(self.run_script_with_name_async(script, name))
}

/// Run a sqllogictest file.
pub fn run_file(&mut self, filename: impl AsRef<Path>) -> Result<(), TestError> {
block_on(self.run_file_async(filename))
Expand Down

0 comments on commit 33e9c11

Please sign in to comment.