semgrep / testo

Test framework for OCaml
ISC License
16 stars 1 forks source link

Control the environment during a test #99

Closed mjambon closed 4 weeks ago

mjambon commented 4 weeks ago

This adds Testo.with_environment_variables which allows for consistent results for tests that are sensitive to environment variables:

  1. This sets environment variables for the duration of a test and restores the old value when done.
  2. This makes the test fail if one of the specified environment variables is modified without being restored. Unfortunately, this doesn't apply to all the environment variables because I don't know how to obtain the full of list of environment variables. (I now know how to check the whole environment using Unix.environment () but I don't think it's something we need now or that needs to be in testo)

Context: I'm still battling weird errors in semgrep tests, one of them having to do with semgrep app tokens. I'm hoping that setting the environment variable SEMGREP_APP_TOKEN to something will result in the same logs on all machines.

PR checklist:

Check out CONTRIBUTING.md for more details.