Skip to content

Commit

Permalink
Organize tests into modules
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobjpeters committed Jun 16, 2024
1 parent 64ce3cf commit be4727e
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 56 deletions.
2 changes: 2 additions & 0 deletions LocalPreferences.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Typstry]
instability_check = "error"
4 changes: 2 additions & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ using Dates: Dates, Date, DateTime, Day, Hour, Minute, Second, Time, Week
using Documenter: Documenter, Docs, DocMeta, deploydocs, makedocs
using .Docs: HTML, Text
using .DocMeta: setdocmeta!
using LaTeXStrings: LaTeXStrings, LaTeXString, @L_str
using LaTeXStrings: LaTeXStrings, LaTeXString
using Luxor: Drawing, finish, julia_blue, julia_green, julia_purple, julia_red, rect, sethue
using Markdown: Markdown, MD, @md_str
using Markdown: Markdown, MD
using Typstry: _show_typst, enclose, join_with, preamble, typst_mime
using Typstry

Expand Down
2 changes: 1 addition & 1 deletion readme.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const delimiter = "## Introduction"

write("README.md", "\n" * join((
"<!-- This file is generated by `.github/workflows/readme.yml`; do not edit directly. -->",
"<!-- This file is generated by .github/workflows/readme.yml and should not be edited directly. -->",
read("HEADER.md", String),
delimiter * replace(
last(split(read("docs/source/index.md", String), delimiter)),
Expand Down
12 changes: 12 additions & 0 deletions test/TestAqua.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

module TestAqua

using Aqua: test_all, test_ambiguities
using Typstry

function test()
test_all(Typstry; ambiguities = false)
test_ambiguities(Typstry)
end

end # TestAqua
11 changes: 11 additions & 0 deletions test/TestDatesExtension.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

module TestDatesExtension

using Dates: Dates
using Typstry

function test()

end

end # TestDatesExtension
44 changes: 44 additions & 0 deletions test/TestDocumenter.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

module TestDocumenter

using Base: get_extension, disable_logging
using Dates: Dates
using Documenter: DocMeta.setdocmeta!, doctest
using Logging: Debug, Info, disable_logging
using Markdown: Markdown
using LaTeXStrings: LaTeXStrings
using Preferences: set_preferences!
using Typstry

const extensions = [:Dates, :LaTeXStrings, :Markdown]

function _test(_module, x)
setdocmeta!(_module, :DocTestSetup, quote
using Preferences: set_preferences!
using Typstry
$x

set_preferences!("Typstry", "instability_check" => "error")
end; recursive = true)

# TODO: errors print twice
doctest(_module; manual = "source", testset = "`$_module` Doctests")
end

function test()
set_preferences!("Typstry", "instability_check" => "error")
disable_logging(Info)

_test(Typstry, nothing)

for extension in extensions
_extension = Symbol(extension, "Extension")
_module = get_extension(Typstry, _extension)

_test(_module, :(using $extension))
end

disable_logging(Debug)
end

end # TestDocumenter
31 changes: 31 additions & 0 deletions test/TestExplicitImports.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

module TestExplicitImports

using ExplicitImports:
check_all_explicit_imports_are_public,
check_all_explicit_imports_via_owners,
check_all_qualified_accesses_are_public,
check_all_qualified_accesses_via_owners,
check_no_implicit_imports,
check_no_self_qualified_accesses,
check_no_stale_explicit_imports
using Test: @test
using Typstry

function test()
@test isnothing(check_all_explicit_imports_are_public(Typstry; ignore = (:MD, :Stateful,
:code_mode, :depth, :escape_raw_string, :indent, :parse, :print_parameters, :show_raw, :workload)))

for check in (
check_all_explicit_imports_via_owners,
check_all_qualified_accesses_are_public,
check_all_qualified_accesses_via_owners,
check_no_implicit_imports,
check_no_self_qualified_accesses,
check_no_stale_explicit_imports
)
@test isnothing(check(Typstry))
end
end

end # TestExplicitImports
21 changes: 21 additions & 0 deletions test/TestLaTeXStringsExtension.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

module TestLaTeXStringsExtension

using ..TestTypstry: test_modes, test_strings
using LaTeXStrings: @L_str
using Typstry

const latex = L"a"

function test()
# test_modes(latex, [
# "```latex \$a\$ ```",
# "```latex \$a\$ ```",
# "#```latex \$a\$ ```"
# ])

# test_strings(latex, "````latex\n a\n \n ````";
# backticks = 4, block = true, depth = 2, indent_size = 4)
end

end # TestLaTeXStringsExtension
21 changes: 21 additions & 0 deletions test/TestMarkdownExtension.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

module TestMarkdownExtension

using ..TestTypstry: test_modes, test_strings
using Markdown: Markdown
using Typstry

const markdown = Markdown.parse("a\\\nb")

function test()
# test_modes(markdown, [
# "```markdown a\nb ```",
# "```markdown a\nb ```",
# "#```markdown a\nb ```"
# ])

# test_strings(markdown, "````markdown\n a \n b\n `````";
# backticks = 4, block = true, depth = 2, indent_size = 4)
end

end # TestMarkdownExtension
72 changes: 19 additions & 53 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,63 +1,29 @@

using Aqua: test_all, test_ambiguities
using Base: get_extension, disable_logging
using ExplicitImports:
check_all_explicit_imports_are_public,
check_all_explicit_imports_via_owners,
check_all_qualified_accesses_are_public,
check_all_qualified_accesses_via_owners,
check_no_implicit_imports,
check_no_self_qualified_accesses,
check_no_stale_explicit_imports
using Dates: Dates
using Documenter: DocMeta.setdocmeta!, doctest
using LaTeXStrings: LaTeXStrings
using Logging: Debug, Info, disable_logging
using Markdown: Markdown
using Preferences: set_preferences!
using Test: @testset, @test
using Typstry

_doctest(_module, name) = doctest(_module; manual = "source", testset = "$name.jl Doctests")
module TestTypstry

_setdocmeta!(_module, x) = setdocmeta!(_module, :DocTestSetup,
:(using Preferences: set_preferences!; using Typstry; $x; set_preferences!("Typstry", "instability_check" => "error"));
recursive = true)
using Test: @test, @testset

set_preferences!("Typstry", "instability_check" => "error")

@testset "Aqua.jl" begin
test_all(Typstry; ambiguities = false)
test_ambiguities(Typstry)
end

_setdocmeta!(Typstry, nothing)
disable_logging(Info)

@testset "Doctests" begin
_doctest(Typstry, "Typstry")

for extension in [:Dates, :LaTeXStrings, :Markdown]
_module = get_extension(Typstry, Symbol(extension, "Extension"))
_setdocmeta!(_module, :(using $extension))
_doctest(_module, extension)
test_modes(x, ss) = @testset "modes" begin
for (mode, s) in zip(instances(Mode), ss)
test_strings(x, s; mode)
end
end

disable_logging(Debug)

@testset "ExplicitImports.jl" begin
@test isnothing(check_all_explicit_imports_are_public(Typstry; ignore = (:MD, :Stateful,
:code_mode, :depth, :escape_raw_string, :indent, :parse, :print_parameters, :show_raw, :workload)))

for check in (
check_all_explicit_imports_via_owners,
check_all_qualified_accesses_are_public,
check_all_qualified_accesses_via_owners,
check_no_implicit_imports,
check_no_self_qualified_accesses,
check_no_stale_explicit_imports
)
@test isnothing(check(Typstry))
test_strings(x, s; kwargs...) = @test TypstString(x; kwargs...).text == s

@testset "Typstry" begin
for description in [
"Aqua",
"DatesExtension",
"Documenter",
"ExplicitImports",
"LaTeXStringsExtension",
"MarkdownExtension"
]
@testset "$description" include("Test" * description * ".jl").test()
end
end

end # TestTypstry

0 comments on commit be4727e

Please sign in to comment.