Skip to content

Commit 46a2874

Browse files
authored
Add tests with Aqua, ExplicitImports and JET (#507)
* Add tests with Aqua, ExplicitImports and JET * Workaround for extension handling in ExplicitImports
1 parent 1743a8b commit 46a2874

File tree

7 files changed

+91
-20
lines changed

7 files changed

+91
-20
lines changed

Project.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,27 @@ ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
1616
SpecialFunctionsChainRulesCoreExt = "ChainRulesCore"
1717

1818
[compat]
19+
Aqua = "0.8.14"
1920
ChainRulesCore = "0.9.44, 0.10, 1"
2021
ChainRulesTestUtils = "0.6.8, 0.7, 1"
22+
ExplicitImports = "1.13.2"
2123
IrrationalConstants = "0.1, 0.2"
2224
JET = "0.9, 0.10"
2325
LogExpFunctions = "0.3.2"
2426
OpenLibm_jll = "0.7, 0.8"
2527
OpenSpecFun_jll = "0.5"
28+
Random = "<0.0.1, 1"
29+
Test = "<0.0.1, 1"
2630
julia = "1.10"
2731

2832
[extras]
33+
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
2934
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
3035
ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a"
36+
ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7"
3137
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
3238
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
3339
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3440

3541
[targets]
36-
test = ["ChainRulesCore", "ChainRulesTestUtils", "JET", "Random", "Test"]
42+
test = ["Aqua", "ChainRulesCore", "ChainRulesTestUtils", "ExplicitImports", "JET", "Random", "Test"]

ext/SpecialFunctionsChainRulesCoreExt.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
module SpecialFunctionsChainRulesCoreExt
22

3-
using SpecialFunctions, ChainRulesCore
3+
using SpecialFunctions
4+
using ChainRulesCore: ChainRulesCore
45

5-
import SpecialFunctions: sqrtπ, invπ
6+
using SpecialFunctions: sqrtπ, invπ
67

78
const BESSEL_ORDER_INFO = """
89
derivatives of Bessel functions with respect to the order are not implemented currently:

src/SpecialFunctions.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ using IrrationalConstants:
1515

1616
import LogExpFunctions
1717

18-
using OpenLibm_jll
19-
using OpenSpecFun_jll
18+
using OpenLibm_jll: libopenlibm
19+
using OpenSpecFun_jll: libopenspecfun
2020

2121
export
2222
airyai,

src/ellip.jl

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,11 @@ As suggested in this paper, the domain is restricted to ``(-\infty,1]``.
3636
ellipk(m::Real) = _ellipk(float(m))
3737

3838
function _ellipk(m::Float64)
39-
flag_is_m_neg = false
40-
if m < 0.0
39+
flag_is_m_neg = m < 0.0
40+
if flag_is_m_neg
4141
x = m / (m-1) #dealing with negative args
42-
flag_is_m_neg = true
43-
elseif m >= 0.0
42+
else
4443
x = m
45-
flag_is_m_neg = false
4644
end
4745

4846
if x == 0.0
@@ -54,7 +52,7 @@ function _ellipk(m::Float64)
5452
elseif x > 1.0
5553
throw(DomainError(m, "`m` must lie between -Inf and 1 ---- Domain: (-Inf,1.0]"))
5654

57-
elseif 0.0 <= x < 0.1 #Table 2 from paper
55+
elseif 0.0 < x < 0.1 #Table 2 from paper
5856
t = x-0.05
5957
t = @horner(t,
6058
1.591003453790792180 , 0.416000743991786912 , 0.245791514264103415 ,
@@ -146,7 +144,8 @@ function _ellipk(m::Float64)
146144
1170222242422.439893 , 8777948323668.937971 , 66101242752484.95041 ,
147145
499488053713388.7989 , 37859743397240299.20)
148146

149-
elseif x >= 0.9
147+
else
148+
@assert 0.9 <= x < 1
150149
td = 1-x
151150
td1 = td-0.05
152151
qd = @horner(td,
@@ -207,13 +206,11 @@ As suggested in this paper, the domain is restricted to ``(-\infty,1]``.
207206
ellipe(m::Real) = _ellipe(float(m))
208207

209208
function _ellipe(m::Float64)
210-
flag_is_m_neg = false
211-
if m < 0.0
209+
flag_is_m_neg = m < 0.0
210+
if flag_is_m_neg
212211
x = m / (m-1) #dealing with negative args
213-
flag_is_m_neg = true
214-
elseif m >= 0.0
212+
else
215213
x = m
216-
flag_is_m_neg = false
217214
end
218215

219216
if x == 0.0
@@ -224,7 +221,7 @@ function _ellipe(m::Float64)
224221
elseif x > 1.0
225222
throw(DomainError(m,"`m` must lie between -Inf and 1 ---- Domain : (-inf,1.0]"))
226223

227-
elseif 0.0 <= x < 0.1 #Table 2 from paper
224+
elseif 0.0 < x < 0.1 #Table 2 from paper
228225
t = x-0.05
229226
t = @horner(t ,
230227
+1.550973351780472328 , -0.400301020103198524 , -0.078498619442941939 ,
@@ -311,7 +308,8 @@ function _ellipe(m::Float64)
311308
-16120097.81581656797 , -109209938.5203089915 , -749380758.1942496220 ,
312309
-5198725846.725541393 , -36409256888.12139973)
313310

314-
elseif x >= 0.9
311+
else
312+
@assert 0.9 <= x < 1.0
315313
td = 1-x
316314
td1 = td-0.05
317315

src/gamma_inc.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,7 @@ end
10151015

10161016
function __gamma_inc_inv(a::Float64, minpq::Float64, pcase::Bool)
10171017
haseta = false
1018+
fp = NaN
10181019

10191020
logp = pcase ? log(minpq) : log1p(-minpq)
10201021
loggamma1pa = a <= 1.0 ? loggamma1p(a) : loggamma(a + 1.0)

test/qa.jl

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
@testset "Aqua" begin
2+
Aqua.test_all(SpecialFunctions)
3+
end
4+
5+
@testset "ExplicitImports" begin
6+
# No implicit imports (`using XY`)
7+
@test ExplicitImports.check_no_implicit_imports(SpecialFunctions) === nothing
8+
9+
# All explicit imports (`using XY: Z`) are loaded via their owners
10+
@test ExplicitImports.check_all_explicit_imports_via_owners(
11+
SpecialFunctions;
12+
ignore = (
13+
# Ref https://github.com/JuliaTesting/ExplicitImports.jl/issues/92
14+
:invπ, # SpecialFunctions
15+
:sqrtπ, # SpecialFunctions
16+
),
17+
) === nothing
18+
19+
# Limit explicit imports (`using XY: Z`) of non-public names to a minimum
20+
@test ExplicitImports.check_all_explicit_imports_are_public(
21+
SpecialFunctions;
22+
ignore = (
23+
:MPFRRoundingMode, # Base.MPFR
24+
:ROUNDING_MODE, # Base.MPFR
25+
:nan_dom_err, # Base.Math
26+
# Ref https://github.com/JuliaTesting/ExplicitImports.jl/issues/92
27+
:invπ, # SpecialFunctions
28+
:sqrtπ, # SpecialFunctions
29+
),
30+
) === nothing
31+
32+
# No explicit imports (`using XY: Z`) that are not used
33+
@test ExplicitImports.check_no_stale_explicit_imports(SpecialFunctions) === nothing
34+
35+
# Nothing is accessed via modules other than its owner
36+
@test ExplicitImports.check_all_qualified_accesses_via_owners(SpecialFunctions) === nothing
37+
38+
# Limit accesses of non-public names to a minimum
39+
@test ExplicitImports.check_all_qualified_accesses_are_public(
40+
SpecialFunctions;
41+
ignore = (
42+
:IEEEFloat, # Base
43+
:MPFR, # Base
44+
:MPFRRoundingMode, # Base.MPFR
45+
:ROUNDING_MODE, # Base.MPFR
46+
:_fact_table64, # Base
47+
:version, # Base.MPFR
48+
(VERSION < v"1.11" ? (:depwarn,) : ())..., # Base
49+
),
50+
) === nothing
51+
52+
# No self-qualified accesses
53+
@test ExplicitImports.check_no_self_qualified_accesses(SpecialFunctions) === nothing
54+
end
55+
56+
@testset "JET" begin
57+
# Check that there are no undefined global references and undefined field accesses
58+
JET.test_package(SpecialFunctions; target_defined_modules = true, mode = :typo)
59+
60+
# Analyze methods based on their declared signature
61+
JET.report_package(SpecialFunctions; target_defined_modules = true)
62+
end

test/runtests.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ using Random
77
using Test
88
using Base.MathConstants: γ
99

10+
using Aqua: Aqua
11+
using ExplicitImports: ExplicitImports
1012
using JET: JET
1113

1214
using SpecialFunctions: AmosException, f64
@@ -35,7 +37,8 @@ tests = [
3537
"logabsgamma",
3638
"sincosint",
3739
"other_tests",
38-
"chainrules"
40+
"chainrules",
41+
"qa"
3942
]
4043

4144
const testdir = dirname(@__FILE__)

0 commit comments

Comments
 (0)