Skip to content

Commit 583394e

Browse files
authored
[~breaking] Fix issue where explicitly imported macros aren't detected as imported (#159)
* Fix issue where explicitly imported macros aren't detected as imported * tweak test running to show errors better
1 parent 46f2fe2 commit 583394e

5 files changed

Lines changed: 46 additions & 3 deletions

File tree

integration/runtest.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ end
1414
for dir in selected_dirs
1515
isfile(joinpath(dir, "check.jl")) || continue
1616
@info "Running integration tests for $(basename(dir))"
17-
@test success(`$(Base.julia_cmd()) --project=$dir -e 'using Pkg; Pkg.instantiate()'`)
18-
@test success(`$(Base.julia_cmd()) --project=$dir $dir/check.jl`)
17+
run(`$(Base.julia_cmd()) --project=$dir -e 'using Pkg; Pkg.instantiate()'`)
18+
run(`$(Base.julia_cmd()) --project=$dir $dir/check.jl`)
1919
end
2020
end

src/get_names_used.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ end
119119
# figure out if `leaf` is part of an import or using statement
120120
# this seems to trigger for both `X` and `y` in `using X: y`, but that seems alright.
121121
function analyze_import_type(leaf)
122-
kind(leaf) == K"Identifier" || return :not_import
122+
kind(leaf) in (K"Identifier", K"MacroName", K"StringMacroName") || return :not_import
123123
has_parent(leaf) || return :not_import
124124
is_import = parents_match(leaf, (K"importpath",))
125125
is_import || return :not_import

test/issue_97.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# https://github.com/JuliaTesting/ExplicitImports.jl/issues/97
2+
module ArgCheck
3+
4+
export @argcheck
5+
6+
macro argcheck(ex)
7+
return esc(ex)
8+
end
9+
10+
end # module
11+
12+
module Issue97
13+
14+
using ..ArgCheck
15+
using ..ArgCheck: ArgCheck, @argcheck
16+
17+
function positive(x)
18+
@argcheck x > 0
19+
return x
20+
end
21+
22+
end # module

test/issue_97_test.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
issue_path = joinpath(@__DIR__, "issue_97.jl")
2+
include(issue_path)
3+
4+
@testset "Issue #97: macro explicit imports" begin
5+
# Issue97 does `using ..ArgCheck` plus `using ..ArgCheck: ArgCheck, @argcheck`.
6+
# The macro is explicitly imported, so check_no_implicit_imports should pass.
7+
@test check_no_implicit_imports(Issue97, issue_path) === nothing
8+
@test check_no_stale_explicit_imports(Issue97, issue_path) === nothing
9+
10+
analysis = ExplicitImports.get_names_used(issue_path).per_usage_info
11+
argcheck_usages = filter(analysis) do nt
12+
nt.name == Symbol("@argcheck") && nt.module_path == [:Issue97]
13+
end
14+
15+
@test getfield.(argcheck_usages, :analysis_code) ==
16+
[ExplicitImports.IgnoredImportRHS, ExplicitImports.External]
17+
end

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ include("issue_140.jl")
109109
include("issue_111_test.jl")
110110
end
111111

112+
@testset "Macro explicit imports (#97)" begin
113+
include("issue_97_test.jl")
114+
end
115+
112116
@testset "module aliases (#106)" begin
113117
# https://github.com/JuliaTesting/ExplicitImports.jl/issues/106
114118
ret = Dict(improper_explicit_imports(ModAlias, "module_alias.jl"))

0 commit comments

Comments
 (0)