Skip to content

Commit 7d62ff4

Browse files
committed
Clarify description of command line args argument to runtests
The current docstring had conflicting information: the signature showed only `ParsedArgs` was accepted, but the description suggested only a vector of strings (like `Base.ARGS`) was accepted.
1 parent ca15026 commit 7d62ff4

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

docs/src/api.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ default_njobs
4141

4242
## Internal Types
4343

44+
These are internal types, not subject to semantic versioning contract (could be changed or removed at any point without notice), not intended for consumption by end-users.
45+
They are documented here exclusively for `ParallelTestRunner` developers and contributors.
46+
4447
```@docs
48+
ParsedArgs
4549
WorkerTestSet
4650
```

docs/src/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ julia --project test/runtests.jl --quickfail
8181

8282
### Using with Pkg.test
8383

84-
You can also pass arguments through `Pkg.test`:
84+
You can also pass arguments through [`Pkg.test`](https://pkgdocs.julialang.org/v1/api/#Pkg.test):
8585

8686
```julia
8787
using Pkg

src/ParallelTestRunner.jl

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,21 @@ function find_tests(dir::String)
499499
return tests
500500
end
501501

502+
"""
503+
ParsedArgs
504+
505+
Struct representing parsed command line arguments, to be passed to [`runtests`](@ref).
506+
`ParsedArgs` objects are typically obtained by using [`parse_args`](@ref).
507+
508+
Fields are
509+
510+
* `jobs::Union{Some{Int}, Nothing}`: the number of jobs
511+
* `verbose::Union{Some{Nothing}, Nothing}`: whether verbose printing was enabled
512+
* `quickfail::Union{Some{Nothing}, Nothing}`: whether quick fail was enabled
513+
* `list::Union{Some{Nothing}, Nothing}`: whether tests should be listed
514+
* `custom::Dict{String,Any}`: a dictionary of custom arguments
515+
* `positionals::Vector{String}`: the list of positional arguments passed on the command line, i.e. the explicit list of test files (to be matches with `startswith`)
516+
"""
502517
struct ParsedArgs
503518
jobs::Union{Some{Int}, Nothing}
504519
verbose::Union{Some{Nothing}, Nothing}
@@ -544,7 +559,7 @@ option was not specified, or `Some(optional_value=nothing)` when it was.
544559
545560
Custom arguments can be specified via the `custom` keyword argument, which should be
546561
an array of strings representing custom flag names (without the `--` prefix). Presence
547-
of these flags will be recorded in the `custom` field of the returned `ParsedArgs` object.
562+
of these flags will be recorded in the `custom` field of the returned [`ParsedArgs`](@ref) object.
548563
"""
549564
function parse_args(args; custom::Array{String} = String[])
550565
args = copy(args)
@@ -615,7 +630,7 @@ function filter_tests!(testsuite, args::ParsedArgs)
615630
end
616631

617632
"""
618-
runtests(mod::Module, args::ParsedArgs;
633+
runtests(mod::Module, args::Union{ParsedArgs,Array{String}};
619634
testsuite::Dict{String,Expr}=find_tests(pwd()),
620635
init_code = :(),
621636
test_worker = Returns(nothing),
@@ -628,14 +643,14 @@ Run Julia tests in parallel across multiple worker processes.
628643
## Arguments
629644
630645
- `mod`: The module calling runtests
631-
- `ARGS`: Command line arguments array, typically from `Base.ARGS`. When you run the tests
632-
with `Pkg.test`, this can be changed with the `test_args` keyword argument. If the caller
633-
needs to accept args too, consider using [`parse_args`](@ref) to parse the arguments first.
646+
- `ARGS`: Command line arguments. This can be either the vector of strings of the arguments, typically from [`Base.ARGS`](https://docs.julialang.org/en/v1/base/constants/#Base.ARGS), or a [`ParsedArgs`](@ref) object, typically parsed with [`parse_args`](@ref).
647+
When you run the tests with [`Pkg.test`](https://pkgdocs.julialang.org/v1/api/#Pkg.test), the command line arguments passed to the script can be changed with the `test_args` keyword argument.
648+
If the caller needs to accept arguments too, consider using [`parse_args`](@ref) to parse the arguments first.
634649
635650
Several keyword arguments are also supported:
636651
637652
- `testsuite`: Dictionary mapping test names to expressions to execute (default: [`find_tests(pwd())`](@ref)).
638-
By default, automatically discovers all `.jl` files in the test directory.
653+
By default, automatically discovers all `.jl` files in the test directory and its subdirectories.
639654
- `init_code`: Code use to initialize each test's sandbox module (e.g., import auxiliary
640655
packages, define constants, etc).
641656
- `test_worker`: Optional function that takes a test name and returns a specific worker.
@@ -1160,6 +1175,6 @@ function runtests(mod::Module, args::ParsedArgs;
11601175

11611176
return
11621177
end
1163-
runtests(mod::Module, ARGS; kwargs...) = runtests(mod, parse_args(ARGS); kwargs...)
1178+
runtests(mod::Module, ARGS::Array{String}; kwargs...) = runtests(mod, parse_args(ARGS); kwargs...)
11641179

11651180
end

0 commit comments

Comments
 (0)