Skip to content

Commit

Permalink
Allow testing values with trailing whitespace in SLT tests
Browse files Browse the repository at this point in the history
  • Loading branch information
findepi committed Oct 31, 2024
1 parent 319d207 commit 5ae6285
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
23 changes: 21 additions & 2 deletions datafusion/sqllogictest/bin/sqllogictests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use std::path::{Path, PathBuf};
use clap::Parser;
use datafusion_sqllogictest::{DataFusion, TestContext};
use futures::stream::StreamExt;
use itertools::Itertools;
use log::info;
use sqllogictest::strict_column_validator;

Expand All @@ -39,6 +40,23 @@ pub fn main() -> Result<()> {
.block_on(run_tests())
}

fn value_validator(actual: &[Vec<String>], expected: &[String]) -> bool {
let expected = expected
.iter()
// Trailing whitespace from lines in SLT will typically be removed, but do not fail if it is not
// If particular test wants to cover trailing whitespace on a value,
// it should project additional non-whitespace column on the right.
.map(|s| s.trim_end().to_owned())
.collect::<Vec<_>>();
let actual = actual
.iter()
.map(|strs| strs.iter().join(" "))
// Editors do not preserve trailing whitespace, so expected may or may not lack it included
.map(|s| s.trim_end().to_owned())
.collect::<Vec<_>>();
actual == expected
}

/// Sets up an empty directory at test_files/scratch/<name>
/// creating it if needed and clearing any file contents if it exists
/// This allows tests for inserting to external tables or copy to
Expand Down Expand Up @@ -140,6 +158,7 @@ async fn run_test_file(test_file: TestFile) -> Result<()> {
))
});
runner.with_column_validator(strict_column_validator);
runner.with_validator(value_validator);
runner
.run_file_async(path)
.await
Expand All @@ -158,6 +177,7 @@ async fn run_test_file_with_postgres(test_file: TestFile) -> Result<()> {
let mut runner =
sqllogictest::Runner::new(|| Postgres::connect(relative_path.clone()));
runner.with_column_validator(strict_column_validator);
runner.with_validator(value_validator);
runner
.run_file_async(path)
.await
Expand All @@ -176,7 +196,6 @@ async fn run_complete_file(test_file: TestFile) -> Result<()> {
path,
relative_path,
} = test_file;
use sqllogictest::default_validator;

info!("Using complete mode to complete: {}", path.display());

Expand All @@ -196,7 +215,7 @@ async fn run_complete_file(test_file: TestFile) -> Result<()> {
.update_test_file(
path,
col_separator,
default_validator,
value_validator,
strict_column_validator,
)
.await
Expand Down
5 changes: 5 additions & 0 deletions datafusion/sqllogictest/test_files/string/string_literal.slt
Original file line number Diff line number Diff line change
Expand Up @@ -816,3 +816,8 @@ query B
SELECT starts_with('foobar', 'bar')
----
false

query TT
select ' ', '|'
----
|

0 comments on commit 5ae6285

Please sign in to comment.