Skip to content

Commit

Permalink
feat: clap wrapper around sqlness (GreptimeTeam#2400)
Browse files Browse the repository at this point in the history
* feat: wrapped sqlness with clap to provide nice interface

* fix: added spaces and changed -f flag to bool
  • Loading branch information
Lilit0x authored and paomian committed Oct 19, 2023
1 parent b306389 commit 41b44f3
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ license.workspace = true

[dependencies]
async-trait = "0.1"
clap = { version = "4.0", features = ["derive"] }
client = { workspace = true }
common-base = { workspace = true }
common-error = { workspace = true }
Expand Down
38 changes: 29 additions & 9 deletions tests/runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,51 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::path::PathBuf;

use clap::Parser;
use env::Env;
use sqlness::{ConfigBuilder, Runner};

mod env;
mod util;

#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
/// SQL Harness for GrepTimeDB
struct Args {
/// Directory of test cases
#[clap(short, long)]
case_dir: Option<PathBuf>,

/// Fail this run as soon as one case fails if true
#[arg(short, long, default_value = "false")]
fail_fast: bool,

/// Environment Configuration File
#[clap(short, long, default_value = "config.toml")]
env_config_file: String,

/// Name of test cases to run. Accept as a regexp.
#[clap(short, long, default_value = ".*")]
test_filter: String,
}

#[tokio::main]
async fn main() {
let mut args: Vec<String> = std::env::args().collect();
let test_filter = if args.len() > 1 {
args.pop().unwrap()
} else {
"".to_string()
};
let args = Args::parse();

#[cfg(windows)]
let data_home = std::env::temp_dir();
#[cfg(not(windows))]
let data_home = std::path::PathBuf::from("/tmp");

let config = ConfigBuilder::default()
.case_dir(util::get_case_dir())
.fail_fast(false)
.test_filter(test_filter)
.case_dir(util::get_case_dir(args.case_dir))
.fail_fast(args.fail_fast)
.test_filter(args.test_filter)
.follow_links(true)
.env_config_file(args.env_config_file)
.build()
.unwrap();
let runner = Runner::new(config, Env::new(data_home));
Expand Down
21 changes: 13 additions & 8 deletions tests/runner/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,20 @@ where

/// Get the dir of test cases. This function only works when the runner is run
/// under the project's dir because it depends on some envs set by cargo.
pub fn get_case_dir() -> String {
// retrieve the manifest runner (./tests/runner)
let mut runner_crate_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));

// change directory to cases' dir from runner's (should be runner/../cases)
let _ = runner_crate_path.pop();
runner_crate_path.push("cases");
pub fn get_case_dir(case_dir: Option<PathBuf>) -> String {
let runner_path = match case_dir {
Some(path) => path,
None => {
// retrieve the manifest runner (./tests/runner)
let mut runner_crate_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
// change directory to cases' dir from runner's (should be runner/../cases)
let _ = runner_crate_path.pop();
runner_crate_path.push("cases");
runner_crate_path
}
};

runner_crate_path.into_os_string().into_string().unwrap()
runner_path.into_os_string().into_string().unwrap()
}

/// Get the dir that contains workspace manifest (the top-level Cargo.toml).
Expand Down

0 comments on commit 41b44f3

Please sign in to comment.