|
| 1 | +module test_lookup_analysis_entry |
| 2 | + |
| 3 | +using Test |
| 4 | +using Pkg |
| 5 | +using JETLS |
| 6 | +using JETLS: lookup_analysis_entry, ScriptInEnvAnalysisEntry, entryenvpath |
| 7 | +using JETLS.URIs2: filepath2uri |
| 8 | + |
| 9 | +@testset "lookup_analysis_entry for docs" begin |
| 10 | + mktempdir() do temp_root |
| 11 | + proj_dir = joinpath(temp_root, "TestPkg") |
| 12 | + mkpath(proj_dir) |
| 13 | + env_path = joinpath(proj_dir, "Project.toml") |
| 14 | + write(env_path, """ |
| 15 | + name = "TestPkg" |
| 16 | + uuid = "12345678-1234-1234-1234-123456789012" |
| 17 | + version = "0.1.0" |
| 18 | + """) |
| 19 | + |
| 20 | + src_dir = joinpath(proj_dir, "src") |
| 21 | + docs_dir = joinpath(proj_dir, "docs") |
| 22 | + mkpath(src_dir) |
| 23 | + mkpath(docs_dir) |
| 24 | + mkpath(joinpath(docs_dir, "src")) |
| 25 | + |
| 26 | + write(joinpath(src_dir, "TestPkg.jl"), "module TestPkg end") |
| 27 | + write(joinpath(docs_dir, "make.jl"), "# docs make script") |
| 28 | + |
| 29 | + # Test docs with docs/Project.toml |
| 30 | + let docs_env_path = joinpath(docs_dir, "Project.toml") |
| 31 | + write(docs_env_path, """ |
| 32 | + [deps] |
| 33 | + Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" |
| 34 | + """) |
| 35 | + |
| 36 | + filepath = joinpath(docs_dir, "make.jl") |
| 37 | + uri = filepath2uri(filepath) |
| 38 | + server = Server() |
| 39 | + server.state.root_path = proj_dir |
| 40 | + entry = lookup_analysis_entry(server, uri) |
| 41 | + @test entry isa ScriptInEnvAnalysisEntry |
| 42 | + @test entryenvpath(entry) == docs_env_path |
| 43 | + end |
| 44 | + |
| 45 | + # Test docs without docs/Project.toml (falls back to root Project.toml) |
| 46 | + let docs_env_path = joinpath(docs_dir, "Project.toml") |
| 47 | + rm(docs_env_path; force=true) |
| 48 | + |
| 49 | + filepath = joinpath(docs_dir, "make.jl") |
| 50 | + uri = filepath2uri(filepath) |
| 51 | + server = Server() |
| 52 | + server.state.root_path = proj_dir |
| 53 | + entry = lookup_analysis_entry(server, uri) |
| 54 | + @test entry isa ScriptInEnvAnalysisEntry |
| 55 | + @test entryenvpath(entry) == env_path |
| 56 | + end |
| 57 | + end |
| 58 | +end |
| 59 | + |
| 60 | +end # module test_lookup_analysis_entry |
0 commit comments