Skip to content

Commit

Permalink
chore(planner test): add name field and improve error handling (#5602)
Browse files Browse the repository at this point in the history
* extract head line comments to name properties

Signed-off-by: Runji Wang <wangrunji0408@163.com>

* add name property and print location on parse error

Signed-off-by: Runji Wang <wangrunji0408@163.com>

Signed-off-by: Runji Wang <wangrunji0408@163.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
wangrunji0408 and mergify[bot] authored Sep 28, 2022
1 parent fea0bf9 commit bc3974a
Show file tree
Hide file tree
Showing 18 changed files with 420 additions and 400 deletions.
24 changes: 21 additions & 3 deletions src/frontend/planner_test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
mod resolve_id;

use std::collections::BTreeMap;
use std::path::Path;
use std::sync::atomic::Ordering;
use std::sync::Arc;

Expand All @@ -35,13 +36,17 @@ use risingwave_frontend::{
use risingwave_sqlparser::ast::{ObjectName, Statement};
use risingwave_sqlparser::parser::Parser;
use serde::{Deserialize, Serialize};

#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Default)]
#[serde(deny_unknown_fields)]
pub struct TestCase {
/// Id of the test case, used in before.
pub id: Option<String>,

/// A brief description of the test case.
pub name: Option<String>,

/// Before running the SQL statements, the test runner will execute the specified test cases
pub before: Option<Vec<String>>,

Expand Down Expand Up @@ -170,6 +175,7 @@ impl TestCaseResult {

let case = TestCase {
id: original_test_case.id.clone(),
name: original_test_case.name.clone(),
before: original_test_case.before.clone(),
sql: original_test_case.sql.to_string(),
before_statements: original_test_case.before_statements.clone(),
Expand Down Expand Up @@ -579,11 +585,23 @@ fn check_err(ctx: &str, expected_err: &Option<String>, actual_err: &Option<Strin
}
}

pub async fn run_test_file(file_name: &str, file_content: &str) -> Result<()> {
println!("-- running {} --", file_name);
pub async fn run_test_file(file_path: &Path, file_content: &str) -> Result<()> {
let file_name = file_path.file_name().unwrap().to_str().unwrap();
println!("-- running {file_name} --");

let mut failed_num = 0;
let cases: Vec<TestCase> = serde_yaml::from_str(file_content).unwrap();
let cases: Vec<TestCase> = serde_yaml::from_str(file_content).map_err(|e| {
if let Some(loc) = e.location() {
anyhow!(
"failed to parse yaml: {e}, at {}:{}:{}",
file_path.display(),
loc.line(),
loc.column()
)
} else {
anyhow!("failed to parse yaml: {e}")
}
})?;
let cases = resolve_testcase_id(cases).expect("failed to resolve");

for (i, c) in cases.into_iter().enumerate() {
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/planner_test/tests/planner_test_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ fn main() {
.join("testdata")
.join(file_name);

let file_content = std::fs::read_to_string(path).unwrap();
build_runtime().block_on(run_test_file(&test_case_name, &file_content))?;
let file_content = std::fs::read_to_string(&path).unwrap();
build_runtime().block_on(run_test_file(&path, &file_content))?;
Ok(())
}));
}
Expand Down
Loading

0 comments on commit bc3974a

Please sign in to comment.