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

feat: clap wrapper around sqlness #2400

Merged
merged 3 commits into from
Sep 16, 2023
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 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