oz / tz

🌐 A time zone helper
GNU General Public License v3.0
849 stars 33 forks source link

Various incremental improvements #73

Closed jnd-au closed 1 week ago

jnd-au commented 1 week ago

This PR addresses multiple issues:

  1. Minor code style improvements.
  2. Unit-test coverage raised from 84.5% to 93.2% (including main.go coverage raised from 31.6% to 76.5%).
  3. Fix #70
  4. Fix #71
  5. Fix #72

This includes feature-support for date-times like tz -when 2006-01-02T15:04:05-07:00.

Internally, main.go tests are supported through the new files os_wrapper.go and os_wrapper_test.go which provide our own os:

  1. Capture & test exit codes without exiting.
  2. Capture & test stderr messages instead of printing to console.
  3. Test flag CLI argument parsing.
  4. Test error-handling code paths.
  5. Clean env vars for each test.
  6. Simulate home dir scenarios.
  7. Virtual test file I/O in-memory

The residual warts are:

  1. Need to add return after os.Exit to support unit testing (in unit-test mode, our os.Exit records the exit code without exiting, so the function needs to return instead).
  2. Need to access os.Stdout() as an interface function instead of a package field.
oz commented 1 week ago

I'm grateful for the contributions, but please don't make one PR for shopping-list issues that you also created yourself.

jnd-au commented 1 week ago

FYI all the commits are interrelated with providing the missing test coverage, which is why I bundled these changes after the other PRs.