Module Vcs_test_helpers

Helper library to write tests using vcs.

val init : [> Vcs.Trait.config | Vcs.Trait.init ] Vcs.t -> path:Fpath_sexp0.Absolute_path.t -> Vcs.Repo_root.t

This takes care of setting the user config with dummy values, so that you can use Vcs.commit without having to worry about your user config on your machine. This isolates the test from your local settings, and also makes things work when running in the GitHub Actions environment, where no default user config exists.

type 'a env = 'a constraint 'a = < fs : [> Eio.Fs.dir_ty ] Eio.Path.t ; process_mgr : [> [> `Generic ] Eio.Process.mgr_ty ] Eio.Resource.t.. >
val init_temp_repo : env:_ env -> sw:Eio.Switch.t -> vcs:[> Vcs.Trait.config | Vcs.Trait.init ] Vcs.t -> Vcs.Repo_root.t

Create a fresh temporary directory and initiate a repo in it. The switch provided is used to attach a task that will discard the repo when the switch is released.

val redact_sexp : Base.Sexp.t -> fields:Base.string Base.list -> Base.Sexp.t

This helper allows to filter out unstable and brittle parts of errors before printing them in an expect test trace. The fields parameter specifies which field-paths to redact.

In its most simple form, a field may simply be a field name that will end up being redacted. For example, if the error is:

((field_a ...)
 (field_b <UNSTABLE>))

then the fields parameter should be ["field_b"], and in this case, redact_sexp error ~fields:["field_b"] will result in:

((field_a ...)
 (field_b <REDACTED>))

Some form of nesting is supported for convenience: in case you only want to redact a field if it is nested deep into another field. In this case, the syntax is to use a "/" separator in the field. For example, if the error is:

((steps ((Vcs.init ((path /invalid/path)))))
 (error (
   (prog git)
   (args (init .))
   (exit_status Unknown)
   (cwd         /invalid/path)
   (stdout      "")
   (stderr      "")
   (error       <UNSTABLE>))))

then the fields parameter should be ["error/error"]. You may mix nested and non-nested fields in the same fields list.