Skip to content
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

Use at-testset for tests #294

Merged
merged 14 commits into from
Oct 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*.jl.*.cov
*.jl.mem

test/examples/build-*
test/examples/builds/
test/missingdocs/build/
test/errors/build/
docs/build/
Expand Down
5 changes: 0 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ environment:
- JULIAVERSION: "julialang/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe"
- JULIAVERSION: "julianightlies/bin/winnt/x64/julia-latest-win64.exe"

branches:
only:
- master
- /^release-.*/

notifications:
- provider: Email
on_build_success: false
Expand Down
1 change: 1 addition & 0 deletions docs/src/man/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Follow the style of the surrounding text when making changes. When adding new fe
### Julia

* 4-space indentation;
* modules spanning entire files should not be indented, but modules that have surrounding code should;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a note here about the modules. Thoughts on the phrasing very welcome.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wording sounds good to me.

* no blank lines at the start or end of files;
* do not manually align syntax such as `=` or `::` over adjacent lines;
* use `local` to define new local variables so that they are easier to locate;
Expand Down
85 changes: 85 additions & 0 deletions test/docsystem.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
module DocSystemTests

if VERSION >= v"0.5.0-dev+7720"
using Base.Test
else
using BaseTestNext
const Test = BaseTestNext
end

import Documenter: Documenter, DocSystem

const alias_of_getdocs = DocSystem.getdocs # NOTE: won't get docstrings if in a @testset
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to move this here, since the test on line 66 started failing (d_4 had 0 docstrings).


@testset "DocSystem" begin
## Bindings.
@test_throws ArgumentError DocSystem.binding(9000)
let b = Docs.Binding(current_module(), :DocSystem)
@test DocSystem.binding(b) == b
end
let b = DocSystem.binding(Documenter.Documents.Document)
@test b.mod === Documenter.Documents
@test b.var === :Document
end
let b = DocSystem.binding(Documenter)
@test b.mod === Main
@test b.var === :Documenter
end
let b = DocSystem.binding(:Main)
# @test b.mod === Main
@test b.var === :Main
end
let b = DocSystem.binding(DocSystem.binding)
@test b.mod === DocSystem
@test b.var === :binding
end
let b = DocSystem.binding(getfield(Core.Intrinsics, :ccall))
@test b.mod === Core.Intrinsics
@test b.var === :ccall
end
let b = DocSystem.binding(Documenter, :Documenter)
@test b.mod === Main
@test b.var === :Documenter
end

## `MultiDoc` object.
@test isdefined(DocSystem, :MultiDoc)
@test fieldnames(DocSystem.MultiDoc) == [:order, :docs]

## `DocStr` object.
@test isdefined(DocSystem, :DocStr)
@test fieldnames(DocSystem.DocStr) == [:text, :object, :data]

## `getdocs`.
let b = DocSystem.binding(DocSystem, :getdocs),
d_0 = DocSystem.getdocs(b, Tuple{}),
d_1 = DocSystem.getdocs(b),
d_2 = DocSystem.getdocs(b, Union{Tuple{ANY}, Tuple{ANY, Type}}; compare = (==)),
d_3 = DocSystem.getdocs(b; modules = Module[Main]),
d_4 = DocSystem.getdocs(DocSystem.binding(current_module(), :alias_of_getdocs)),
d_5 = DocSystem.getdocs(DocSystem.binding(current_module(), :alias_of_getdocs); aliases = false)

@test length(d_0) == 0
@test length(d_1) == 2
@test length(d_2) == 1
@test length(d_3) == 0
@test length(d_4) == 2
@test length(d_5) == 0

@test d_1[1].data[:binding] == b
@test d_1[2].data[:binding] == b
@test d_1[1].data[:typesig] == Union{Tuple{Docs.Binding}, Tuple{Docs.Binding, Type}}
@test d_1[2].data[:typesig] == Union{Tuple{ANY}, Tuple{ANY, Type}}
@test d_1[1].data[:module] == DocSystem
@test d_1[2].data[:module] == DocSystem

@test d_2[1].data[:binding] == b
@test d_2[1].data[:typesig] == Union{Tuple{ANY}, Tuple{ANY, Type}}
@test d_2[1].data[:module] == DocSystem

@test d_1 == d_4
@test d_1 != d_5
end
end

end
98 changes: 98 additions & 0 deletions test/dom.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
module DOMTests

if VERSION >= v"0.5.0-dev+7720"
using Base.Test
else
using BaseTestNext
const Test = BaseTestNext
end

import Documenter.Utilities.DOM: DOM, @tags, HTMLDocument

@tags div ul li p

@testset "DOM" begin
for tag in (:div, :ul, :li, :p)
TAG = getfield(current_module(), tag)
@test isdefined(tag)
@test isa(TAG, DOM.Tag)
@test TAG.name === tag
end

@test div().name === :div
@test div().text == ""
@test isempty(div().nodes)
@test isempty(div().attributes)

@test div("...").name === :div
@test div("...").text == ""
@test length(div("...").nodes) === 1
@test div("...").nodes[1].text == "..."
@test div("...").nodes[1].name === Symbol("")
@test isempty(div("...").attributes)

@test div[".class"]("...").name === :div
@test div[".class"]("...").text == ""
@test length(div[".class"]("...").nodes) === 1
@test div[".class"]("...").nodes[1].text == "..."
@test div[".class"]("...").nodes[1].name === Symbol("")
@test length(div[".class"]("...").attributes) === 1
@test div[".class"]("...").attributes[1] == (:class => "class")
@test div[:attribute].attributes[1] == (:attribute => "")
@test div[:attribute => "value"].attributes[1] == (:attribute => "value")

let d = div(ul(map(li, [string(n) for n = 1:10])))
@test d.name === :div
@test d.text == ""
@test isempty(d.attributes)
@test length(d.nodes) === 1
let u = d.nodes[1]
@test u.name === :ul
@test u.text == ""
@test isempty(u.attributes)
@test length(u.nodes) === 10
for n = 1:10
let v = u.nodes[n]
@test v.name === :li
@test v.text == ""
@test isempty(v.attributes)
@test length(v.nodes) === 1
@test v.nodes[1].name === Symbol("")
@test v.nodes[1].text == string(n)
@test !isdefined(v.nodes[1], :attributes)
@test !isdefined(v.nodes[1], :nodes)
end
end
end
end

@tags script style img

@test string(div(p("one"), p("two"))) == "<div><p>one</p><p>two</p></div>"
@test string(div[:key => "value"]) == "<div key=\"value\"></div>"
@test string(p(" < > & ' \" ")) == "<p> &lt; &gt; &amp; &#39; &quot; </p>"
@test string(img[:src => "source"]) == "<img src=\"source\"/>"
@test string(img[:none]) == "<img none/>"
@test string(script(" < > & ' \" ")) == "<script> < > & ' \" </script>"
@test string(style(" < > & ' \" ")) == "<style> < > & ' \" </style>"
@test string(script) == "<script>"

function locally_defined()
@tags button
@test try
x = button
true
catch err
false
end
end
@test !isdefined(current_module(), :button)
locally_defined()
@test !isdefined(current_module(), :button)

# HTMLDocument
@test string(HTMLDocument(div())) == "<!DOCTYPE html>\n<div></div>\n"
@test string(HTMLDocument("custom doctype", div())) == "<!DOCTYPE custom doctype>\n<div></div>\n"
end

end
111 changes: 111 additions & 0 deletions test/examples/make.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Defines the modules referred to in the example docs (under src/) and then builds them.
# It can be called separately to build the examples/, or as part of the test suite.
#
# It defines a set of variables (`examples_*`) that can be used in the tests.
# The `examples_root` should be used to check whether this file has already been included
# or not and should be kept unique.
isdefined(:examples_root) && error("examples_root is already defined\n$(@__FILE__) included multiple times?")

# The `Mod` and `AutoDocs` modules are assumed to exists in the Main module.
current_module() === Main || error("$(@__FILE__) must be included into Main.")

# Modules `Mod` and `AutoDocs`
module Mod
"""
func(x)

[`T`](@ref)
"""
func(x) = x

"""
T

[`func(x)`](@ref)
"""
type T end
end

"`AutoDocs` module."
module AutoDocs
module Pages
include("pages/a.jl")
include("pages/b.jl")
include("pages/c.jl")
include("pages/d.jl")
include("pages/e.jl")
end

"Function `f`."
f(x) = x

"Constant `K`."
const K = 1

"Type `T`."
type T end

"Macro `@m`."
macro m() end

"Module `A`."
module A
"Function `A.f`."
f(x) = x

"Constant `A.K`."
const K = 1

"Type `B.T`."
type T end

"Macro `B.@m`."
macro m() end
end

"Module `B`."
module B
"Function `B.f`."
f(x) = x

"Constant `B.K`."
const K = 1

"Type `B.T`."
type T end

"Macro `B.@m`."
macro m() end
end
end

# Build example docs
using Documenter

const examples_root = dirname(@__FILE__)

info("Building mock package docs: MarkdownWriter")
examples_markdown_doc = makedocs(
debug = true,
root = examples_root,
build = "builds/markdown",
)

info("Building mock package docs: HTMLWriter")
examples_html_doc = makedocs(
debug = true,
root = examples_root,
build = "builds/html",
format = Documenter.Formats.HTML,
sitename = "Documenter example",
pages = Any[
"Home" => "index.md",
"Manual" => [
"man/tutorial.md",
],
"Library" => [
"lib/functions.md",
"lib/autodocs.md",
]
]
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading