diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d0243d..189f6e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +**Breaking changes**: * runner: `RecordOutput` is now returned by `Runner::run` (or `Runner::run_async`). This allows users to access the output of each record, or check whether the record is skipped. +* substitution: add a special variable `__NOW__` which will be replaced with the current Unix timestamp in nanoseconds. ## [0.20.6] - 2024-06-21 diff --git a/sqllogictest/src/substitution.rs b/sqllogictest/src/substitution.rs index f350163..d66041a 100644 --- a/sqllogictest/src/substitution.rs +++ b/sqllogictest/src/substitution.rs @@ -23,6 +23,13 @@ impl<'a> subst::VariableMap<'a> for Substitution { test_dir.path().to_string_lossy().into_owned().into() } + "__NOW__" => std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .expect("failed to get current time") + .as_nanos() + .to_string() + .into(), + key => Env.get(key), } } diff --git a/tests/substitution/basic.slt b/tests/substitution/basic.slt index bc7d130..7ff4378 100644 --- a/tests/substitution/basic.slt +++ b/tests/substitution/basic.slt @@ -25,6 +25,10 @@ echo "$MY_USERNAME" statement ok path $__TEST_DIR__ +# a special variable `__NOW__` to get the current timestamp in nanoseconds +statement ok +time $__NOW__ + # non existent variables without default values are errors statement error No such variable check $NONEXISTENT_VARIABLE diff --git a/tests/substitution/substitution.rs b/tests/substitution/substitution.rs index 8b62d81..a7e5607 100644 --- a/tests/substitution/substitution.rs +++ b/tests/substitution/substitution.rs @@ -37,6 +37,10 @@ impl sqllogictest::DB for FakeDB { x.to_string() } } + Some(("time", x)) => { + let _ = x.parse::().map_err(|_| FakeDBError)?; + x.to_string() + } _ => return Err(FakeDBError), };