Skip to content

Commit 16ce7a6

Browse files
committed
add tests for finding module files
1 parent 5d87708 commit 16ce7a6

4 files changed

Lines changed: 115 additions & 35 deletions

File tree

src/Atom.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
__precompile__()
22

3+
@doc read(joinpath(dirname(@__DIR__), "README.md"), String)
34
module Atom
45

56
using Juno, Lazy, JSON, MacroTools, Media, Base.StackTraces

test/goto.jl

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@testset "goto symbols" begin
2-
using Atom: modulegotoitems, realpath′, toplevelgotoitems, SYMBOLSCACHE,
2+
using Atom: modulegotoitems, toplevelgotoitems, SYMBOLSCACHE,
33
regeneratesymbols, methodgotoitems, globalgotoitems
44
using CSTParser
55

@@ -51,19 +51,18 @@
5151

5252
@testset "module goto" begin
5353
let item = modulegotoitems("Atom", Main)[1]
54-
@test item.file == realpath′(joinpath(@__DIR__, "..", "src", "Atom.jl"))
55-
@test item.line == 2
54+
@test item.file == joinpath′(atomjldir, "Atom.jl")
55+
@test item.line == 3
5656
end
5757
let item = modulegotoitems("Junk2", Main.Junk)[1]
58-
@test item.file == joinpath(@__DIR__, "fixtures", "Junk.jl")
58+
@test item.file == joinpath(junkpath)
5959
@test item.line == 14
6060
end
6161
end
6262

6363
@testset "goto toplevel symbols" begin
6464
## where Revise approach works, i.e.: precompiled modules
65-
let dir = realpath′(joinpath(@__DIR__, "..", "src"))
66-
path = joinpath(dir, "comm.jl")
65+
let path = joinpath′(atomjldir, "comm.jl")
6766
text = read(path, String)
6867
mod = Atom
6968
key = "Atom"
@@ -79,23 +78,8 @@
7978
# check caching works
8079
@test haskey(SYMBOLSCACHE, key)
8180

82-
# check the Revise-like approach finds all the included files
83-
let numfiles = 0
84-
debuggerpath = realpath′(joinpath(@__DIR__, "..", "src", "debugger"))
85-
profilerpath = realpath′(joinpath(@__DIR__, "..", "src", "profiler"))
86-
for (d, ds, fs) walkdir(dir)
87-
if d (debuggerpath, profilerpath)
88-
numfiles += 1 # debugger.jl / traceur.jl (in Atom module)
89-
continue
90-
end
91-
for f fs
92-
if endswith(f, ".jl") # .jl check is needed for travis, who creates hoge.cov files
93-
numfiles += 1
94-
end
95-
end
96-
end
97-
@test length(SYMBOLSCACHE[key]) == numfiles
98-
end
81+
# check the Revise-like approach finds all files in Atom module
82+
@test length(SYMBOLSCACHE[key]) == length(atommodfiles)
9983

10084
# when `path` isn't given, i.e. via docpane / workspace
10185
let items = toplevelgotoitems(word, mod, "", nothing) .|> Dict
@@ -106,11 +90,18 @@
10690

10791
# same as above, but without any previous cache -- falls back to CSTPraser-based module-walk
10892
delete!(SYMBOLSCACHE, key)
93+
10994
let items = toplevelgotoitems(word, mod, "", nothing) .|> Dict
11095
@test !isempty(items)
11196
@test items[1][:file] == path
11297
@test items[1][:text] == word
11398
end
99+
100+
# check CSTPraser-based module-walk finds all the included files
101+
# currently broken:
102+
# - files in submodules are included
103+
# - webio.jl is excluded since `include("webio.jl")` is a toplevel call
104+
@test_broken length(SYMBOLSCACHE[key]) == length(atommoddir)
114105
end
115106

116107
## where the Revise-like approach doesn't work, e.g. non-precompiled modules
@@ -143,15 +134,15 @@
143134
# handle dot accessors gracefully
144135
let
145136
# can access the non-exported (non-method) bindings in the other module
146-
path = realpath′(joinpath(@__DIR__, "..", "src", "goto.jl"))
137+
path = joinpath′(@__DIR__, "..", "src", "goto.jl")
147138
text = read(@__FILE__, String)
148139
items = Dict.(toplevelgotoitems("Atom.SYMBOLSCACHE", Main, text, @__FILE__))
149140
@test !isempty(items)
150141
@test items[1][:file] == path
151142
@test items[1][:text] == "SYMBOLSCACHE"
152143

153144
# handle if a module is duplicated
154-
path = realpath′(joinpath(@__DIR__, "..", "src", "comm.jl"))
145+
path = joinpath′(@__DIR__, "..", "src", "comm.jl")
155146
text = read(path, String)
156147
items = Dict.(toplevelgotoitems("Atom.handlers", Atom, text, path))
157148
@test !isempty(items)

test/modules.jl

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
@testset "module utilties" begin
2+
@testset "find module definition" begin
3+
using Atom: moduledefinition
4+
5+
let (path, line) = moduledefinition(Atom)
6+
@test path == joinpath′(@__DIR__, "..", "src", "Atom.jl")
7+
@test line == 4
8+
end
9+
let (path, line) = moduledefinition(Junk)
10+
@test path == joinpath′(@__DIR__, "fixtures", "Junk.jl")
11+
@test line == 1
12+
end
13+
let (path, line) = moduledefinition(Junk.Junk2)
14+
@test path == joinpath′(@__DIR__, "fixtures", "Junk.jl")
15+
@test line == 15
16+
end
17+
end
18+
19+
@testset "find module files" begin
20+
using Atom: modulefiles
21+
22+
## Revise-like module file detection
23+
# works for precompiled packages
24+
let (parentfile, included_files) = modulefiles(Atom)
25+
expected = Set(atommodfiles)
26+
actual = Set((parentfile, included_files...))
27+
@test actual == expected
28+
29+
# can't detect display/webio.jl
30+
@test_broken webiofile in modfiles
31+
end
32+
33+
# fails for non-precompiled packages
34+
@test_broken junkpath == modulefiles(Junk)[1]
35+
36+
## CSTPraser-based module file detection
37+
let included_files = normpath.(modulefiles(joinpath′(atomjldir, "Atom.jl")))
38+
# finds all the files in Atom module except display/webio.jl
39+
for f in atommodfiles
40+
f == webiofile && continue
41+
@test f in included_files
42+
end
43+
44+
# can't exclude files in the submodules
45+
@test_broken length(atommodfiles) == length(included_files)
46+
47+
# can't look for non-toplevel `include` calls
48+
@test_broken webiofile in included_files
49+
end
50+
end
51+
end

test/runtests.jl

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,57 @@ using Lazy
44
import JSON
55

66

7+
joinpath′(files...) = Atom.fullpath(joinpath(files...))
8+
9+
atomjldir = joinpath′(@__DIR__, "..", "src")
10+
11+
webiofile = joinpath′(atomjldir, "display", "webio.jl")
12+
13+
# files in `Atom` module (except files in its submodules)
14+
atommodfiles = let
15+
files = []
16+
debuggerdir = joinpath′(atomjldir, "debugger")
17+
profilerdir = joinpath′(atomjldir, "profiler")
18+
for (d, ds, fs) in walkdir(atomjldir)
19+
# NOTE: update directories below when you create an new submodule
20+
# the 2 files below are in Atom module
21+
if d == debuggerdir
22+
push!(files, joinpath′(d, "debugger.jl"))
23+
continue
24+
end
25+
if d == profilerdir
26+
push!(files, joinpath′(d, "profiler.jl"))
27+
push!(files, joinpath′(d, "traceur.jl"))
28+
continue
29+
end
30+
for f in fs
31+
# NOTE: currently both Revise-like and CSTPraser-based approach fails
32+
# to detect display/webio.jl as a file in Atom module
33+
f == "webio.jl" && continue
34+
35+
# .jl check is needed for travis, who creates hoge.cov files
36+
endswith(f, ".jl") && push!(files, joinpath′(d, f))
37+
end
38+
end
39+
files
40+
end
41+
742
# mock a listener
843
Core.eval(Atom, Meta.parse("sock = IOBuffer()"))
944
readmsg() = JSON.parse(String(take!(Atom.sock)))
1045

1146
# mock Module
12-
junkpath = joinpath(@__DIR__, "fixtures", "Junk.jl")
47+
junkpath = joinpath(@__DIR__, "fixtures", "Junk.jl")
1348
include(junkpath)
1449

15-
include("./misc.jl") # basics
16-
include("./utils.jl")
17-
include("./eval.jl")
18-
include("./outline.jl")
19-
include("./completions.jl")
20-
include("./goto.jl")
21-
include("./datatip.jl")
22-
include("./workspace.jl")
23-
include("./display.jl")
50+
51+
include("misc.jl") # basics
52+
include("utils.jl")
53+
include("eval.jl")
54+
include("modules.jl")
55+
include("outline.jl")
56+
include("completions.jl")
57+
include("goto.jl")
58+
include("datatip.jl")
59+
include("workspace.jl")
60+
include("display.jl")

0 commit comments

Comments
 (0)