Skip to content

Commit 6cde5e4

Browse files
committed
check if variables declared as public/exported, or listed as private
1 parent ec8669e commit 6cde5e4

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/public.julia

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ public AccelerationFreeUnits, AccelerationUnits, ActionFreeUnits, ActionUnits,
199199
MolarMassUnits, MolarityFreeUnits, MolarityUnits, MomentumFreeUnits, MomentumUnits,
200200
PowerFreeUnits, PowerUnits, PressureFreeUnits, PressureUnits, ScalarUnits,
201201
TemperatureFreeUnits, TemperatureUnits, TimeFreeUnits, TimeUnits, Units,
202-
VelocityFreeUnits, VelocityUnits, VoltageFreeUnits, VoltageUnits,
202+
VelocityFreeUnits,
203+
VelocityUnits, VoltageFreeUnits, VoltageUnits,
203204
VolumeFlowFreeUnits, VolumeFlowUnits, VolumeFreeUnits, VolumeUnits,
204205
WavenumberFreeUnits, WavenumberUnits
205206

test/runtests.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,29 @@ end
6060

6161
is_finite_nonzero(x) = isfinite(x) && !iszero(x)
6262

63+
VERSION >= v"1.11.0-DEV.469" && @testset "public variables" begin
64+
module_names = [:DefaultSymbols]
65+
private_vars = [:BCAST_PROPAGATE_CALLS, :allowed_funcs, :basefactors, :prefixdict, :promotion, :si_no_prefix, :si_prefixes, :unitmodules]
66+
private_fns = [:abbr, :abs2_fast, :abs_fast, :affinetranslation, :affineunit, :base, :basefactor, :basefactors_expr, :colon,
67+
:colonstartstop, :conj_fast, :convfact, :convfact_floattype, :dimtype, :expfn, :fp_overflow_underflow, :fromlog,
68+
:gaintype, :genericunit, :get_T, :has_unit_spacing, :inv_fast, :isrootpower, :isrootpower_dim, :isunitless, :leveltype,
69+
:logfn, :lookup_units, :name, :numtype, :power, :prefactor, :preferunits, :prefix, :print_closing_bracket,
70+
:print_opening_bracket, :printed_length, :promote_to_derived, :promote_unit, :quantitytype, :register, :showrep, :showval,
71+
:sign_fast, :sortexp, :superscript, :tens, :tensfactor, :tolog, :try_uconvert, :uconvert_affine, :unwrap, :ustrcheck_bool]
72+
73+
_basenames = names(Base; all=true)
74+
unitful_ids = filter(x -> !startswith(string(x), r"#|@"), names(Unitful; all=true))
75+
base_overloaded_names = filter(x -> x in _basenames, unitful_ids)
76+
undescored_names = filter(x -> startswith(string(x), "_"), unitful_ids)
77+
private_names = vcat(module_names, private_fns, private_vars, undescored_names)
78+
exported_names = filter(x -> Base.isexported(Unitful, x), unitful_ids)
79+
public_names = filter(x -> Base.ispublic(Unitful, x), unitful_ids)
80+
other_names = setdiff(unitful_ids, union(private_names, exported_names, base_overloaded_names, public_names))
81+
isempty(other_names) ||
82+
@warn """For variables in $(other_names): declare as public or exported, or prepend underscore, or add to a private variables list in testset "public variables" """
83+
84+
@test isempty(other_names)
85+
end
6386
@testset "Construction" begin
6487
@test isa(NoUnits, FreeUnits)
6588
@test typeof(𝐋) === Unitful.Dimensions{(Unitful.Dimension{:Length}(1),)}
@@ -2547,6 +2570,8 @@ using REPL # This is necessary to make `@doc` work correctly
25472570
"""
25482571
end
25492572

2573+
2574+
25502575
# Test precompiled Unitful extension modules
25512576
mktempdir() do load_path
25522577
mktempdir() do load_cache_path

0 commit comments

Comments
 (0)