Skip to content

Commit 42af19e

Browse files
committed
sqllogictest: A logging and command line filter
1 parent df41267 commit 42af19e

2 files changed

Lines changed: 56 additions & 20 deletions

File tree

datafusion/core/tests/sqllogictests/README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,21 @@ This is the Datafusion implementation of [sqllogictest](https://www.sqlite.org/s
2323

2424
#### Running tests
2525

26-
`cargo test -p datafusion --test sqllogictests`
26+
```shell
27+
cargo test -p datafusion --test sqllogictests
28+
```
29+
30+
Run tests with debug logging enabled:
31+
32+
```shell
33+
RUST_LOG=debug cargo test -p datafusion --test sqllogictests
34+
```
35+
36+
Run only the tests in `information_schema.slt`:
37+
38+
```shell
39+
cargo test -p datafusion --test sqllogictests -- information_schema.slt
40+
```
2741

2842
#### sqllogictests
2943

datafusion/core/tests/sqllogictests/src/main.rs

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ use async_trait::async_trait;
1919
use datafusion::arrow::csv::WriterBuilder;
2020
use datafusion::arrow::record_batch::RecordBatch;
2121
use datafusion::prelude::{SessionConfig, SessionContext};
22-
use std::path::Path;
22+
use log::info;
23+
use std::path::PathBuf;
2324
use std::time::Duration;
2425

2526
use sqllogictest::TestError;
@@ -70,39 +71,60 @@ pub async fn main() -> Result<()> {
7071
#[tokio::main]
7172
#[cfg(not(target_family = "windows"))]
7273
pub async fn main() -> Result<()> {
73-
let paths = std::fs::read_dir(TEST_DIRECTORY).unwrap();
74+
// Enable logging (e.g. set RUST_LOG=debug to see debug logs)
7475

75-
// run each file using its own new SessionContext
76+
use log::info;
77+
env_logger::init();
78+
79+
// run each file using its own new DB
7680
//
7781
// Note: can't use tester.run_parallel_async()
7882
// as that will reuse the same SessionContext
7983
//
8084
// We could run these tests in parallel eventually if we wanted.
8185

82-
for path in paths {
83-
// TODO better error handling
84-
let path = path.unwrap().path();
85-
86-
run_file(&path).await?;
87-
}
88-
89-
Ok(())
90-
}
86+
let files = get_test_files();
87+
info!("Running test files {:?}", files);
9188

92-
/// Run the tests in the specified `.slt` file
93-
async fn run_file(path: &Path) -> Result<()> {
94-
println!("Running: {}", path.display());
89+
for path in files {
90+
println!("Running: {}", path.display());
9591

96-
let file_name = path.file_name().unwrap().to_str().unwrap().to_string();
92+
let file_name = path.file_name().unwrap().to_str().unwrap().to_string();
9793

98-
let ctx = context_for_test_file(&file_name).await;
94+
let ctx = context_for_test_file(&file_name).await;
9995

100-
let mut tester = sqllogictest::Runner::new(DataFusion { ctx, file_name });
101-
tester.run_file_async(path).await?;
96+
let mut tester = sqllogictest::Runner::new(DataFusion { ctx, file_name });
97+
tester.run_file_async(path).await?;
98+
}
10299

103100
Ok(())
104101
}
105102

103+
/// Gets a list of test files to execute. If there were arguments
104+
/// passed to the program treat them as filenames
105+
///
106+
fn get_test_files() -> Vec<PathBuf> {
107+
info!("Test directory: {}", TEST_DIRECTORY);
108+
109+
let args: Vec<_> = std::env::args().collect();
110+
111+
if args.len() > 1 {
112+
let test_path = PathBuf::from(TEST_DIRECTORY);
113+
114+
// treat args after the first as filenames in the test directory
115+
args.into_iter()
116+
.skip(1)
117+
.map(|arg| test_path.join(arg))
118+
.collect::<Vec<_>>()
119+
} else {
120+
// default to all files in test directory
121+
std::fs::read_dir(TEST_DIRECTORY)
122+
.unwrap()
123+
.map(|path| path.unwrap().path())
124+
.collect()
125+
}
126+
}
127+
106128
/// Create a SessionContext, configured for the specific test
107129
async fn context_for_test_file(file_name: &str) -> SessionContext {
108130
match file_name {

0 commit comments

Comments
 (0)