Packaging: why can't Julia find Test in Travis?

I’ve got these really basic .travis.yml and test/runtests.jl files and in the Travis log I’m getting the error:

$ julia --check-bounds=yes --color=yes -e "if VERSION < v\"0.7.0-DEV.5183\"; Pkg.test(\"${JL_PKG}\", coverage=true); else using Pkg; Pkg.test(coverage=true); end"
    Testing Integration
######################################################################## 100.0%
      Added registry `General` to `~/.julia/registries/General`
Status `/tmp/jl_oGVJCk/Project.toml`
  [fe4b9952] Integration v0.1.0 `~/build/fusion809/Integration`
Status `/tmp/jl_oGVJCk/Manifest.toml`
  [fe4b9952] Integration v0.1.0 `~/build/fusion809/Integration`
ERROR: LoadError: ArgumentError: Package Test not found in current path:
- Run `import Pkg; Pkg.add("Test")` to install the Test package.
Stacktrace:
 [1] require(::Module, ::Symbol) at ./loading.jl:893
 [2] include(::String) at ./client.jl:444
 [3] top-level scope at none:6
in expression starting at /home/travis/build/fusion809/Integration/test/runtests.jl:2
ERROR: Package Integration errored during testing
Stacktrace:
 [1] pkgerror(::String) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Pkg/src/Types.jl:52
 [2] test(::Pkg.Types.Context, ::Array{Pkg.Types.PackageSpec,1}; coverage::Bool, julia_args::Cmd, test_args::Cmd, test_fn::Nothing) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Pkg/src/Operations.jl:1561
 [3] test(::Pkg.Types.Context, ::Array{Pkg.Types.PackageSpec,1}; coverage::Bool, test_fn::Nothing, julia_args::Cmd, test_args::Cmd, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Pkg/src/API.jl:327
 [4] #test#61 at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Pkg/src/API.jl:67 [inlined]
 [5] test(; name::Nothing, uuid::Nothing, version::Nothing, url::Nothing, rev::Nothing, path::Nothing, mode::Pkg.Types.PackageMode, subdir::Nothing, kwargs::Base.Iterators.Pairs{Symbol,Bool,Tuple{Symbol},NamedTuple{(:coverage,),Tuple{Bool}}}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Pkg/src/API.jl:80
 [6] top-level scope at none:1
The command "julia --check-bounds=yes --color=yes -e "if VERSION < v\"0.7.0-DEV.5183\"; Pkg.test(\"${JL_PKG}\", coverage=true); else using Pkg; Pkg.test(coverage=true); end"" failed and exited with 1 during .

and I must admit I’m a little stumped. Naturally, you may say “Just add import Pkg; Pkg.add("Test") to the top of runtests.jl like the error tells you to.” Well, I’ve tried that and what it complains about after making that change is that it cannot find Pkg (here’s the log). Based on these errors it seems like Travis’ Julia is pretty minimalist, so minimalist it doesn’t even have its package manager, so I’m a little stumped as to what to do.

I believe the issue you’re seeing is because Project.toml doesn’t include the dependency on Test (or Pkg). Here’s a way to fix that:

  • julia> ] add Test

Project.toml will now have:

[deps]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

If you only need Test when you run your tests (i.e. you don’t have using Test or import Test anywhere in /src/), you can edit this slightly to:

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]

I think I remember reading that there will be a way to do this in a single step at some point in the future, but in any case, committing that change to git should fix the tests on travis.

(I opened a PR to make certain this would work, but you might like to make the change yourself :slight_smile: )

2 Likes

To add to this: the [extras] and [targets] are necessary on julia versions < 1.2. From 1.2 onward you may add Test as a dependency in the test environment, that is

pkg> activate test
test> add Test

and the test/Project.toml file would reflect Test as a dependency. Following this you may import Test in your runtests.jl.

2 Likes