How to use VSCode and REPL to write and test a package?

https://github.com/JuliaTesting/TestEnv.jl is the only reproducible way I have found. Not sure who originally created it, but I think it was another beautiful package from @oxinabox

  1. Create your normal package Project.toml file, no manifest checked into git
  2. Create a /test/Project.toml file, again best not to check a manifest in and to use the compat as required, but less of an issue there,
  3. Do a ] add TestEnv to the global environment. Hopefully vscode even add/load testenv automatically at some point in the future.
  4. Otherwise, keep your global environment clean (e.g. Revise, PkgBenchmark, BenchmarkTools, TestEnv but not much else) usually works best. I keep the package I am working on out of it, but probably other ways work

Just to be clear: at no point do you need to add your package to theglobal environment or manually make any temp project file, and you definetely don’t want to put test-only dependencies in the global environment,

Then to use this:

  1. Start vscode in your packages folder so it starts activated.
  2. To run the unit tests fully, you could just do the classic ] test and it uses the test/Project.toml
  3. To work interactively, given that your package is activated just go using TestEnv; TestEnv.activate() when you start up the REPL,

This creates, activates, and instantiates a temporary manifest that emulates what ] test would do. Fully reproducible.

Then you can just use vscode as you normally would, executing the unit tests line by line, modify the package functions and then <shift-enter> or using Revise, etc. Seamless.

7 Likes