Using test/Project.toml

Following the instructions from Pkg docs, I ran the following commands to add two dependecies that I only need for tests:

Starting Julia...
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.2.0 (2019-08-20)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

(v1.2) pkg> activate ./test

(test) pkg> add Test DataStructures
  Updating registry at `C:\Users\carlm\.juliapro\JuliaPro_v1.2.0-1\registries\JuliaPro`
  Updating git-repo `https://pkg.juliacomputing.com//registry/JuliaPro`
 Resolving package versions...
  Updating `C:\Users\carlm\workspace\montecarlo\MC\test\Project.toml`
 [no changes]
  Updating `C:\Users\carlm\workspace\montecarlo\MC\test\Manifest.toml`
 [no changes]

(test) pkg> activate .

(MC) pkg> test
   Testing MC
ERROR: target `test` has unlisted dependency `Test`

My Project.toml and test/Project.toml are as follows:

Project.toml

name = "MC"
uuid = "769ab3d0-0d7b-11ea-0685-592be65fdeeb"
authors = ["Carl Morris"]
version = "0.1.0"

[compat]
julia = "1"

[targets]
test = ["Test"]

test/Project.toml

[deps]
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

I create my project using PkgTemplates in case that’s relevant. Any pointer to where I went wrong?

[extras]
Test = #UUID here

But the documents say

To add a test-specific dependency, i.e. a dependency that is available only when testing, it is thus enough to add this dependency to the test/Project.toml project.

So the extras line is still needed even in 1.2?

I’m still relatively new to this myself, but looking at the documentation, I thought the use of test/Project.toml was for setting the dependencies for Julia 1.2, and the [targets] lines in the project’s Project.toml were for Julia 1.0?

I followed the Julia 1.2 instructions for my project, and there are no [targets] in my project Project.toml. The test/Project.toml was generated like you showed in your original post.

You are mixing up both formats, so Pkg is using the “targets” based testing. Remove this section:

[targets]
test = ["Test"]

and Pkg will look for test/Project.toml instead.

2 Likes