From 5639465c555d79b99ac842f12eb7496c65b2dfb0 Mon Sep 17 00:00:00 2001 From: Charles Kawczynski Date: Tue, 5 Sep 2023 13:49:59 -0700 Subject: [PATCH 1/7] Add Aqua tests --- Project.toml | 3 ++- test/AquaTest.jl | 30 ++++++++++++++++++++++++++++++ test/runtests.jl | 5 +++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 test/AquaTest.jl diff --git a/Project.toml b/Project.toml index 1f12c7ba..6355850d 100644 --- a/Project.toml +++ b/Project.toml @@ -35,6 +35,7 @@ StaticArrays = "1.5" julia = "1.6" [extras] +Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" Calculus = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9" DiffTests = "de460e47-3fe3-5279-bb4a-814414816d5d" InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" @@ -43,4 +44,4 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Calculus", "DiffTests", "SparseArrays", "StaticArrays", "Test", "InteractiveUtils"] +test = ["Aqua", "Calculus", "DiffTests", "SparseArrays", "StaticArrays", "Test", "InteractiveUtils"] diff --git a/test/AquaTest.jl b/test/AquaTest.jl new file mode 100644 index 00000000..d22cf692 --- /dev/null +++ b/test/AquaTest.jl @@ -0,0 +1,30 @@ +using Test +using ForwardDiff +using Aqua + +@testset "Aqua tests (performance)" begin + # This tests that we don't accidentally run into + # https://github.com/JuliaLang/julia/issues/29393 + ua = Aqua.detect_unbound_args_recursively(ForwardDiff) + @test length(ua) == 6 + + # See: https://github.com/SciML/OrdinaryDiffEq.jl/issues/1750 + # Test that we're not introducing method ambiguities across deps + ambs = Aqua.detect_ambiguities(ForwardDiff; recursive = true) + pkg_match(pkgname, pkdir::Nothing) = false + pkg_match(pkgname, pkdir::AbstractString) = occursin(pkgname, pkdir) + filter!(x -> pkg_match("ForwardDiff", pkgdir(last(x).module)), ambs) + + @test length(ambs) == 0 +end + +@testset "Aqua tests (additional)" begin + Aqua.test_undefined_exports(ForwardDiff) + Aqua.test_stale_deps(ForwardDiff) + Aqua.test_deps_compat(ForwardDiff) + Aqua.test_project_extras(ForwardDiff) + Aqua.test_project_toml_formatting(ForwardDiff) + Aqua.test_piracy(ForwardDiff) +end + +nothing diff --git a/test/runtests.jl b/test/runtests.jl index e440af65..8f920c90 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -51,5 +51,10 @@ Random.seed!(SEED) t = @elapsed include("AllocationsTest.jl") println("##### done (took $t seconds).") end + @testset "Aqua" begin + println("##### Testing aqua...") + t = @elapsed include("AquaTest.jl") + println("##### done (took $t seconds).") + end println("##### Running all ForwardDiff tests took $(time() - t0) seconds.") end From 4fae6ebca4061f226ff45d06a8fe564b15453b30 Mon Sep 17 00:00:00 2001 From: Charles Kawczynski Date: Thu, 4 Jan 2024 09:50:17 -0500 Subject: [PATCH 2/7] Update --- Project.toml | 7 +++++++ test/AquaTest.jl | 13 +++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Project.toml b/Project.toml index 6355850d..0eea8826 100644 --- a/Project.toml +++ b/Project.toml @@ -22,16 +22,23 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" ForwardDiffStaticArraysExt = "StaticArrays" [compat] +Aqua = "0.8" Calculus = "0.5" CommonSubexpressions = "0.3" DiffResults = "1.1" DiffRules = "1.4" DiffTests = "0.1" +InteractiveUtils = "1" +LinearAlgebra = "1" LogExpFunctions = "0.3" NaNMath = "1" Preferences = "1" +Printf = "1" +Random = "1" +SparseArrays = "1" SpecialFunctions = "1, 2" StaticArrays = "1.5" +Test = "1" julia = "1.6" [extras] diff --git a/test/AquaTest.jl b/test/AquaTest.jl index d22cf692..8d890b9d 100644 --- a/test/AquaTest.jl +++ b/test/AquaTest.jl @@ -2,12 +2,14 @@ using Test using ForwardDiff using Aqua -@testset "Aqua tests (performance)" begin +@testset "Aqua tests - unbound_args" begin # This tests that we don't accidentally run into # https://github.com/JuliaLang/julia/issues/29393 ua = Aqua.detect_unbound_args_recursively(ForwardDiff) @test length(ua) == 6 +end +@testset "Aqua tests - ambiguities" begin # See: https://github.com/SciML/OrdinaryDiffEq.jl/issues/1750 # Test that we're not introducing method ambiguities across deps ambs = Aqua.detect_ambiguities(ForwardDiff; recursive = true) @@ -18,13 +20,8 @@ using Aqua @test length(ambs) == 0 end -@testset "Aqua tests (additional)" begin - Aqua.test_undefined_exports(ForwardDiff) - Aqua.test_stale_deps(ForwardDiff) - Aqua.test_deps_compat(ForwardDiff) - Aqua.test_project_extras(ForwardDiff) - Aqua.test_project_toml_formatting(ForwardDiff) - Aqua.test_piracy(ForwardDiff) +@testset "Aqua tests - remaining" begin + Aqua.test_all(ForwardDiff; ambiguities = false, unbound_args = false) end nothing From 7a4fe949f54d6552458f78284bdf92799df05c8f Mon Sep 17 00:00:00 2001 From: Charles Kawczynski Date: Thu, 4 Jan 2024 12:22:02 -0500 Subject: [PATCH 3/7] Wrap aqua tests in module --- test/AquaTest.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/AquaTest.jl b/test/AquaTest.jl index 8d890b9d..14a23a5b 100644 --- a/test/AquaTest.jl +++ b/test/AquaTest.jl @@ -1,3 +1,5 @@ +module AquaTest + using Test using ForwardDiff using Aqua @@ -24,4 +26,4 @@ end Aqua.test_all(ForwardDiff; ambiguities = false, unbound_args = false) end -nothing +end From 75416f2a1f84393f6c77bc666a3762b62a84831d Mon Sep 17 00:00:00 2001 From: Charles Kawczynski Date: Thu, 4 Jan 2024 12:22:26 -0500 Subject: [PATCH 4/7] Add aqua badge to readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c9e5154b..d13dbe85 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![](https://img.shields.io/badge/docs-stable-blue.svg)](https://juliadiff.org/ForwardDiff.jl/stable) [![](https://img.shields.io/badge/docs-dev-blue.svg)](https://juliadiff.org/ForwardDiff.jl/dev) +[![Aqua QA](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl) # ForwardDiff.jl From 7d7dc43e48bfe702cafdf0c7c6081217f65f8d24 Mon Sep 17 00:00:00 2001 From: Charles Kawczynski Date: Fri, 5 Jan 2024 10:21:09 -0500 Subject: [PATCH 5/7] Fix tests --- test/AquaTest.jl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/AquaTest.jl b/test/AquaTest.jl index 14a23a5b..7d3d8cc7 100644 --- a/test/AquaTest.jl +++ b/test/AquaTest.jl @@ -19,7 +19,16 @@ end pkg_match(pkgname, pkdir::AbstractString) = occursin(pkgname, pkdir) filter!(x -> pkg_match("ForwardDiff", pkgdir(last(x).module)), ambs) - @test length(ambs) == 0 + ambs_dict = Dict() + ambs_dict[(1, 6)] = 2 + ambs_dict[(1, 10)] = 1 + verkey(v) = (Int(VERSION.major), Int(VERSION.minor)) + + @test length(ambs) ≤ ambs_dict[verkey(VERSION)] + # notify us when we fix one + if length(ambs) < ambs_dict[verkey(VERSION)] + @info "Ambiguities may have been fixed, please lower the limit." + end end @testset "Aqua tests - remaining" begin From 9d24e2e3f3bb25500aac727212a30d1009f1d64c Mon Sep 17 00:00:00 2001 From: Charles Kawczynski Date: Fri, 5 Jan 2024 10:40:58 -0500 Subject: [PATCH 6/7] Reorder tests --- test/AquaTest.jl | 1 + test/runtests.jl | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/test/AquaTest.jl b/test/AquaTest.jl index 7d3d8cc7..546bdc88 100644 --- a/test/AquaTest.jl +++ b/test/AquaTest.jl @@ -28,6 +28,7 @@ end # notify us when we fix one if length(ambs) < ambs_dict[verkey(VERSION)] @info "Ambiguities may have been fixed, please lower the limit." + @info " length(ambs) = $(length(ambs))" end end diff --git a/test/runtests.jl b/test/runtests.jl index 8f920c90..33263baf 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,6 +6,11 @@ Random.seed!(SEED) @testset "ForwardDiff.jl" begin t0 = time() + @testset "Aqua" begin + println("##### Testing aqua...") + t = @elapsed include("AquaTest.jl") + println("##### done (took $t seconds).") + end @testset "Partials" begin println("##### Testing Partials...") t = @elapsed include("PartialsTest.jl") @@ -51,10 +56,5 @@ Random.seed!(SEED) t = @elapsed include("AllocationsTest.jl") println("##### done (took $t seconds).") end - @testset "Aqua" begin - println("##### Testing aqua...") - t = @elapsed include("AquaTest.jl") - println("##### done (took $t seconds).") - end println("##### Running all ForwardDiff tests took $(time() - t0) seconds.") end From 15bdd616f834a777e3d335670c27f42822cfd07f Mon Sep 17 00:00:00 2001 From: Charles Kawczynski Date: Fri, 5 Jan 2024 10:54:04 -0500 Subject: [PATCH 7/7] Skip amb test for all other julia versions --- test/AquaTest.jl | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/AquaTest.jl b/test/AquaTest.jl index 546bdc88..625044e3 100644 --- a/test/AquaTest.jl +++ b/test/AquaTest.jl @@ -24,11 +24,13 @@ end ambs_dict[(1, 10)] = 1 verkey(v) = (Int(VERSION.major), Int(VERSION.minor)) - @test length(ambs) ≤ ambs_dict[verkey(VERSION)] - # notify us when we fix one - if length(ambs) < ambs_dict[verkey(VERSION)] - @info "Ambiguities may have been fixed, please lower the limit." - @info " length(ambs) = $(length(ambs))" + if haskey(ambs_dict, verkey(VERSION)) + @test length(ambs) ≤ ambs_dict[verkey(VERSION)] + # notify us when we fix one + if length(ambs) < ambs_dict[verkey(VERSION)] + @info "Ambiguities may have been fixed, please lower the limit." + @info " length(ambs) = $(length(ambs))" + end end end