Skip to content

Commit ab9f041

Browse files
committed
finish apply and test runner
Signed-off-by: Alex Chi <[email protected]>
1 parent dad209c commit ab9f041

File tree

16 files changed

+327
-24
lines changed

16 files changed

+327
-24
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/target
22
/Cargo.lock
3+
rust-toolchain

Cargo.toml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ readme = "README.md"
88
homepage = "https://github.com/risinglightdb/sqlplannertest-rs"
99
repository = "https://github.com/risinglightdb/sqlplannertest-rs"
1010
keywords = ["sql", "database", "planner", "cli"]
11-
1211
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1312

1413
[dependencies]
15-
async-trait = "0.1"
1614
anyhow = "1"
15+
async-trait = "0.1"
16+
glob = "0.3"
17+
libtest-mimic = "0.4"
1718
serde = { version = "1.0", features = ["derive"] }
1819
serde_yaml = "0.8"
19-
tokio = { version = "1", features = ["rt"] }
20-
libtest-mimic = "0.4"
20+
similar = "2"
21+
tokio = { version = "1", features = ["rt", "fs"] }
22+
console = "0.15"
23+
24+
[workspace]
25+
members = ["naivedb"]

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,21 @@ Basically, it is like:
4141
4242
And it will generate a file describing the result. Developers can diff the regression
4343
test result to see what have been changed throughout the process.
44+
45+
## NaiveDB
46+
47+
The naive database system for testing sqlplannertest.
48+
49+
**Update the test cases**
50+
51+
```
52+
cargo run -p naivedb --bin apply
53+
```
54+
55+
**Verify the test cases**
56+
57+
```
58+
cargo test -p naivedb
59+
# or use nextest
60+
cargo nextest run -p naivedb
61+
```

naivedb/Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "naivedb"
3+
version = "0.1.0"
4+
edition = "2021"
5+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
6+
7+
[dependencies]
8+
async-trait = "0.1"
9+
sqlplannertest = { path = ".." }
10+
anyhow = "1"
11+
tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros", "fs"] }
12+
13+
[[test]]
14+
name = "plannertest"
15+
harness = false

naivedb/src/bin/apply.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use std::path::Path;
2+
3+
use anyhow::Result;
4+
5+
#[tokio::main]
6+
async fn main() -> Result<()> {
7+
sqlplannertest::planner_test_apply(
8+
Path::new(env!("CARGO_MANIFEST_DIR")).join("tests"),
9+
|| async { Ok(naivedb::NaiveDb::new()) },
10+
)
11+
.await?;
12+
Ok(())
13+
}

naivedb/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use anyhow::Result;
2+
use async_trait::async_trait;
3+
4+
#[derive(Default)]
5+
pub struct NaiveDb {}
6+
7+
impl NaiveDb {
8+
pub fn new() -> Self {
9+
Self {}
10+
}
11+
}
12+
13+
#[async_trait]
14+
impl sqlplannertest::PlannerTestRunner for NaiveDb {
15+
async fn run(&mut self, _test_case: &sqlplannertest::ParsedTestCase) -> Result<String> {
16+
Ok("hello, world!".to_string())
17+
}
18+
}

naivedb/tests/1.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-----
2+
CREATE TABLE t1(v1 int);
3+
4+
hello, world!
5+
6+
-----
7+
CREATE TABLE t2(v2 int);
8+
9+
hello, world!
10+
11+
-----
12+
SELECT * FROM t1, t2 WHERE t1.v1 = t2.v2;
13+
14+
hello, world!
15+

naivedb/tests/1.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
- id: sql1
2+
sql: |
3+
CREATE TABLE t1(v1 int);
4+
- id: sql2
5+
sql: |
6+
CREATE TABLE t2(v2 int);
7+
- sql: |
8+
SELECT * FROM t1, t2 WHERE t1.v1 = t2.v2;
9+
desc: Test whether join works correctly.
10+
before: ["*sql1", "*sql2", "CREATE TABLE t3(v3 int);"]
11+
test:
12+
- logical
13+
- physical

naivedb/tests/2.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-----
2+
CREATE TABLE t1(v1 int);
3+
4+
hello, world!
5+
6+
-----
7+
CREATE TABLE t2(v2 int);
8+
9+
hello, world!
10+
11+
-----
12+
SELECT * FROM t1, t2 WHERE t1.v1 = t2.v2;
13+
14+
hello, world!
15+

naivedb/tests/2.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
- id: sql1
2+
sql: |
3+
CREATE TABLE t1(v1 int);
4+
- id: sql2
5+
sql: |
6+
CREATE TABLE t2(v2 int);
7+
- sql: |
8+
SELECT * FROM t1, t2 WHERE t1.v1 = t2.v2;
9+
desc: Test whether join works correctly.
10+
before: ["*sql1", "*sql2", "CREATE TABLE t3(v3 int);"]
11+
test:
12+
- logical
13+
- physical

0 commit comments

Comments
 (0)