Skip to content

Commit 4b9eeb2

Browse files
committed
Add tests
1 parent 8a8850c commit 4b9eeb2

7 files changed

+92
-4
lines changed

datafusion-cli/tests/cli_integration.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::process::Command;
1919

2020
use rstest::rstest;
2121

22-
use insta::{glob, Settings};
22+
use insta::{assert_snapshot, glob, Settings};
2323
use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
2424
use std::{env, fs};
2525

@@ -59,6 +59,7 @@ fn init() {
5959
"batch_size",
6060
["--command", "show datafusion.execution.batch_size", "-q", "-b", "1"],
6161
)]
62+
6263
#[test]
6364
fn cli_quick_test<'a>(
6465
#[case] snapshot_name: &'a str,
@@ -74,6 +75,31 @@ fn cli_quick_test<'a>(
7475
assert_cmd_snapshot!(cmd);
7576
}
7677

78+
#[rstest]
79+
#[case::default_explain_plan(
80+
"batch_size",
81+
// default explain format should be tree
82+
["--command", "EXPLAIN SELECT 123"],
83+
)]
84+
#[case::can_see_indent_format(
85+
"batch_size",
86+
// can choose the old explain format too
87+
["--command", "EXPLAIN FORMAT indent SELECT 123"],
88+
)]
89+
#[test]
90+
fn cli_quick_test_explain<'a>(
91+
#[case] snapshot_name: &'a str,
92+
#[case] args: impl IntoIterator<Item = &'a str>,
93+
) {
94+
let mut settings = make_settings();
95+
settings.set_snapshot_suffix(snapshot_name);
96+
let _bound = settings.bind_to_scope();
97+
98+
let mut cmd = cli();
99+
cmd.args(args);
100+
101+
assert_cmd_snapshot!(cmd);
102+
}
77103
#[rstest]
78104
#[case("csv")]
79105
#[case("tsv")]

datafusion-cli/tests/snapshots/[email protected]

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ info:
88
- "--format"
99
- json
1010
- "-q"
11+
snapshot_kind: text
1112
---
1213
success: true
1314
exit_code: 0

datafusion-cli/tests/snapshots/cli_quick_test@batch_size.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
source: tests/cli_integration.rs
2+
source: datafusion-cli/tests/cli_integration.rs
33
info:
44
program: datafusion-cli
55
args:
@@ -8,6 +8,7 @@ info:
88
- "-q"
99
- "-b"
1010
- "1"
11+
snapshot_kind: text
1112
---
1213
success: true
1314
exit_code: 0

datafusion-cli/tests/snapshots/[email protected]

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
---
2-
source: tests/cli_integration.rs
2+
source: datafusion-cli/tests/cli_integration.rs
33
info:
44
program: datafusion-cli
55
args:
66
- "--file"
77
- tests/sql/select.sql
88
- "-q"
9+
snapshot_kind: text
910
---
1011
success: true
1112
exit_code: 0

datafusion-cli/tests/snapshots/[email protected]

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
---
2-
source: tests/cli_integration.rs
2+
source: datafusion-cli/tests/cli_integration.rs
33
info:
44
program: datafusion-cli
55
args:
66
- "--command"
77
- select 1; select 2;
88
- "-q"
9+
snapshot_kind: text
910
---
1011
success: true
1112
exit_code: 0
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
source: datafusion-cli/tests/cli_integration.rs
3+
info:
4+
program: datafusion-cli
5+
args:
6+
- "--command"
7+
- EXPLAIN SELECT 123
8+
snapshot_kind: text
9+
---
10+
success: true
11+
exit_code: 0
12+
----- stdout -----
13+
[CLI_VERSION]
14+
+---------------+-------------------------------+
15+
| plan_type | plan |
16+
+---------------+-------------------------------+
17+
| physical_plan | ┌───────────────────────────┐ |
18+
| |ProjectionExec|
19+
| |--------------------|
20+
| |Int64(123): 123|
21+
| | └─────────────┬─────────────┘ |
22+
| | ┌─────────────┴─────────────┐ |
23+
| |PlaceholderRowExec|
24+
| | └───────────────────────────┘ |
25+
| | |
26+
+---------------+-------------------------------+
27+
1 row(s) fetched.
28+
[ELAPSED]
29+
30+
31+
----- stderr -----
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
source: datafusion-cli/tests/cli_integration.rs
3+
info:
4+
program: datafusion-cli
5+
args:
6+
- "--command"
7+
- EXPLAIN FORMAT indent SELECT 123
8+
snapshot_kind: text
9+
---
10+
success: true
11+
exit_code: 0
12+
----- stdout -----
13+
[CLI_VERSION]
14+
+---------------+------------------------------------------+
15+
| plan_type | plan |
16+
+---------------+------------------------------------------+
17+
| logical_plan | Projection: Int64(123) |
18+
| | EmptyRelation |
19+
| physical_plan | ProjectionExec: expr=[123 as Int64(123)] |
20+
| | PlaceholderRowExec |
21+
| | |
22+
+---------------+------------------------------------------+
23+
2 row(s) fetched.
24+
[ELAPSED]
25+
26+
27+
----- stderr -----

0 commit comments

Comments
 (0)