miller/test
John Kerl 72ffcb3414
Support %a %A %e %h %c %x %X in strptime (#1518) (#2179)
Miller's strftime delegates to the full-featured lestrrat-go/strftime
library, but strptime uses an in-tree fork of a small subset-only
package, so strftime output couldn't always be parsed back by
strptime with the same format string. This adds the format codes
needed to round-trip common formats like "%a %b %e %T %Y":

* %a / %A (weekday name) and %h (alias of %b): straightforward
  formatMap entries, same pattern as the existing %b/%B.
* %e (space-padded day of month): needed dedicated width-detection
  logic, since %e's own optional leading pad space is otherwise
  indistinguishable from a literal separator space when the code
  searches for the next literal text to bound a field -- this was
  the root cause of the round-trip failure in the linked issue.
* %c, %x, %X: shorthand aliases (expanding to %a %b %e %H:%M:%S %Y,
  %m/%d/%y, and %H:%M:%S respectively), same mechanism already used
  for %T/%D/%F/%R/%r.

Also documents the %D/%F/%r/%R/%T shorthands in the strptime table
in reference-dsl-time.md.in, which were already supported but
missing from the docs -- this was the exact confusion reported in
the discussion linked from #1518.

Round-trip tests added in pkg/bifs/datetime_test.go assert
strptime(strftime(t, fmt), fmt) == t across the newly-supported
formats, plus table-driven cases in
pkg/pbnjay-strptime/strptime_test.go covering %e's edge cases
(padded/unpadded single digit, double digit, adjacent to another
code with no separator, at end of string).

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-08 16:42:03 -04:00
..
cases Support %a %A %e %h %c %x %X in strptime (#1518) (#2179) 2026-07-08 16:42:03 -04:00
cases-not-suitable-for-ci Avoid assuming ./mlr is the mlr to test (#876) 2022-01-17 17:01:40 -05:00
expected Standardize Go-package structure (#746) 2021-11-11 14:15:13 -05:00
input Add mlr rank verb (#2178) 2026-07-07 17:35:18 -04:00
stdlib Standardize Go-package structure (#746) 2021-11-11 14:15:13 -05:00
README.md test/README.md (#1972) 2026-02-16 16:44:31 -05:00

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 is test/cases/).
  • mr test/cases/foo — run only cases under that directory.
  • mr -v test/cases/foo — same, plus per-command pass/fail; use -vv or -vvv for 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/0003populate: write or overwrite expout and experr from 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

  1. Create a case directory under test/cases/, e.g. test/cases/my-feature/0001.
  2. Add a cmd file containing the Miller command line (one line), e.g. mlr cat test/input/simple.dkvp.
  3. Use shared input under test/input/, or add a local input file in the case directory; in cmd you can use ${CASEDIR} so the command refers to the case directory (e.g. mlr cat ${CASEDIR}/input).
  4. Run mlr regtest -p test/cases/my-feature/0001 to generate expout (and experr if the command produces stderr). If the command is expected to exit non-zero, add an empty should-fail file.
  5. 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).