Skip to content
This repository has been archived by the owner on Feb 17, 2024. It is now read-only.

test: don't exit on flag parsing error #42

Merged
merged 3 commits into from
Jun 1, 2023

Conversation

achille-roussel
Copy link
Contributor

@achille-roussel achille-roussel commented Jun 1, 2023

This PR modifies the main package and its tests to not call os.Exit on invalid command line arguments, which makes it possible to invoke main.Root from tests.

This has a few advantages:

  • we don't need to build the binary to run the tests, so a simple go test captures the latest changes without requiring an extra step to rebuild timecraft
  • we can use pprof with go test to profile the program execution (it was masked when invoking timecraft as a separate binary)
  • the tests run faster because the baseline cost of a function call is much lower than creating a new process
  • overall the code is better structured, there is no secret escape of from the control flow to terminate the program, functions have to return or panic (so defers are always run)
  • go test can compute the test coverage of the top-level package

Signed-off-by: Achille Roussel <[email protected]>
@achille-roussel achille-roussel merged commit 418fdf3 into main Jun 1, 2023
3 checks passed
@achille-roussel achille-roussel deleted the dont-exit-on-flag-parsing-error branch June 1, 2023 03:44
@pelletier
Copy link
Contributor

nice!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants