Skip to content

Commit

Permalink
feat: report error when include empty result (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
xxchan authored Jan 4, 2024
1 parent 0919ca0 commit 58673cb
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-semver-checks --version ^0.22 --locked
args: cargo-semver-checks --version ^0.27 --locked
- name: Check semver
run: |
cargo semver-checks check-release -p sqllogictest
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [0.19.1] - 2024-01-04

* parser: `include` now returns error if no file is matched.

## [0.19.0] - 2023-11-11

* parser: refactor `expect` field in sqllogictest parser to make it easier to work with.
Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver = "2"
members = ["sqllogictest", "sqllogictest-bin", "sqllogictest-engines", "tests"]

[workspace.package]
version = "0.19.0"
version = "0.19.1"
edition = "2021"
homepage = "https://github.com/risinglightdb/sqllogictest-rs"
keywords = ["sql", "database", "parser", "cli"]
Expand Down
7 changes: 3 additions & 4 deletions sqllogictest-bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,9 @@ async fn run_test_file<T: std::io::Write, M: MakeConnection>(
filename: impl AsRef<Path>,
) -> Result<Duration> {
let filename = filename.as_ref();
let records = tokio::task::block_in_place(|| {
sqllogictest::parse_file(filename).map_err(|e| anyhow!("{:?}", e))
})
.context("failed to parse sqllogictest file")?;
let records =
tokio::task::block_in_place(|| sqllogictest::parse_file(filename).map_err(|e| anyhow!(e)))
.context("failed to parse sqllogictest file")?;

let mut begin_times = vec![];
let mut did_pop = false;
Expand Down
20 changes: 14 additions & 6 deletions sqllogictest/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use itertools::Itertools;
use regex::Regex;

use crate::ColumnType;
use crate::ParseErrorKind::InvalidIncludeFile;

const RESULTS_DELIMITER: &str = "----";

Expand Down Expand Up @@ -112,6 +111,7 @@ pub enum Record<T: ColumnType> {
/// An include copies all records from another files.
Include {
loc: Location,
/// A glob pattern
filename: String,
},
/// A statement is an SQL command that is to be evaluated but from which we do not expect to
Expand Down Expand Up @@ -584,8 +584,10 @@ pub enum ParseErrorKind {
InvalidDuration(String),
#[error("invalid control: {0:?}")]
InvalidControl(String),
#[error("invalid include file pattern: {0:?}")]
#[error("invalid include file pattern: {0}")]
InvalidIncludeFile(String),
#[error("no files found for include file pattern: {0:?}")]
EmptyIncludeFile(String),
#[error("no such file")]
FileNotFound,
}
Expand Down Expand Up @@ -843,10 +845,16 @@ fn parse_file_inner<T: ColumnType>(loc: Location) -> Result<Vec<Record<T>>, Pars
path_buf.as_os_str().to_string_lossy().to_string()
};

for included_file in glob::glob(&complete_filename)
.map_err(|e| InvalidIncludeFile(format!("{e:?}")).at(loc.clone()))?
.filter_map(Result::ok)
{
let mut iter = glob::glob(&complete_filename)
.map_err(|e| ParseErrorKind::InvalidIncludeFile(e.to_string()).at(loc.clone()))?
.peekable();
if iter.peek().is_none() {
return Err(ParseErrorKind::EmptyIncludeFile(filename).at(loc.clone()));
}
for included_file in iter {
let included_file = included_file.map_err(|e| {
ParseErrorKind::InvalidIncludeFile(e.to_string()).at(loc.clone())
})?;
let included_file = included_file.as_os_str().to_string_lossy().to_string();

records.push(Record::Injected(Injected::BeginInclude(
Expand Down

0 comments on commit 58673cb

Please sign in to comment.