Skip to content

Commit 58673cb

Browse files
authored
feat: report error when include empty result (#203)
1 parent 0919ca0 commit 58673cb

File tree

6 files changed

+26
-15
lines changed

6 files changed

+26
-15
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
uses: actions-rs/cargo@v1
6464
with:
6565
command: install
66-
args: cargo-semver-checks --version ^0.22 --locked
66+
args: cargo-semver-checks --version ^0.27 --locked
6767
- name: Check semver
6868
run: |
6969
cargo semver-checks check-release -p sqllogictest

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
## [0.19.1] - 2024-01-04
11+
12+
* parser: `include` now returns error if no file is matched.
13+
1014
## [0.19.0] - 2023-11-11
1115

1216
* parser: refactor `expect` field in sqllogictest parser to make it easier to work with.

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ resolver = "2"
33
members = ["sqllogictest", "sqllogictest-bin", "sqllogictest-engines", "tests"]
44

55
[workspace.package]
6-
version = "0.19.0"
6+
version = "0.19.1"
77
edition = "2021"
88
homepage = "https://github.com/risinglightdb/sqllogictest-rs"
99
keywords = ["sql", "database", "parser", "cli"]

sqllogictest-bin/src/main.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,10 +465,9 @@ async fn run_test_file<T: std::io::Write, M: MakeConnection>(
465465
filename: impl AsRef<Path>,
466466
) -> Result<Duration> {
467467
let filename = filename.as_ref();
468-
let records = tokio::task::block_in_place(|| {
469-
sqllogictest::parse_file(filename).map_err(|e| anyhow!("{:?}", e))
470-
})
471-
.context("failed to parse sqllogictest file")?;
468+
let records =
469+
tokio::task::block_in_place(|| sqllogictest::parse_file(filename).map_err(|e| anyhow!(e)))
470+
.context("failed to parse sqllogictest file")?;
472471

473472
let mut begin_times = vec![];
474473
let mut did_pop = false;

sqllogictest/src/parser.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use itertools::Itertools;
1010
use regex::Regex;
1111

1212
use crate::ColumnType;
13-
use crate::ParseErrorKind::InvalidIncludeFile;
1413

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

@@ -112,6 +111,7 @@ pub enum Record<T: ColumnType> {
112111
/// An include copies all records from another files.
113112
Include {
114113
loc: Location,
114+
/// A glob pattern
115115
filename: String,
116116
},
117117
/// A statement is an SQL command that is to be evaluated but from which we do not expect to
@@ -584,8 +584,10 @@ pub enum ParseErrorKind {
584584
InvalidDuration(String),
585585
#[error("invalid control: {0:?}")]
586586
InvalidControl(String),
587-
#[error("invalid include file pattern: {0:?}")]
587+
#[error("invalid include file pattern: {0}")]
588588
InvalidIncludeFile(String),
589+
#[error("no files found for include file pattern: {0:?}")]
590+
EmptyIncludeFile(String),
589591
#[error("no such file")]
590592
FileNotFound,
591593
}
@@ -843,10 +845,16 @@ fn parse_file_inner<T: ColumnType>(loc: Location) -> Result<Vec<Record<T>>, Pars
843845
path_buf.as_os_str().to_string_lossy().to_string()
844846
};
845847

846-
for included_file in glob::glob(&complete_filename)
847-
.map_err(|e| InvalidIncludeFile(format!("{e:?}")).at(loc.clone()))?
848-
.filter_map(Result::ok)
849-
{
848+
let mut iter = glob::glob(&complete_filename)
849+
.map_err(|e| ParseErrorKind::InvalidIncludeFile(e.to_string()).at(loc.clone()))?
850+
.peekable();
851+
if iter.peek().is_none() {
852+
return Err(ParseErrorKind::EmptyIncludeFile(filename).at(loc.clone()));
853+
}
854+
for included_file in iter {
855+
let included_file = included_file.map_err(|e| {
856+
ParseErrorKind::InvalidIncludeFile(e.to_string()).at(loc.clone())
857+
})?;
850858
let included_file = included_file.as_os_str().to_string_lossy().to_string();
851859

852860
records.push(Record::Injected(Injected::BeginInclude(

0 commit comments

Comments
 (0)