Skip to content

Commit

Permalink
Add JET to Test plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
gdalle committed Oct 10, 2023
1 parent 774f9fd commit fcfdf12
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 3 deletions.
36 changes: 35 additions & 1 deletion src/plugins/tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ const TEST_DEP = PackageSpec(; name="Test", uuid=TEST_UUID)
const AQUA_UUID = "4c88cf16-eb10-579e-8560-4a9242c79595"
const AQUA_DEP = PackageSpec(; name="Aqua", uuid=AQUA_UUID)

const JET_UUID = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
const JET_DEP = PackageSpec(; name="JET", uuid=JET_UUID)

"""
Tests(;
file="$(contractuser(default_file("test", "runtests.jl")))",
project=false,
aqua=false,
aqua_kwargs=NamedTuple(),
jet=false,
)
Sets up testing for packages.
Expand All @@ -21,6 +25,7 @@ Sets up testing for packages.
for more details.
- `aqua::Bool`: Controls whether or not to add quality tests with [Aqua.jl](https://github.com/JuliaTesting/Aqua.jl).
- `aqua_kwargs::NamedTuple`: Which keyword arguments to supply to Aqua tests (many people use `ambiguities=false` for example)
- `jet::Bool`: Controls whether or not to add a linting test with [JET.jl](https://github.com/aviatesk/JET.jl) (works best on type-stable code)
!!! note
Managing test dependencies with `test/Project.toml` is only supported
Expand All @@ -31,6 +36,7 @@ Sets up testing for packages.
project::Bool = false
aqua::Bool = false
aqua_kwargs::NamedTuple = NamedTuple()
jet::Bool = false
end

source(p::Tests) = p.file
Expand All @@ -54,6 +60,17 @@ function view(p::Tests, ::Template, pkg::AbstractString)
d["AQUA_IMPORT"] = ""
d["AQUA_TESTSET"] = ""
end
if p.jet
d["JET_IMPORT"] = "\nusing JET"
d["JET_TESTSET"] = """
@testset "Code linting (JET.jl)" begin
JET.test_package($pkg; target_defined_modules = true)
end
"""
else
d["JET_IMPORT"] = ""
d["JET_TESTSET"] = ""
end
return d
end

Expand Down Expand Up @@ -100,18 +117,35 @@ function make_test_project(p::Tests, pkg_dir::AbstractString)
if p.aqua
with_project(() -> Pkg.add(AQUA_DEP), joinpath(pkg_dir, "test"))
end
if p.jet
with_project(() -> Pkg.add(JET_DEP), joinpath(pkg_dir, "test"))
end
end

# Add Test as a test-only dependency.
function add_test_dependency(p::Tests, pkg_dir::AbstractString)
# Add the dependency manually since there's no programmatic way to add to [extras].
path = joinpath(pkg_dir, "Project.toml")
toml = TOML.parsefile(path)

get!(toml, "extras", Dict())["Test"] = TEST_UUID
if p.aqua
get!(toml, "extras", Dict())["Aqua"] = AQUA_UUID
end
get!(toml, "targets", Dict())["test"] = p.aqua ? ["Aqua", "Test"] : ["Test"]
if p.jet
get!(toml, "extras", Dict())["JET"] = JET_UUID
end

targets = String[]
if p.aqua
push!(targets, "Aqua")
end
if p.jet
push!(targets, "JET")
end
push!(targets, "Test")
get!(toml, "targets", Dict())["test"] = targets

write_project(path, toml)

# Generate the manifest by updating the project.
Expand Down
4 changes: 2 additions & 2 deletions templates/test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using {{{PKG}}}
using Test{{{AQUA_IMPORT}}}
using Test{{{AQUA_IMPORT}}}{{{JET_IMPORT}}}

@testset "{{{PKG}}}.jl" begin
{{{AQUA_TESTSET}}}# Write your tests here.
{{{AQUA_TESTSET}}}{{{JET_TESTSET}}}# Write your tests here.
end
1 change: 1 addition & 0 deletions test/fixtures/WackyOptions/test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[deps]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
4 changes: 4 additions & 0 deletions test/fixtures/WackyOptions/test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using WackyOptions
using Test
using Aqua
using JET

@testset "WackyOptions.jl" begin
@testset "Code quality (Aqua.jl)" begin
Aqua.test_all(WackyOptions; ambiguities = false, unbound_args = true)
end
@testset "Code linting (JET.jl)" begin
JET.test_package(WackyOptions; target_defined_modules = true)
end
# Write your tests here.
end
1 change: 1 addition & 0 deletions test/reference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ end
project=true,
aqua=true,
aqua_kwargs=(; ambiguities=false, unbound_args=true),
jet=true,
),
TravisCI(;
coverage=false,
Expand Down
1 change: 1 addition & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ end
project: false
aqua: false
aqua_kwargs: NamedTuple()
jet: false
"""
# `with_clean_gitconfig` requires Git to be installed, but if Git is not installed,
# then we probably don't need to worry about any conflicting Git config files.
Expand Down

0 comments on commit fcfdf12

Please sign in to comment.