* Allow step -a shift_lag/shift_lead/delta/ratio to specify records back/forward (#1002) Extends the slwin_m_n naming convention to more steppers: shift_lag_12 refers 12 records back, shift_lead_4 refers 4 records forward, and likewise delta_N, ratio_N, and shift_N. The unsuffixed forms keep their existing 1-record-back/forward behavior and output field names. Backward-looking steppers cache copies of previous values in a fixed-size ring buffer (tValueRing) in their own state, following the existing pattern of not reading from the window keeper's already-emitted records, to avoid races with downstream transformers. shift_lead_N uses the existing forward-window machinery shared with slwin. Also adds nil guards to all steppers' process functions for the case where the record at the window center lacks the stepped field, which previously panicked (pre-existing on main, e.g. "mlr step -a delta,shift_lead -f x" or "-a slwin_1_1" over heterogeneous data), and which the new parameterized combinations make easier to reach. Includes unit tests, regression cases 0024-0027, and regenerated help text / docs / man page. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Clarify step -a help text: both plain and _{n} stepper forms are valid (#1002) Per review on #2190: descriptions like "E.g. delta_7 for 7 records back" read as if the suffixed form were the only syntax. Reword the shift, shift_lag, shift_lead, delta, and ratio descriptions to state both forms explicitly -- e.g. "Use delta or equivalently delta_1 for the previous record, or delta_{n} for n records back" -- using the {n} placeholder style, and update the matching usage paragraph and reference-verbs prose. Regenerate help-derived docs, man page, and cli-help regression expectation. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Give a specific error for invalid stepper count suffixes (#1002) Per review on #2190: "mlr step -a delta_0" (or delta_-1, delta_x, etc.) previously reported the generic 'stepper "delta_0" not found'. Now, when the name prefixes a known count-suffix stepper (shift, shift_lag, shift_lead, delta, ratio) but the suffix is not a positive integer, the error is: mlr step: stepper "delta_0": count must be a positive integer Truly unknown stepper names keep the existing "not found" message. Adds should-fail regression cases for delta_0 and delta_-1, and unit tests for the detection helper. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com> |
||
|---|---|---|
| .. | ||
| cases | ||
| cases-not-suitable-for-ci | ||
| expected | ||
| input | ||
| stdlib | ||
| README.md | ||
Miller regression tests
There are a few files unit-tested with Go's testing package -- a few dozen cases total.
The vast majority of Miller tests, though -- thousands of cases -- are tested by running scripted invocations of mlr with various flags and inputs, comparing against expected output, and checking the exit code back to the shell.
How to run the regression tests, in brief
Note: while this README.md file is within the test/ subdirectory, all paths in this file are written from the perspective of the user being cd'ed into the repository base directory, i.e. this directory's parent directory.
-
mlr regtest --help -
go test github.com/johnkerl/miller/v6/pkg/...— runs the Go unit tests (a few dozen cases).
Items for the duration of the Go port
mlr regtest -c ...runs the C version of Miller from the local checkout
More details
You can alias mr='mlr regtest' for convenience. With no arguments, mr runs all cases under test/cases/. Pass one or more paths to run only those directories or specific .cmd files.
mr— run all regression cases (default path istest/cases/).mr test/cases/foo— run only cases under that directory.mr -v test/cases/foo— same, plus per-command pass/fail; use-vvor-vvvfor more detail.mr -j test/cases/foo/0003— show the Miller command, any script, and actual output for that case (handy for debugging).mr -p test/cases/foo/0003— populate: write or overwriteexpoutandexperrfrom the current run (use when adding or updating expected output).mr -c ...— use the C build of Miller (e.g.-c→../c/mlr) instead of the current executable.
To review populated files before committing, run mr -p on the desired path, then git diff to inspect changes and git reset --hard to discard them.
Creating new cases
- Create a case directory under
test/cases/, e.g.test/cases/my-feature/0001. - Add a
cmdfile containing the Miller command line (one line), e.g.mlr cat test/input/simple.dkvp. - Use shared input under
test/input/, or add a localinputfile in the case directory; incmdyou can use${CASEDIR}so the command refers to the case directory (e.g.mlr cat ${CASEDIR}/input). - Run
mlr regtest -p test/cases/my-feature/0001to generateexpout(andexperrif the command produces stderr). If the command is expected to exit non-zero, add an emptyshould-failfile. - Run
mlr regtest test/cases/my-feature/0001(without-p) to confirm the case passes.
Optional: mlr — DSL script file when the test uses -f/put/filter; env — environment variables to set for the case (unset after).