-
Notifications
You must be signed in to change notification settings - Fork 505
Make Documenter Syntax-versioning aware #2874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Keno
wants to merge
2
commits into
master
Choose a base branch
from
kf/synver
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # Test module that sets its syntax version to 1.14 | ||
| # Doctests in this module should automatically use 1.14 syntax | ||
|
|
||
| module SyntaxVersioning | ||
|
|
||
| # Set this module's syntax version to 1.14 | ||
| Base.Experimental.@set_syntax_version v"1.14" | ||
|
|
||
| """ | ||
| Verify that the syntax version is set correctly. | ||
|
|
||
| ```jldoctest | ||
| julia> (Base.Experimental.@VERSION).syntax | ||
| v"1.14.0" | ||
| ``` | ||
| """ | ||
| function check_syntax_version end | ||
|
|
||
| """ | ||
| This doctest uses labeled break syntax which requires Julia 1.14. | ||
| Since the module has its syntax version set, this should work without | ||
| needing a `syntax=` annotation. | ||
|
|
||
| ```jldoctest | ||
| julia> result = @label myblock begin | ||
| for i in 1:10 | ||
| if i > 5 | ||
| break myblock i * 2 | ||
| end | ||
| end | ||
| 0 | ||
| end | ||
| 12 | ||
| ``` | ||
| """ | ||
| function labeled_break_example end | ||
|
|
||
| """ | ||
| This doctest uses labeled continue syntax which requires Julia 1.14. | ||
|
|
||
| ```jldoctest | ||
| julia> output = Int[] | ||
| Int64[] | ||
|
|
||
| julia> @label outer for i in 1:3 | ||
| for j in 1:3 | ||
| if j == 2 | ||
| continue outer | ||
| end | ||
| push!(output, i * 10 + j) | ||
| end | ||
| end | ||
|
|
||
| julia> output | ||
| 3-element Vector{Int64}: | ||
| 11 | ||
| 21 | ||
| 31 | ||
| ``` | ||
| """ | ||
| function labeled_continue_example end | ||
|
|
||
| end # module |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Negative test: module with syntax version set to 1.13 | ||
| # Verifies that the parser actually respects the older syntax version | ||
|
|
||
| module SyntaxVersioning13 | ||
|
|
||
| Base.Experimental.@set_syntax_version v"1.13" | ||
|
|
||
| """ | ||
| Verify that the syntax version is 1.13, not 1.14. | ||
|
|
||
| ```jldoctest | ||
| julia> (Base.Experimental.@VERSION).syntax == v"1.13" | ||
| true | ||
| ``` | ||
| """ | ||
| function check_syntax_version end | ||
|
|
||
| end # module |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # Syntax Versioning Tests | ||
|
|
||
| This page tests the `syntax=` attribute for doctests. | ||
|
|
||
| ## Per-block syntax version | ||
|
|
||
| This doctest uses the `syntax=` attribute to specify Julia 1.14 syntax: | ||
|
|
||
| ```jldoctest; syntax = v"1.14" | ||
| julia> result = @label myblock begin | ||
| for i in 1:5 | ||
| if i > 3 | ||
| break myblock i * 10 | ||
| end | ||
| end | ||
| 0 | ||
| end | ||
| 40 | ||
| ``` | ||
|
|
||
| ## Verifying syntax version with @VERSION | ||
|
|
||
| ```jldoctest; syntax = v"1.14" | ||
| julia> (Base.Experimental.@VERSION).syntax == v"1.14" | ||
| true | ||
| ``` | ||
|
|
||
| ## Negative test: syntax version 1.13 | ||
|
|
||
| This verifies that setting `syntax = v"1.13"` actually uses the 1.13 parser, | ||
| not the default one. | ||
|
|
||
| ```jldoctest; syntax = v"1.13" | ||
| julia> (Base.Experimental.@VERSION).syntax == v"1.13" | ||
| true | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # Tests for syntax versioning support in doctests | ||
| # | ||
| # These tests verify that modules with syntax version set via | ||
| # Base.Experimental.@set_syntax_version have their doctests parsed | ||
| # with the correct syntax version. | ||
|
|
||
| module SyntaxVersioningTests | ||
| using Test | ||
| using Documenter | ||
| import IOCapture | ||
|
|
||
| function run_doctest(; modules = Module[], mdfiles = String[]) | ||
| builds_directory = mktempdir() | ||
| srcdir = joinpath(builds_directory, "src") | ||
| mkpath(srcdir) | ||
| touch(joinpath(srcdir, "index.md")) | ||
| for mdfile in mdfiles | ||
| cp(joinpath(@__DIR__, "src", mdfile), joinpath(srcdir, mdfile)) | ||
| end | ||
| c = IOCapture.capture(rethrow = InterruptException) do | ||
| withenv("JULIA_DEBUG" => "") do | ||
| makedocs( | ||
| sitename = " ", | ||
| format = Documenter.HTML(edit_link = nothing), | ||
| root = builds_directory, | ||
| modules = modules, | ||
| pages = isempty(mdfiles) ? Documenter.Page[] : mdfiles, | ||
| remotes = nothing, | ||
| checkdocs = :none, | ||
| doctest = true, | ||
| warnonly = false, | ||
| ) | ||
| end | ||
| end | ||
| if c.error | ||
| @error "Doctest failed" output = c.output | ||
| end | ||
| return @test !c.error | ||
| end | ||
|
|
||
| # Only run these tests on Julia 1.14+ where syntax versioning is available | ||
| @testset "Syntax Versioning" begin | ||
| if !isdefined(Base, :VersionedParse) | ||
| @info "Skipping syntax versioning tests: requires Julia 1.14+" | ||
| @test_skip false | ||
| else | ||
| include("src/SyntaxVersioning.jl") | ||
| include("src/SyntaxVersioning13.jl") | ||
|
|
||
| @testset "Module with @set_syntax_version v\"1.14\"" begin | ||
| run_doctest(modules = [SyntaxVersioning]) | ||
| end | ||
|
|
||
| @testset "Module with @set_syntax_version v\"1.13\" (negative)" begin | ||
| run_doctest(modules = [SyntaxVersioning13]) | ||
| end | ||
|
|
||
| @testset "Markdown with syntax= attribute" begin | ||
| run_doctest(mdfiles = ["syntax_versioning.md"]) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| end # module |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.