Recommended way to test for precompilation warnings and errors?

Several times recently while developing Julia packages, I have found myself needing to test that a particular package feature does not result in precompilation warnings or errors when used by other packages. Often this is because calling the feature does some code generation including method definition, which can lead to overwritten methods that Julia’s precompilation process will complain about, but which calling the feature in a script leads to no issues (e.g. this issue in Gen.jl which I finally managed to fix).

However, it’s not clear to me how test for such warnings using Julia’s current testing infrastructure for packages. It’s not enough to just create nested modules in test scripts, because those modules don’t get precompiled. Rather, I’ve found that I have to manually create dummy packages (sometimes mulitple) that import the package I’m developing, and then trigger precompilation of those packages in order to make sure there are no precompilation issues.

For e.g., for the fix I mentioned above, I had to create three packages with the following dependency structure in order to test the package PkgToTest:

[[TestPkg]]
deps = ["TestSubPkgA", "TestSubPkgB"]

[[TestSubPkgA]]
deps = ["PkgToTest"]

[[TestSubPkgB]]
deps = ["PkgToTest"]

Is there a simpler way to do this that I’m missing, and that can be run by calling Pkg.test so that I can be assured by CI against any precompilation errors? Or does this functionality / tooling not exist right now?

I am not even remotely as well versed in Julia, so this might be a silly suggestion, but would it not be easier to do all of this in a completely separate process started by a bash script that creates a temporary Julia environment, runs some simplistic imports and greps the output for precompilation warnings? It can have different exit statuses depending on what warnings were raised and the runtests.jl can check for these exit statuses.

I guess my suggestion of using bash is superfluous, but my bigger point is “would it not be easier to just spawn a bunch of new julia processes from the test itself: the parent process can set up some mock local packages and the child process can import them to trigger warnings”.

1 Like