@@ -19,7 +19,8 @@ use async_trait::async_trait;
1919use datafusion:: arrow:: csv:: WriterBuilder ;
2020use datafusion:: arrow:: record_batch:: RecordBatch ;
2121use datafusion:: prelude:: { SessionConfig , SessionContext } ;
22- use std:: path:: Path ;
22+ use log:: info;
23+ use std:: path:: PathBuf ;
2324use std:: time:: Duration ;
2425
2526use sqllogictest:: TestError ;
@@ -70,39 +71,60 @@ pub async fn main() -> Result<()> {
7071#[ tokio:: main]
7172#[ cfg( not( target_family = "windows" ) ) ]
7273pub 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
107129async fn context_for_test_file ( file_name : & str ) -> SessionContext {
108130 match file_name {
0 commit comments