Skip to content

Commit 263aa0c

Browse files
authored
feat: general variable substitution (#196)
Support environment variables and special variables (like `$__TEST_DIR__`) substitution with the crate [`subst`](crates.io/subst). Basically, this is a general form of the previous `replace_keywords`. This is helpful if we want to don't want to hardcode some information in the SQL, for example, authentication information. ``` control substitution on query T select $MY_USERNAME, ${MY_PASSWORD}, ${MY_INEXISTENT_PORT:11451}, ${MY_DATABASE:$MY_USERNAME-db} ---- sqllogictest, rust, 11451, sqllogictest-db query T select $__TEST_DIR__ ---- /var/folders/h3/ky82klmd2ygfr58ppqm4js6m0000gn/T/.tmp63ZLdk ``` See `substitution/basic.slt` for more detailed usages. In order to be compatible with other implementations, this feature is under the gate of `control substitution` and is by default disabled.
1 parent d554415 commit 263aa0c

File tree

18 files changed

+538
-304
lines changed

18 files changed

+538
-304
lines changed

CHANGELOG.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,40 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
## [0.17.0] - 2023-09-19
11+
12+
* Support environment variables substituion for SQL and system commands.
13+
For compatibility, this feature is by default disabled, and can be enabled by adding `control substitution on` to the test file.
14+
```
15+
control substitution on
16+
17+
query TTTT
18+
SELECT
19+
'$foo' -- short
20+
, '${foo}' -- long
21+
, '${bar:default}' -- default value
22+
, '${bar:$foo-default}' -- recursive default value
23+
FROM baz;
24+
----
25+
...
26+
```
27+
28+
Besides, there's a special variable `$__TEST_DIR__` which is the path to a temporary directory specific to the current test case.
29+
This can be helpful if you need to manipulate some external resources during the test.
30+
```
31+
control substitution on
32+
33+
statement ok
34+
COPY (SELECT * FROM foo) TO '$__TEST_DIR__/foo.txt';
35+
36+
system ok
37+
echo "foo" > "$__TEST_DIR__/foo.txt"
38+
```
39+
40+
Changes:
41+
- (parser) **Breaking change**: Add `Control::Substitution`. Mark `Control` as `#[non_exhaustive]`.
42+
- (runner) **Breaking change**: Remove `enable_testdir`. For migration, one should now enable general substitution by the `control` statement and use a dollar-prefixed `$__TEST_DIR__`.
43+
1044
## [0.16.0] - 2023-09-15
1145

1246
* Support running external system commands with the syntax below. This is useful for manipulating some external resources during the test.

0 commit comments

Comments
 (0)