mgechev / revive

🔥 ~6x faster, stricter, configurable, extensible, and beautiful drop-in replacement for golint
https://revive.run
MIT License
4.79k stars 278 forks source link

refactor: cli tests: use TestMain, t.Setenv, t.Cleanup #931

Closed alexandear closed 11 months ago

alexandear commented 11 months ago

This PR refactors tests in cli/main_test.go.

Changes

  1. Replace os.Setenv with t.Setenv;
  2. Replace init() with TestMain.
  3. Use t.Cleanup for reseting AppFs.

Motivation

T.Setenv calls os.Setenv and uses Cleanup to restore the environment variable to its original value after the test. Cleanup registers a function to be called when the test and all its subtests complete. TestMain is a handy way to do extra setup or teardown before or after a test executes.