Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permit running sqllogictest as a rust test in IDEs (+ use clap for sqllogicttest parsing, accept (and ignore) rust test harness arguments) #8288

Merged
merged 5 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions datafusion/sqllogictest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async-trait = { workspace = true }
bigdecimal = { workspace = true }
bytes = { version = "1.4.0", optional = true }
chrono = { workspace = true, optional = true }
clap = { version = "4.4.8", features = ["derive", "env"] }
datafusion = { path = "../core", version = "34.0.0" }
datafusion-common = { workspace = true }
futures = { version = "0.3.28" }
Expand Down
98 changes: 60 additions & 38 deletions datafusion/sqllogictest/bin/sqllogictests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use std::path::{Path, PathBuf};
#[cfg(target_family = "windows")]
use std::thread;

use clap::Parser;
use datafusion_sqllogictest::{DataFusion, TestContext};
use futures::stream::StreamExt;
use log::info;
Expand Down Expand Up @@ -77,7 +78,8 @@ async fn run_tests() -> Result<()> {
// Enable logging (e.g. set RUST_LOG=debug to see debug logs)
env_logger::init();

let options = Options::new();
let options: Options = clap::Parser::parse();
options.warn_on_ignored();

// Run all tests in parallel, reporting failures at the end
//
Expand All @@ -88,7 +90,7 @@ async fn run_tests() -> Result<()> {
.map(|test_file| {
tokio::task::spawn(async move {
println!("Running {:?}", test_file.relative_path);
if options.complete_mode {
if options.complete {
run_complete_file(test_file).await?;
} else if options.postgres_runner {
run_test_file_with_postgres(test_file).await?;
Expand Down Expand Up @@ -289,49 +291,54 @@ fn read_dir_recursive_impl(dst: &mut Vec<PathBuf>, path: &Path) -> Result<()> {
}

/// Parsed command line options
///
/// This structure attempts to mimic the command line options
/// accepted by IDEs such as CLion that pass arguments
///
/// See <https://github.com/apache/arrow-datafusion/issues/8287> for more details
#[derive(Parser, Debug)]
#[clap(author, version, about, long_about= None)]
struct Options {
// regex like
/// arguments passed to the program which are treated as
/// cargo test filter (substring match on filenames)
filters: Vec<String>,

/// Auto complete mode to fill out expected results
complete_mode: bool,

/// Run Postgres compatibility tests with Postgres runner
#[clap(long, help = "Auto complete mode to fill out expected results")]
complete: bool,

#[clap(
long,
env = "PG_COMPAT",
help = "Run Postgres compatibility tests with Postgres runner"
)]
postgres_runner: bool,

/// Include tpch files
#[clap(long, env = "INCLUDE_TPCH", help = "Include tpch files")]
include_tpch: bool,
}

impl Options {
fn new() -> Self {
let args: Vec<_> = std::env::args().collect();

let complete_mode = args.iter().any(|a| a == "--complete");
let postgres_runner = std::env::var("PG_COMPAT").map_or(false, |_| true);
let include_tpch = std::env::var("INCLUDE_TPCH").map_or(false, |_| true);

// treat args after the first as filters to run (substring matching)
let filters = if !args.is_empty() {
args.into_iter()
.skip(1)
// ignore command line arguments like `--complete`
.filter(|arg| !arg.as_str().starts_with("--"))
.collect::<Vec<_>>()
} else {
vec![]
};
#[clap(
action,
help = "regex like arguments passed to the program which are treated as cargo test filter (substring match on filenames)"
)]
filters: Vec<String>,

Self {
filters,
complete_mode,
postgres_runner,
include_tpch,
}
}
#[clap(
long,
help = "IGNORED (for compatibility with built in rust test runner)"
)]
format: Option<String>,

#[clap(
short = 'Z',
long,
help = "IGNORED (for compatibility with built in rust test runner)"
)]
z_options: Option<String>,

#[clap(
long,
help = "IGNORED (for compatibility with built in rust test runner)"
)]
show_output: bool,
}

impl Options {
/// Because this test can be run as a cargo test, commands like
///
/// ```shell
Expand Down Expand Up @@ -359,4 +366,19 @@ impl Options {
let file_name = path.file_name().unwrap().to_str().unwrap().to_string();
!self.postgres_runner || file_name.starts_with(PG_COMPAT_FILE_PREFIX)
}

/// Logs warning messages to stdout if any ignored options are passed
fn warn_on_ignored(&self) {
if self.format.is_some() {
println!("WARNING: Ignoring `--format` compatibility option");
}

if self.z_options.is_some() {
println!("WARNING: Ignoring `-Z` compatibility option");
}

if self.show_output {
println!("WARNING: Ignoring `--show-output` compatibility option");
}
}
}