Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine test specific dependencies #52477

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions doc/src/tutorials/creating-packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,17 @@ test-specific dependencies, are available, see below.

### Test-specific dependencies

There are two ways of adding test-specific dependencies (dependencies that are not dependencies of the package but will still be available to
load when the package is tested).
There are two ways of adding test-specific dependencies (dependencies that are not dependencies of the package but
will still be available to load when the package is tested). If no `test/Project.toml` exists Pkg will default to
use the `target` based test specific dependencies.
ViralBShah marked this conversation as resolved.
Show resolved Hide resolved

#### `target` based test specific dependencies

Using this method of adding test-specific dependencies, the packages are added under an `[extras]` section and to a test target,
e.g. to add `Markdown` and `Test` as test dependencies, add the following to the `Project.toml` file:
!!! compat
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect this compat notice after the explanation of what the target method does

Copy link
Contributor Author

@freemin7 freemin7 Feb 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is directly related to the decision what functionality to choose, i could see that compat block being useful before further explanations.
That said. I don't care.

This older method of adding test-specific dependencies will be supported for all Julia 1.X releases.
IanButterworth marked this conversation as resolved.
Show resolved Hide resolved
ViralBShah marked this conversation as resolved.
Show resolved Hide resolved

Using this method of adding test-specific dependencies, the packages are added under an `[extras]` section and to a test target.
E.g. to add `Markdown` and `Test` as test dependencies, add the following to the projects `Project.toml` file:

```toml
[extras]
Expand All @@ -292,22 +296,23 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
test = ["Markdown", "Test"]
```

During testing the file `test/runtests.jl` will be executed with all dependencies from the `Project.toml` and the test dependencies
loaded. This special dependency handling is done during a `Pkg.test` call and doesn't happen if `runtest.jl` is executed directly.

Note that the only supported targets are `test` and `build`, the latter of which (not recommended) can be used
for any `deps/build.jl` scripts.
for any `deps/build.jl` scripts. This `target` based approach can't be used for other uses such as building
documentation.

#### Alternative approach: `test/Project.toml` file test specific dependencies

!!! note
The exact interaction between `Project.toml`, `test/Project.toml` and their corresponding
`Manifest.toml`s are not fully worked out and may be subject to change in future versions.
The older method of adding test-specific dependencies, described in the previous section,
will therefore be supported throughout all Julia 1.X releases.
In Julia 1.2 and later test dependencies can be declared in `test/Project.toml`. This is similar
ViralBShah marked this conversation as resolved.
Show resolved Hide resolved
to `test/` being a project but when running tests, Pkg will automatically merge `test/Project.toml`
and the `Project.toml` to create the test environment.

In Julia 1.2 and later test dependencies can be declared in `test/Project.toml`. When running
tests, Pkg will automatically merge this and the package Projects to create the test environment.

!!! note
If no `test/Project.toml` exists Pkg will use the `target` based test specific dependencies.
!!! compat
The exact interaction between `Project.toml`, `test/Project.toml` and their corresponding
`Manifest.toml`s are not fully worked out and might not work as intended on older and
especially unsupported Julia versions.

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. This can be
Expand Down Expand Up @@ -335,7 +340,7 @@ julia> write("test/runtests.jl",
@test 1 == 1
""");

(test) pkg> activate .
(test) pkg> activate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removed does not appear to be "white spaces".


(HelloWorld) pkg> test
Testing HelloWorld
Expand Down